Skip to content

Commit

Permalink
add parsing ipf symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 16, 2023
1 parent d577cba commit 4d6f6ec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect mddqa.in.devexperts.com:7400 OptionSale AAPL"
argument = "Connect demo.dxfeed.com:7300 Quote &quot;ipf[https://demo:[email protected]/ipf?TYPE=STOCK&amp;compression=zip],APPL&quot;"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
Expand Down
8 changes: 8 additions & 0 deletions DXFeedFramework/Utils/String+Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ extension Collection {
extension String.Index {
func distance<S: StringProtocol>(in string: S) -> Int { string.distance(to: self) }
}

extension String {
public func slice(from: String, to: String) -> String? {
guard let rangeFrom = range(of: from)?.upperBound else { return nil }
guard let rangeTo = self[rangeFrom...].range(of: to)?.lowerBound else { return nil }
return String(self[rangeFrom..<rangeTo])
}
}
42 changes: 40 additions & 2 deletions Samples/PerfTestCL/ConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,54 @@ Where:
}
let address = arguments[1]
let types = arguments[2]
let symbols = arguments[3].components(separatedBy: ",")

let symbols = arguments[3]
var symbolsList = [String]()
func addSymbol(str: String) {
if str.hasPrefix("ipf[") && str.hasSuffix("]") {
if let address = str.slice(from: "[", to: "]") {
let profiles = try? DXInstrumentProfileReader().readFromFile(address: address)
profiles?.forEach({ profile in
symbolsList.append(profile.symbol)
})
}
} else {
symbolsList.append(str)
}
}
var parentheses = 0
var tempSrting = ""
symbols.forEach { character in
switch character {
case "{", "(", "[":
parentheses += 1
tempSrting.append(character)
case "}", ")", "]":
if parentheses > 0 {
parentheses -= 1
}
tempSrting.append(character)
case ",":
if parentheses == 0 {
addSymbol(str: tempSrting)
tempSrting = ""
} else {
tempSrting.append(character)
}
default:
tempSrting.append(character)
}
}

addSymbol(str: tempSrting)
var time: String?
if arguments.count > 4 {
time = arguments[4]
}

let listener = ConnectEventListener()
subscription.createSubscription(address: address,
symbols: symbols,
symbols: symbolsList,
types: types,
listener: listener,
time: time)
Expand Down

0 comments on commit 4d6f6ec

Please sign in to comment.