Skip to content

Commit

Permalink
refactor market event(each of them has type EventCode)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Jan 5, 2024
1 parent 164c67d commit 5b3dec4
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "Connect demo.dxfeed.com:7300 quote AAPL,IBM"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = " Dump demo.dxfeed.com:7300 timeandsale,quote,profile,order,trade IBM,AAPL,ETH/USD:GDAX -p dxfeed.wildcard.enable=true,one_more_prop=abc -t test_tape_ios.txt[format=text] -q"
Expand All @@ -89,7 +89,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "Dump tapeK2.tape[speed=max] all all -t ios_tapeK2.tape -q"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "DuMp tapeK2.tape[speed=max] -t ios_tapeK2.tape -q"
Expand Down
19 changes: 11 additions & 8 deletions DXFeedFramework/Api/DXFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ public class DXFeed {
/// This method creates new ``DXFeedTimeSeriesSubscription`` and invokes ``attachSubscription``.
///
/// - Parameters:
/// - events: The list of event codes.
/// - events: The list of ITimeSeriesEvent.
/// - Returns: ``DXFeedSubscription``
/// - Throws: ``GraalException``. Rethrows exception from Java, ``ArgumentException/invalidOperationException(_:)``
public func createTimeSeriesSubscription(_ events: [EventCode]) throws -> DXFeedTimeSeriesSubscription {
return try DXFeedTimeSeriesSubscription(native: native.createTimeSeriesSubscription(events), events: events)
/// - Throws: ``GraalException``. Rethrows exception from Java.
public func createTimeSeriesSubscription(_ types: [ITimeSeriesEvent.Type]) throws -> DXFeedTimeSeriesSubscription {
return try DXFeedTimeSeriesSubscription(native: native.createTimeSeriesSubscription(types.map { $0.type}),
events: types.map { $0.type})
}

/// Creates new time series subscription for a single event type that is <i>attached</i> to this feed.
Expand All @@ -63,10 +64,12 @@ public class DXFeed {
/// This method creates new ``DXFeedTimeSeriesSubscription`` and invokes ``attachSubscription``.
///
/// - Parameters:
/// - event: event code.
/// - type: type of ITimeSeriesEvent.
/// - Returns: ``DXFeedSubscription``
/// - Throws: ``GraalException``. Rethrows exception from Java, ``ArgumentException/invalidOperationException(_:)``
public func createTimeSeriesSubscription(_ event: EventCode) throws -> DXFeedTimeSeriesSubscription {
return try DXFeedTimeSeriesSubscription(native: native.createTimeSeriesSubscription(event), events: [event])
/// - Throws: ``GraalException``. Rethrows exception from Java.
public func createTimeSeriesSubscription(_ type: ITimeSeriesEvent.Type) throws -> DXFeedTimeSeriesSubscription {
return try DXFeedTimeSeriesSubscription(
native: native.createTimeSeriesSubscription(type.type),
events: [type.type])
}
}
9 changes: 0 additions & 9 deletions DXFeedFramework/Events/EventCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,3 @@ public extension EventCode {
}
}

public extension EventCode {
func isTimeSeriesEvent() -> Bool {
return self == .candle ||
self == .timeAndSale ||
self == .greeks ||
self == .underlying ||
self == .theoPrice
}
}
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/AnalyticOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/AnalyticOrder.html)
public class AnalyticOrder: Order {
public class override var type: EventCode { .analyticOrder }

/*
* Analytic flags property has several significant bits that are packed into an integer in the following way:
* 31...2 1 0
Expand All @@ -35,7 +37,7 @@ public class AnalyticOrder: Order {
public var icebergFlags: Int32 = 0
/// Initializes a new instance of the ``AnalyticOrder`` class.
public init(_ eventSymbol: String) {
super.init(eventSymbol: eventSymbol, type: .analyticOrder)
super.init(eventSymbol: eventSymbol)
}

/// Returns string representation of this candle event.
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Candles/Candle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Foundation
/// with a data taken from the specified ``CandleExchange`` from the specified ``CandleSession``
/// with further details of aggregation provided by ``CandleAlignment``.
public class Candle: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .candle }

/// Gets or sets candle symbol object.
public override var eventSymbol: String {
get {
Expand Down Expand Up @@ -62,7 +64,7 @@ public class Candle: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringC

/// Initializes a new instance of the ``Candle`` class with the specified event symbol.
public convenience init(_ symbol: CandleSymbol) {
self.init(type: .candle)
self.init()
self.candleSymbol = symbol
}

Expand Down
3 changes: 3 additions & 0 deletions DXFeedFramework/Events/Market/Extra/IEventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public protocol IEventType {

/// Hashcode fot perftest and other purposes.
var hashCode: Int { get }

static var type: EventCode { get }

}
6 changes: 4 additions & 2 deletions DXFeedFramework/Events/Market/Extra/MarketEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public class MarketEvent: IEventType {
return "Override toString() method"
}

internal init(type: EventCode) {
self.type = type
internal init() {
self.type = Self.type
}

public class var type: EventCode { fatalError("Override type field") }
}

public struct MarketEventConst {
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/Extra/OrderBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public class OrderBase: MarketEvent, IIndexedEvent, CustomStringConvertible {
/// Gets or sets trade size for events containing trade-related action.
public var tradeSize: Double = .nan

init(eventSymbol: String, type: EventCode) {
super.init(type: type)
init(eventSymbol: String) {
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Extra/TradeBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class TradeBase: MarketEvent, ILastingEvent {
var flags: Int32 = 0

public init(symbol: String, type: EventCode) {
super.init(type: type)
super.init()
self.eventSymbol = symbol
}

Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Greeks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/option/Greeks.html)
public class Greeks: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .greeks }

public var eventSource: IndexedEventSource = .defaultSource

public var eventFlags: Int32 = 0
Expand Down Expand Up @@ -56,7 +58,7 @@ public class Greeks: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringC
public var vega: Double = .nan

public init(_ eventSymbol: String) {
super.init(type: .greeks)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/OptionSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/OptionSale.html)
public class OptionSale: MarketEvent, IIndexedEvent {
public class override var type: EventCode { .optionSale }

public var eventSource: IndexedEventSource = .defaultSource

Expand Down Expand Up @@ -70,7 +71,7 @@ public class OptionSale: MarketEvent, IIndexedEvent {
public var optionSymbol: String?

public init(_ eventSymbol: String) {
super.init(type: .optionSale)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
9 changes: 3 additions & 6 deletions DXFeedFramework/Events/Market/Order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Order.html)
public class Order: OrderBase {
public class override var type: EventCode { .order }

/// Gets or sets market maker or other aggregate identifier of this order.
/// This value is defined for ``Scope/aggregate`` and ``Scope/order`` orders.
public var marketMaker: String?

public convenience init(_ eventSymbol: String) {
self.init(eventSymbol: eventSymbol, type: .order)
}

/// Initializes a new instance of the ``Order`` class.
override init(eventSymbol: String, type: EventCode) {
super.init(eventSymbol: eventSymbol, type: type)
self.init(eventSymbol: eventSymbol)
}

/// Returns string representation of this candle event.
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Profile.html)
public class Profile: MarketEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .profile }

/*
* Flags property has several significant bits that are packed into an integer in the following way:
* 31..4 3 2 1 0
Expand Down Expand Up @@ -67,7 +69,7 @@ public class Profile: MarketEvent, ILastingEvent, CustomStringConvertible {

/// Initializes a new instance of the ``Profile`` class.
public init(_ symbol: String) {
super.init(type: .profile)
super.init()
self.eventSymbol = symbol
}

Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Quote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Quote.html)
public class Quote: MarketEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .quote }

/// Gets or sets time millis sequence.
/// Do not sets this value directly.
/// Change ``setSequence(_:)`` and/or ``time``.
Expand Down Expand Up @@ -60,7 +62,7 @@ public class Quote: MarketEvent, ILastingEvent, CustomStringConvertible {

/// Initializes a new instance of the ``Quote`` class.
public required init(_ symbol: String) {
super.init(type: .quote)
super.init()
self.eventSymbol = symbol
}
public var description: String {
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Series.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Foundation
///
/// (For more details see)[https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/option/Series.html]
public class Series: MarketEvent, IIndexedEvent {
public class override var type: EventCode { .series }

public var eventSource: IndexedEventSource = .defaultSource

public var eventFlags: Int32 = 0
Expand Down Expand Up @@ -53,7 +55,7 @@ public class Series: MarketEvent, IIndexedEvent {
public var interest: Double = .nan

public init(_ eventSymbol: String) {
super.init(type: .series)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/SpreadOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/SpreadOrder.html)
public class SpreadOrder: OrderBase {
public class override var type: EventCode { .spreadOrder }

/// Gets or sets spread symbol of this event.
public var spreadSymbol: String?

/// Initializes a new instance of the ``SpreadOrder`` class.
public init(_ eventSymbol: String) {
super.init(eventSymbol: eventSymbol, type: .spreadOrder)
super.init(eventSymbol: eventSymbol)
}

/// Returns string representation of this candle event.
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Summary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Summary.html)
public class Summary: MarketEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .summary }

/*
* Flags property has several significant bits that are packed into an integer in the following way:
* 31..4 3 2 1 0
Expand Down Expand Up @@ -57,7 +59,7 @@ public class Summary: MarketEvent, ILastingEvent, CustomStringConvertible {

/// Initializes a new instance of the ``Summary`` class.
public init(_ eventSymbol: String) {
super.init(type: .summary)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/TheoPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/option/TheoPrice.html)
public class TheoPrice: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .theoPrice }

public var eventSource: IndexedEventSource = .defaultSource

Expand Down Expand Up @@ -49,7 +50,7 @@ public class TheoPrice: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStri
public var interest: Double = .nan

public init(_ eventSymbol: String) {
super.init(type: .theoPrice)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/TimeAndSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/TimeAndSale.html)
public class TimeAndSale: MarketEvent, ITimeSeriesEvent, CustomStringConvertible {
public class override var type: EventCode { .timeAndSale }

/*
* Flags property has several significant bits that are packed into an integer in the following way:
* 31..16 15...8 7 6 5 4 3 2 1 0
Expand Down Expand Up @@ -69,7 +71,7 @@ public class TimeAndSale: MarketEvent, ITimeSeriesEvent, CustomStringConvertible
public var index: Long = 0

init(_ symbol: String) {
super.init(type: .timeAndSale)
super.init()
self.eventSymbol = symbol
}

Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Trade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Trade.html)
public class Trade: TradeBase {
public class override var type: EventCode { .trade }

public init(_ symbol: String) {
super.init(symbol: symbol, type: .trade)
super.init(symbol: symbol, type: Self.type)
}

/// Returns string representation of this trade event.
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/TradeETH.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/TradeETH.html)
public class TradeETH: TradeBase {
public class override var type: EventCode { .tradeETH }

public init(_ symbol: String) {
super.init(symbol: symbol, type: .tradeETH)
super.init(symbol: symbol, type: Self.type)
}

/// Returns string representation of this trade event.
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Events/Market/Underlying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/option/Underlying.html)
public class Underlying: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringConvertible {
public class override var type: EventCode { .underlying }

public var eventSource: IndexedEventSource = .defaultSource

public var eventFlags: Int32 = 0
Expand Down Expand Up @@ -42,7 +44,7 @@ public class Underlying: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStr
public var putCallRatio: Double = .nan

public init(_ eventSymbol: String) {
super.init(type: .underlying)
super.init()
self.eventSymbol = eventSymbol
}

Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Events/Markets/Candle+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

extension Candle {
convenience init(native: dxfg_candle_t) {
self.init(type: .candle)
self.init()
self.eventSymbol = String(pointee: native.event_symbol)
self.eventTime = native.event_time
self.eventFlags = native.event_flags
Expand Down
10 changes: 1 addition & 9 deletions DXFeedFramework/Native/Feed/NativeFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ class NativeFeed {
event.nativeCode()))
return NativeSubscription(subscription: subscription)
}

func createTimeSeriesSubscription(_ events: [EventCode]) throws -> NativeTimeSeriesSubscription? {
try events.forEach {
if !$0.isTimeSeriesEvent() {
throw ArgumentException.invalidOperationException("\($0) is not TimeSeriesEvent")
}
}
let nativeCodes = events.map { $0.nativeCode() }
let elements = ListNative(elements: nativeCodes)
let listPointer = elements.newList()
Expand All @@ -71,9 +66,6 @@ class NativeFeed {
}

func createTimeSeriesSubscription(_ event: EventCode) throws -> NativeTimeSeriesSubscription? {
if !event.isTimeSeriesEvent() {
throw ArgumentException.invalidOperationException("\(event) is not TimeSeriesEvent")
}
let thread = currentThread()
let subscription = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_createTimeSeriesSubscription(thread,
Expand Down
Loading

0 comments on commit 5b3dec4

Please sign in to comment.