-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ | |
<CommandLineArguments> | ||
<CommandLineArgument | ||
argument = "PerfTest localhost:6666 TimeAndSale YQKNT" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "DXFeedLiveIpfSample https://demo:[email protected]/ipf" | ||
isEnabled = "YES"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// LiveIpfCommand.swift | ||
// Tools | ||
// | ||
// Created by Aleksey Kosylo on 09.10.23. | ||
// | ||
|
||
import Foundation | ||
import DXFeedFramework | ||
|
||
class LiveIpfCommand: ToolsCommand { | ||
lazy var name = { | ||
stringReference(self) | ||
}() | ||
|
||
private var ipfList = [InstrumentProfile]() | ||
private var buffer = [String: InstrumentProfile]() | ||
|
||
static let defaultIpfUrl = "https://demo:[email protected]/ipf" | ||
|
||
var cmd = "DXFeedLiveIpfSample" | ||
|
||
var shortDescription = "An sample that demonstrates a subscription using InstrumentProfile." | ||
|
||
var fullDescription: String = | ||
""" | ||
Connects to the specified address(es) and calculates latency. | ||
Usage: | ||
usage: DXFeedLiveIpfSample [<ipf-url>] | ||
Where: | ||
where: <ipf-url> is URL for the instruments profiles. | ||
Example of url: " + \(LiveIpfCommand.defaultIpfUrl) | ||
""" | ||
var collector: DXInstrumentProfileCollector? | ||
var connection: DXInstrumentProfileConnection? | ||
|
||
func execute() { | ||
var arguments: [String]! | ||
do { | ||
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 1) | ||
} catch { | ||
print(fullDescription) | ||
} | ||
do { | ||
collector = try DXInstrumentProfileCollector() | ||
connection = try DXInstrumentProfileConnection(arguments[1], collector!) | ||
// Update period can be used to re-read IPF files, not needed for services supporting IPF "live-update" | ||
try connection?.setUpdatePeriod(60000) | ||
connection?.add(observer: self) | ||
try connection?.start() | ||
// We can wait until we get first full snapshot of instrument profiles | ||
connection?.waitUntilCompleted(10000) | ||
// It is possible to add listener after connection is started - updates will not be missed in this case | ||
try collector?.add(observer: self) | ||
} catch { | ||
print("Error: \(error)") | ||
} | ||
|
||
_ = readLine() | ||
} | ||
} | ||
|
||
extension LiveIpfCommand: DXInstrumentProfileConnectionObserver { | ||
func connectionDidChangeState(old: DXInstrumentProfileConnectionState, new: DXInstrumentProfileConnectionState) { | ||
print("Connection state: \(new)") | ||
} | ||
} | ||
|
||
extension LiveIpfCommand: DXInstrumentProfileUpdateListener { | ||
func instrumentProfilesUpdated(_ instruments: [DXFeedFramework.InstrumentProfile]) { | ||
instruments.forEach { ipf in | ||
if ipf.getIpfType() == .removed { | ||
self.buffer.removeValue(forKey: ipf.symbol) | ||
} else { | ||
self.buffer[ipf.symbol] = ipf | ||
} | ||
} | ||
self.ipfList = self.buffer.map { _, value in | ||
value | ||
}.sorted(by: { ipf1, ipf2 in | ||
ipf1.symbol < ipf2.symbol | ||
}) | ||
print( | ||
""" | ||
Instrument Profiles: | ||
Total number of profiles (1): \(self.ipfList.count) | ||
Last modified: \(TimeUtil.toLocalDateString(millis: collector?.getLastUpdateTime() ?? 0)) | ||
""" | ||
) | ||
} | ||
} | ||
|
||
extension LiveIpfCommand: Hashable { | ||
static func == (lhs: LiveIpfCommand, rhs: LiveIpfCommand) -> Bool { | ||
return lhs === rhs || lhs.name == rhs.name | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(name) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters