Skip to content

Commit

Permalink
add more parameters for connect tool
Browse files Browse the repository at this point in the history
refactoring IndexedEventSubscriptionSymbol
  • Loading branch information
kosyloa committed Nov 6, 2023
1 parent a16653a commit 61d0385
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "Connect demo.dxfeed.com:7300 TimeAndSale &quot;ipf[https://demo:[email protected]/ipf?TYPE=STOCK&amp;compression=zip],APPL&quot;"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect demo.dxfeed.com:7300 quote AAPL -f 2012-05-26-14:15:00"
Expand All @@ -93,7 +93,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "Dump tapeK2.tape[speed=max] -t ios_tapeK2.tape -q"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "LatencyTest mddqa.in.devexperts.com:7400 TimeAndSale ETH/USD:GDAX"
Expand Down
39 changes: 35 additions & 4 deletions DXFeedFramework/Api/Osub/IndexedEventSubscriptionSymbol.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// IndexedEventSubscriptionSymbol.swift
// GenericIndexedEventSubscriptionSymbol.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 01.06.23.
Expand All @@ -17,7 +17,7 @@ import Foundation
/// [Javadoc](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/osub/IndexedEventSubscriptionSymbol.html)
///
/// `T`: The type of event symbol
public class IndexedEventSubscriptionSymbol<T: Equatable>: Symbol {
public class GenericIndexedEventSubscriptionSymbol<T: Equatable>: Symbol {
/// Gets event symbol.
let symbol: T
/// Gets indexed event source. ``IndexedEventSource``
Expand All @@ -39,8 +39,39 @@ public class IndexedEventSubscriptionSymbol<T: Equatable>: Symbol {
}
}

extension IndexedEventSubscriptionSymbol: Equatable {
public static func == (lhs: IndexedEventSubscriptionSymbol<T>, rhs: IndexedEventSubscriptionSymbol<T>) -> Bool {
extension GenericIndexedEventSubscriptionSymbol: Equatable {
public static func == (lhs: GenericIndexedEventSubscriptionSymbol<T>,
rhs: GenericIndexedEventSubscriptionSymbol<T>) -> Bool {
return lhs === rhs || (lhs.symbol == rhs.symbol && lhs.source == rhs.source)
}
}

/// Non-generic version, for using with Symbol protocol without equatable T
public class IndexedEventSubscriptionSymbol: Symbol {
/// Gets event symbol.
let symbol: Symbol
/// Gets indexed event source. ``IndexedEventSource``
let source: IndexedEventSource
/// Initializes a new instance of the ``IndexedEventSubscriptionSymbol`` class
/// with a specified event symbol and source.
///
/// - Parameters:
/// - symbol: The event symbol.
/// - source: The event source.
public init(symbol: Symbol, source: IndexedEventSource) {
self.symbol = symbol
self.source = source
}

/// Custom symbol has to return string representation.
public var stringValue: String {
return "\(symbol.stringValue)source=\(source.toString())"
}
}

extension IndexedEventSubscriptionSymbol: Equatable {
public static func == (lhs: IndexedEventSubscriptionSymbol,
rhs: IndexedEventSubscriptionSymbol) -> Bool {
return lhs === rhs || (lhs.symbol.stringValue == rhs.symbol.stringValue && lhs.source == rhs.source)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
/// [Javadoc](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/osub/TimeSeriesSubscriptionSymbol.html)
///
/// `T`: The type of event symbol.
public class TimeSeriesSubscriptionSymbol: IndexedEventSubscriptionSymbol<AnyHashable> {
public class TimeSeriesSubscriptionSymbol: GenericIndexedEventSubscriptionSymbol<AnyHashable> {
let fromTime: Long
/// Initializes a new instance of the ``TimeSeriesSubscriptionSymbol`` class
/// with a specified event symbol and from time in milliseconds since Unix epoch.
Expand Down
10 changes: 5 additions & 5 deletions DXFeedFramework/Events/Market/Extra/OrderSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Foundation
///
/// There are the following kinds of order sources:
///
/// Synthetic sources ``COMPOSITE_BID``, ``COMPOSITE_ASK``,
/// ``REGIONAL_BID``, and ``REGIONAL_ASK`` are provided for convenience of a consolidated
/// Synthetic sources ``compsoiteBid``, ``compsoiteAsk``,
/// ``regionalBid``, and ``regionalAsk`` are provided for convenience of a consolidated
/// order book and are automatically generated based on the corresponding ``Quote`` events.
/// Aggregate sources ``AGGREGATE_BID`` and ``AGGREGATE_ASK`` provide
/// Aggregate sources ``agregateBid`` and ``agregateAsk`` provide
/// futures depth (aggregated by price level) and NASDAQ Level II (top of book for each market maker).
/// These source cannot be directly published to via dxFeed API.
/// ``isPublishable(Class) Publishable`` sources ``DEFAULT``, ``NTV``, and ``ISE``
/// ``isPublishable(eventType:)`` sources ``defaultOrderSource``, ``NTV``, and ``ISE``
/// support full range of dxFeed API features.
///
///
Expand Down Expand Up @@ -294,7 +294,7 @@ public class OrderSource: IndexedEventSource {
/// Gets a value indicating whether the given event type can be directly published with this source.
///
/// Subscription on such sources can be observed directly via ``DXPublisher``
/// Subscription on such sources is observed via instances of ``IndexedEventSubscriptionSymbol``
/// Subscription on such sources is observed via instances of ``GenericIndexedEventSubscriptionSymbol``
/// - Parameters:
/// - eventype : Possible values ``Order``, ``AnalyticOrder``, ``SpreadOrder``
/// - Returns: true- events can be directly published with this source
Expand Down
3 changes: 2 additions & 1 deletion Samples/Tools/ConnectTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Where:
types: arguments.parseTypes(at: 2),
listener: self,
properties: arguments.properties,
time: arguments.time)
time: arguments.time,
source: arguments.source)

// Print till input new line
_ = readLine()
Expand Down
4 changes: 3 additions & 1 deletion Samples/Tools/LiveIpfSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class LiveIpfSample: ToolsCommand {
func execute() {
do {
collector = try DXInstrumentProfileCollector()
connection = try DXInstrumentProfileConnection(arguments.count > 1 ? arguments[1] : LiveIpfSample.defaultIpfUrl, collector!)
connection = try DXInstrumentProfileConnection(arguments.count > 1 ?
arguments[1] :
LiveIpfSample.defaultIpfUrl, 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(listener: self)
Expand Down
11 changes: 10 additions & 1 deletion Samples/Tools/SubscriptionUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Subscription {
types: [EventCode],
listener: O,
properties: [String: String],
time: String?)
time: String?,
source: String? = nil)
where O: DXEventListener, O: Hashable {
print("""
Create subscription to \(address) for \(types):\(symbols) with properties:\(properties) and time \(time ?? "---")
Expand All @@ -40,6 +41,13 @@ Create subscription to \(address) for \(types):\(symbols) with properties:\(prop
TimeSeriesSubscriptionSymbol(symbol: symbol, date: date)
}
try? subscription?.addSymbols(timeSubscriptionSymbols)
} else if source != nil {
if let source = try? OrderSource.valueOf(name: source!) {
let indexedEventSubscriptionSymbols = symbols.map { symbol in
IndexedEventSubscriptionSymbol(symbol: symbol, source: source)
}
try? subscription?.addSymbols(indexedEventSubscriptionSymbols)
}
} else {
try? subscription?.addSymbols(symbols)
}
Expand All @@ -49,3 +57,4 @@ Create subscription to \(address) for \(types):\(symbols) with properties:\(prop
}
}
}

0 comments on commit 61d0385

Please sign in to comment.