Skip to content

Commit

Permalink
parse symbols using qds embedded method
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Nov 17, 2023
1 parent 5cfc776 commit e003e7f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 40 deletions.
16 changes: 16 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
6498E6C42AB20B860093A065 /* ScheduleSessionType+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6C32AB20B860093A065 /* ScheduleSessionType+Ext.swift */; };
649F48862A615BC90016FDD1 /* CandleSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649F48852A615BC90016FDD1 /* CandleSymbol.swift */; };
649F48882A615BED0016FDD1 /* CandleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649F48872A615BED0016FDD1 /* CandleType.swift */; };
64A42F3B2B07A7A3001C3ACC /* SymbolParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A42F3A2B07A7A3001C3ACC /* SymbolParser.swift */; };
64A42F3E2B07A807001C3ACC /* NativeSymbolParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A42F3D2B07A807001C3ACC /* NativeSymbolParser.swift */; };
64AAF0532A8113E800E8942B /* String+Range.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AAF0522A8113E800E8942B /* String+Range.swift */; };
64AAF0552A82499A00E8942B /* ConcurrentDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AAF0542A82499A00E8942B /* ConcurrentDict.swift */; };
64AAF0572A82A3FC00E8942B /* ICandleSymbolProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AAF0562A82A3FC00E8942B /* ICandleSymbolProperty.swift */; };
Expand Down Expand Up @@ -693,6 +695,8 @@
6498E6C32AB20B860093A065 /* ScheduleSessionType+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScheduleSessionType+Ext.swift"; sourceTree = "<group>"; };
649F48852A615BC90016FDD1 /* CandleSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleSymbol.swift; sourceTree = "<group>"; };
649F48872A615BED0016FDD1 /* CandleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleType.swift; sourceTree = "<group>"; };
64A42F3A2B07A7A3001C3ACC /* SymbolParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolParser.swift; sourceTree = "<group>"; };
64A42F3D2B07A807001C3ACC /* NativeSymbolParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSymbolParser.swift; sourceTree = "<group>"; };
64AAF0522A8113E800E8942B /* String+Range.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Range.swift"; sourceTree = "<group>"; };
64AAF0542A82499A00E8942B /* ConcurrentDict.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrentDict.swift; sourceTree = "<group>"; };
64AAF0562A82A3FC00E8942B /* ICandleSymbolProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICandleSymbolProperty.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1136,6 +1140,7 @@
64C772002A975102009868C2 /* Reference+Util.swift */,
6464074E2A9F62D4006FF769 /* Date+Ext.swift */,
648BD5702AC583AC004A3A95 /* TimeFormat.swift */,
64A42F3A2B07A7A3001C3ACC /* SymbolParser.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1244,6 +1249,14 @@
path = Candles;
sourceTree = "<group>";
};
64A42F3C2B07A7F4001C3ACC /* QDS */ = {
isa = PBXGroup;
children = (
64A42F3D2B07A807001C3ACC /* NativeSymbolParser.swift */,
);
path = QDS;
sourceTree = "<group>";
};
64ACBCDB2A28974900032C53 /* Osub */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1468,6 +1481,7 @@
8088D77A29C5D8AD00F240CB /* Native */ = {
isa = PBXGroup;
children = (
64A42F3C2B07A7F4001C3ACC /* QDS */,
80FC415A29CA2B7100E6B611 /* Endpoint */,
8088D77B29C8D96600F240CB /* ErrorHandling */,
642BE4C52A2E1B550052340A /* Events */,
Expand Down Expand Up @@ -2169,6 +2183,7 @@
6486B9732AD045C800D8D5FA /* TheoPrice.swift in Sources */,
64ACBCDF2A2897EA00032C53 /* String+Symbol.swift in Sources */,
64B4363A2AB86D1A0003919E /* DayFilter.swift in Sources */,
64A42F3B2B07A7A3001C3ACC /* SymbolParser.swift in Sources */,
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */,
6406F2572AD9820700B58C42 /* NativePublisher.swift in Sources */,
6486B9772AD04C5800D8D5FA /* TheoPriceMapper.swift in Sources */,
Expand Down Expand Up @@ -2258,6 +2273,7 @@
649F48862A615BC90016FDD1 /* CandleSymbol.swift in Sources */,
646407492A9DF984006FF769 /* InstrumentProfileMapper.swift in Sources */,
64656F6B2A1CFAC2006A0B19 /* BridgeUtil.swift in Sources */,
64A42F3E2B07A807001C3ACC /* NativeSymbolParser.swift in Sources */,
8088D77329C3A2F400F240CB /* GraalException.swift in Sources */,
64C771FF2A9504ED009868C2 /* SnapshotProcessor.swift in Sources */,
64C771F82A94B88C009868C2 /* TimeAndSaleType.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions DXFeedFramework/Native/QDS/NativeSymbolParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NativeSymbolParser.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 17.11.23.
//

import Foundation
@_implementationOnly import graal_api

class NativeSymbolParser {
func parse(_ symbols: String) throws -> [String] {
let thread = currentThread()
let symbols = try ErrorCheck.nativeCall(thread, dxfg_Tools_parseSymbols(thread, symbols.toCStringRef()))
var result = [String]()
for index in 0..<Int(symbols.pointee.size) {
result.append(String(pointee: symbols.pointee.elements[index]))
}
try ErrorCheck.nativeCall(thread, dxfg_CList_String_release(thread, symbols))
return result
}
}
21 changes: 21 additions & 0 deletions DXFeedFramework/Utils/SymbolParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// SymbolParser.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 17.11.23.
//

import Foundation

public class SymbolParser {
/// It returs list of symbols.
///
/// You can use input like this
/// "ipf[https://demo:[email protected]/ipf?TYPE=STOCK&compression=zip],APPL"
/// It will download symbols from ipf endpoint.
/// - Throws: GraalException. Rethrows exception from Java.
public static func parse(_ symbols: String) throws -> [String] {
let nativeParser = NativeSymbolParser()
return try nativeParser.parse(symbols)
}
}
41 changes: 1 addition & 40 deletions Samples/Tools/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,49 +107,10 @@ Cmd \(cmd) contains not enough \(cmd.count - 1) arguments. Expected \(requiredNu
if namelessParameters.count <= index {
return [WildcardSymbol.all]
}

let symbols = namelessParameters[index]
if symbols.lowercased() == "all" {
return [WildcardSymbol.all]
}

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)
return symbolsList
return (try? SymbolParser.parse(symbols)) ?? [String]()
}
}

0 comments on commit e003e7f

Please sign in to comment.