Skip to content

Commit

Permalink
Series: ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 13, 2023
1 parent e5397da commit f3a673b
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 77 deletions.
12 changes: 8 additions & 4 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
649282ED2AD593F3008F0F04 /* OrderSourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */; };
64963B6A2A8E545C001E40F7 /* IEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64963B692A8E545C001E40F7 /* IEventType.swift */; };
649706842AD82B070068FF88 /* Series.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706832AD82B070068FF88 /* Series.swift */; };
649706862AD832860068FF88 /* Series+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706852AD832860068FF88 /* Series+Ext.swift */; };
6498E6B22AB1D41A0093A065 /* DXSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B12AB1D41A0093A065 /* DXSchedule.swift */; };
6498E6B52AB1D4480093A065 /* NativeSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B42AB1D4480093A065 /* NativeSchedule.swift */; };
6498E6B72AB1DACE0093A065 /* ScheduleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B62AB1DACE0093A065 /* ScheduleTest.swift */; };
Expand Down Expand Up @@ -288,7 +289,6 @@
64BDDB2E2AD7DC5E00694210 /* OrderMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB2D2AD7DC5E00694210 /* OrderMapper.swift */; };
64BDDB312AD7E5A600694210 /* AnalyticOrderMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB2F2AD7E5A500694210 /* AnalyticOrderMapper.swift */; };
64BDDB322AD7E5A600694210 /* SpreadOrderMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB302AD7E5A600694210 /* SpreadOrderMapper.swift */; };
64BDDB342AD7F1FE00694210 /* OrderTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB332AD7F1FE00694210 /* OrderTest.swift */; };
64C771F22A94A224009868C2 /* Character+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C771F12A94A224009868C2 /* Character+Ext.swift */; };
64C771F42A94A86E009868C2 /* Side.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C771F32A94A86E009868C2 /* Side.swift */; };
64C771F62A94ADDA009868C2 /* Direction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C771F52A94ADDA009868C2 /* Direction.swift */; };
Expand All @@ -314,6 +314,7 @@
64DB79352A376E1B00229597 /* DXFeedFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
64E342502AAB083700457994 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6469F8D22A3B401700846831 /* Colors.swift */; };
64E342522AAB29CF00457994 /* InstrumentProfileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64E342512AAB29CF00457994 /* InstrumentProfileType.swift */; };
64E3637B2AD83459002E2B0D /* SeriesMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64E3637A2AD83459002E2B0D /* SeriesMapper.swift */; };
64ECD67F2A9CF4CB00B36935 /* IPFTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD67E2A9CF4CB00B36935 /* IPFTests.swift */; };
64ECD6822A9DDC2800B36935 /* DXInstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6812A9DDC2800B36935 /* DXInstrumentProfileReader.swift */; };
64ECD6852A9DDF6200B36935 /* DXInstrumentProfileCollector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6842A9DDF6200B36935 /* DXInstrumentProfileCollector.swift */; };
Expand Down Expand Up @@ -665,6 +666,7 @@
649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderSourceTest.swift; sourceTree = "<group>"; };
64963B692A8E545C001E40F7 /* IEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IEventType.swift; sourceTree = "<group>"; };
649706832AD82B070068FF88 /* Series.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Series.swift; sourceTree = "<group>"; };
649706852AD832860068FF88 /* Series+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Series+Ext.swift"; sourceTree = "<group>"; };
6498E6B12AB1D41A0093A065 /* DXSchedule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXSchedule.swift; sourceTree = "<group>"; };
6498E6B42AB1D4480093A065 /* NativeSchedule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSchedule.swift; sourceTree = "<group>"; };
6498E6B62AB1DACE0093A065 /* ScheduleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -740,7 +742,6 @@
64BDDB2D2AD7DC5E00694210 /* OrderMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderMapper.swift; sourceTree = "<group>"; };
64BDDB2F2AD7E5A500694210 /* AnalyticOrderMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyticOrderMapper.swift; sourceTree = "<group>"; };
64BDDB302AD7E5A600694210 /* SpreadOrderMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpreadOrderMapper.swift; sourceTree = "<group>"; };
64BDDB332AD7F1FE00694210 /* OrderTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderTest.swift; sourceTree = "<group>"; };
64C771F12A94A224009868C2 /* Character+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Character+Ext.swift"; sourceTree = "<group>"; };
64C771F32A94A86E009868C2 /* Side.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Side.swift; sourceTree = "<group>"; };
64C771F52A94ADDA009868C2 /* Direction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Direction.swift; sourceTree = "<group>"; };
Expand All @@ -764,6 +765,7 @@
64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnectionObserver.swift; sourceTree = "<group>"; };
64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeIPFConnectionListener.swift; sourceTree = "<group>"; };
64E342512AAB29CF00457994 /* InstrumentProfileType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileType.swift; sourceTree = "<group>"; };
64E3637A2AD83459002E2B0D /* SeriesMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeriesMapper.swift; sourceTree = "<group>"; };
64ECD67E2A9CF4CB00B36935 /* IPFTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPFTests.swift; sourceTree = "<group>"; };
64ECD6812A9DDC2800B36935 /* DXInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileReader.swift; sourceTree = "<group>"; };
64ECD6842A9DDF6200B36935 /* DXInstrumentProfileCollector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileCollector.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1010,6 +1012,8 @@
64BDDB302AD7E5A600694210 /* SpreadOrderMapper.swift */,
64BDDB2B2AD7DB9B00694210 /* AnalyticOrder+Ext.swift */,
64BDDB2F2AD7E5A500694210 /* AnalyticOrderMapper.swift */,
649706852AD832860068FF88 /* Series+Ext.swift */,
64E3637A2AD83459002E2B0D /* SeriesMapper.swift */,
);
path = Markets;
sourceTree = "<group>";
Expand Down Expand Up @@ -1414,7 +1418,6 @@
64098F662ACEB6F70020D741 /* DXConnectionStateTests.swift */,
6486B95C2AD0287E00D8D5FA /* DateTests.swift */,
649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */,
64BDDB332AD7F1FE00694210 /* OrderTest.swift */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2118,6 +2121,7 @@
64ACBCE62A28BA7D00032C53 /* SymbolMapper.swift in Sources */,
64ECD6822A9DDC2800B36935 /* DXInstrumentProfileReader.swift in Sources */,
6486B9712AD0445E00D8D5FA /* UnderlyingMapper.swift in Sources */,
64E3637B2AD83459002E2B0D /* SeriesMapper.swift in Sources */,
642BE4CC2A2E1DB70052340A /* Mapper.swift in Sources */,
64104FC72A2613BC00D1FC41 /* ConcurrentArray.swift in Sources */,
6498E6B22AB1D41A0093A065 /* DXSchedule.swift in Sources */,
Expand Down Expand Up @@ -2166,6 +2170,7 @@
6447A5E32A8F611700739CCF /* IObservableSubscription.swift in Sources */,
64104FC92A26298D00D1FC41 /* DXFeedSubcription.swift in Sources */,
64104FD32A277B2D00D1FC41 /* ListNative.swift in Sources */,
649706862AD832860068FF88 /* Series+Ext.swift in Sources */,
642BE4C82A2E1BD40052340A /* QuoteMapper.swift in Sources */,
64AAF0552A82499A00E8942B /* ConcurrentDict.swift in Sources */,
6486B95F2AD02C0C00D8D5FA /* Summary+Ext.swift in Sources */,
Expand Down Expand Up @@ -2250,7 +2255,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
64BDDB342AD7F1FE00694210 /* OrderTest.swift in Sources */,
6426C8912A531AAE00236784 /* EndpointTest.swift in Sources */,
6401A5162A582141009BA686 /* SystemPropertyTest.swift in Sources */,
64D0DBE82A29FF4B00710605 /* EventsTest.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ extension MarketEvent {
public var analyticOrder: AnalyticOrder {
return (self as? AnalyticOrder)!
}

/// Use only for event.type is ``EventCode/series``
public var series: Series {
return (self as? Series)!
}
}
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/Extra/OrderSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ public class OrderSource: IndexedEventSource {
}

if !OrderSource.sourcesById.tryInsert(key: identifier, value: self) {
throw ArgumentException.exception("duplicate id")
throw ArgumentException.exception("duplicate id \(identifier)")
}
if !OrderSource.sourcesByName.tryInsert(key: name, value: self) {
throw ArgumentException.exception("duplicate name")
throw ArgumentException.exception("duplicate name \(name)")
}
}

Expand Down
19 changes: 10 additions & 9 deletions DXFeedFramework/Events/Market/Series.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ public class Series: MarketEvent, IIndexedEvent {
/// This method is intended for efficient series time priority comparison.
/// **Do not use this method directly**
/// Change ``time`` and/or ``sequence``
public private(set) var timeSequence: Long = 0
public var timeSequence: Long = 0
/// Gets or sets day id of expiration.
public let expiration: Int32 = 0
public var expiration: Int32 = 0
/// Gets or sets implied volatility index for this series based on VIX methodology.
public let volatility: Double = .nan
public var volatility: Double = .nan
/// Gets or sets call options traded volume for a day.
public let callVolume: Double = .nan
public var callVolume: Double = .nan
/// Gets or sets put options traded volume for a day.
public let putVolume: Double = .nan
public var putVolume: Double = .nan
/// Gets or sets ratio of put options traded volume to call options traded volume for a day.
public let putCallRatio: Double = .nan
public var putCallRatio: Double = .nan
/// Gets or sets implied forward price for this option series.
public let forwardPrice: Double = .nan
public var forwardPrice: Double = .nan
/// Gets or sets implied simple dividend return of the corresponding option series.
public let dividend: Double = .nan
public var dividend: Double = .nan
/// Gets or sets implied simple interest return of the corresponding option series.
public let interest: Double = .nan
public var interest: Double = .nan

public init(_ eventSymbol: String) {
self.eventSymbol = eventSymbol
Expand Down Expand Up @@ -103,6 +103,7 @@ extension Series {
return callVolume.isNaN ? putVolume : putVolume + putVolume;
}

/// Returns string representation of this candle event.
public func toString() -> String {
return
"""
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Native/Events/EventMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class EventMapper: Mapper {
.theoPrice: TheoPriceMapper(),
.order: OrderMapper(),
.analyticOrder: AnalyticOrderMapper(),
.spreadOrder: SpreadOrderMapper()]
.spreadOrder: SpreadOrderMapper(),
.series: SeriesMapper()]

func fromNative(native: UnsafeMutablePointer<dxfg_event_type_t>) throws -> MarketEvent? {
let code = try EnumUtil.valueOf(value: EventCode.convert(native.pointee.clazz))
Expand Down
28 changes: 28 additions & 0 deletions DXFeedFramework/Native/Events/Markets/Series+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Series+Ext.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 12.10.23.
//

import Foundation
@_implementationOnly import graal_api

extension Series {
convenience init(native: dxfg_series_t) {
self.init(String(pointee: native.market_event.event_symbol))

self.eventTime = native.market_event.event_time
self.eventFlags = native.event_flags
self.index = native.index
self.timeSequence = native.time_sequence
self.expiration = native.expiration
self.volatility = native.volatility
self.callVolume = native.call_volume
self.putVolume = native.put_volume
self.putCallRatio = native.put_call_ratio
self.forwardPrice = native.forward_price
self.dividend = native.dividend
self.interest = native.interest
}
}
47 changes: 47 additions & 0 deletions DXFeedFramework/Native/Events/Markets/SeriesMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SeriesMapper.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 12.10.23.
//

import Foundation
@_implementationOnly import graal_api

class SeriesMapper: Mapper {
let type = dxfg_series_t.self

func fromNative(native: UnsafeMutablePointer<dxfg_event_type_t>) -> MarketEvent? {
let event = native.withMemoryRebound(to: type, capacity: 1) { native in
return Series(native: native.pointee)
}
return event
}

func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<TypeAlias>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

let series = event.series

pointee.index = series.index
pointee.event_flags = series.eventFlags
pointee.time_sequence = series.timeSequence
pointee.expiration = series.expiration
pointee.volatility = series.volatility
pointee.call_volume = series.callVolume
pointee.put_volume = series.putVolume
pointee.put_call_ratio = series.putCallRatio
pointee.forward_price = series.forwardPrice
pointee.dividend = series.dividend
pointee.interest = series.interest

let eventType = pointer.withMemoryRebound(to: dxfg_event_type_t.self, capacity: 1) { pointer in
pointer.pointee.clazz = DXFG_EVENT_SERIES
return pointer
}
return eventType
}
}
15 changes: 10 additions & 5 deletions DXFeedFrameworkTests/FeedTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ final class FeedTest: XCTestCase {
try waitingEvent(code: .candle)
}

func testSeries() throws {
try waitingEvent(code: .series)
}

func testOrder() throws {
try waitingEvent(code: .order)
}

static func checkType(_ code: EventCode, _ event: MarketEvent?) -> Bool {
switch code {
case .timeAndSale:
Expand Down Expand Up @@ -133,15 +141,12 @@ final class FeedTest: XCTestCase {
break
case .order:
return event is Order
break
case .analyticOrder:
return event is AnalyticOrder
break
case .spreadOrder:
return event is SpreadOrder
break
case .series:
break
return event is Series
case .optionSale:
break
}
Expand All @@ -166,7 +171,7 @@ final class FeedTest: XCTestCase {
return anonymCl
}
try subscription?.add(observer: listener)
try subscription?.addSymbols(["ETH/USD:GDAX"])
try subscription?.addSymbols(["ETH/USD:GDAX", "IBM"])
wait(for: [receivedEventExp], timeout: 10)
}
}
9 changes: 0 additions & 9 deletions DXFeedFrameworkTests/OrderSourceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ final class OrderSourceTest: XCTestCase {
XCTAssert(false, "should be generated exception")
}

func testCreateOrderSource() throws {
do {
_ = try OrderSource(5, "COMPOSITE_ASK2", 0)
_ = try OrderSource(6, "COMPOSITE_ASK4", 0)
} catch {
XCTAssert(false, "undefined error \(error)")
}
}

func testVAlueOf() throws {
do {
let source1 = OrderSource.compsoiteBid
Expand Down
46 changes: 0 additions & 46 deletions DXFeedFrameworkTests/OrderTest.swift

This file was deleted.

0 comments on commit f3a673b

Please sign in to comment.