Skip to content

Commit

Permalink
add mapper for summary
Browse files Browse the repository at this point in the history
FIX: missed eventsymbol, eventtime in to native convert
  • Loading branch information
kosyloa committed Oct 6, 2023
1 parent 861e1e2 commit 8563e43
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 9 deletions.
8 changes: 8 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
6486B9582AD00BDC00D8D5FA /* Summary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B9572AD00BDC00D8D5FA /* Summary.swift */; };
6486B95B2AD015B400D8D5FA /* PriceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B95A2AD015B400D8D5FA /* PriceType.swift */; };
6486B95D2AD0287E00D8D5FA /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B95C2AD0287E00D8D5FA /* DateTests.swift */; };
6486B95F2AD02C0C00D8D5FA /* Summary+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B95E2AD02C0C00D8D5FA /* Summary+Ext.swift */; };
6486B9612AD02D3900D8D5FA /* SummaryMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B9602AD02D3900D8D5FA /* SummaryMapper.swift */; };
648BD5692AC450D6004A3A95 /* ConnectCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD5682AC450D6004A3A95 /* ConnectCommand.swift */; };
648BD56B2AC4576F004A3A95 /* HelpCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56A2AC4576F004A3A95 /* HelpCommand.swift */; };
648BD56D2AC56A04004A3A95 /* SubscriptionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */; };
Expand Down Expand Up @@ -614,6 +616,8 @@
6486B9572AD00BDC00D8D5FA /* Summary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Summary.swift; sourceTree = "<group>"; };
6486B95A2AD015B400D8D5FA /* PriceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceType.swift; sourceTree = "<group>"; };
6486B95C2AD0287E00D8D5FA /* DateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = "<group>"; };
6486B95E2AD02C0C00D8D5FA /* Summary+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Summary+Ext.swift"; sourceTree = "<group>"; };
6486B9602AD02D3900D8D5FA /* SummaryMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryMapper.swift; sourceTree = "<group>"; };
648BD5682AC450D6004A3A95 /* ConnectCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectCommand.swift; sourceTree = "<group>"; };
648BD56A2AC4576F004A3A95 /* HelpCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpCommand.swift; sourceTree = "<group>"; };
648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionUtils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -933,6 +937,8 @@
64BA926A2A3072CA00BE26A0 /* TradeMapper.swift */,
64278C6F2A602FA00074B5AA /* Candle+Ext.swift */,
64278C712A6030290074B5AA /* CandleMapper.swift */,
6486B95E2AD02C0C00D8D5FA /* Summary+Ext.swift */,
6486B9602AD02D3900D8D5FA /* SummaryMapper.swift */,
);
path = Markets;
sourceTree = "<group>";
Expand Down Expand Up @@ -2050,6 +2056,7 @@
6447A5DB2A8E559000739CCF /* ILastingEvent.swift in Sources */,
64ACBCDD2A28978600032C53 /* Symbol.swift in Sources */,
64B4363E2AB883350003919E /* SessionFilter.swift in Sources */,
6486B9612AD02D3900D8D5FA /* SummaryMapper.swift in Sources */,
64B436402AB8857F0003919E /* SessionFilter+Ext.swift in Sources */,
646407592AA0CA8D006FF769 /* NativeProfileIterator.swift in Sources */,
6469F8C82A3B25C900846831 /* MarketEvent+Access.swift in Sources */,
Expand All @@ -2070,6 +2077,7 @@
64104FD32A277B2D00D1FC41 /* ListNative.swift in Sources */,
642BE4C82A2E1BD40052340A /* QuoteMapper.swift in Sources */,
64AAF0552A82499A00E8942B /* ConcurrentDict.swift in Sources */,
6486B95F2AD02C0C00D8D5FA /* Summary+Ext.swift in Sources */,
64ACBCE12A28999B00032C53 /* WildcardSymbol.swift in Sources */,
64C771F42A94A86E009868C2 /* Side.swift in Sources */,
64656F672A1CCFC2006A0B19 /* DXPublisher.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ extension MarketEvent {
public var candle: Candle {
return (self as? Candle)!
}
/// Use only for event.type is ``EventCode/summary``
public var summary: Summary {
return (self as? Summary)!
}
}
7 changes: 5 additions & 2 deletions DXFeedFramework/Events/Market/Extra/PriceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public enum PriceType: DXPriceType, CaseIterable {
case preliminary = 2
case final = 3

private static let types: [PriceType] = EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .regular, allCases: PriceType.allCases)

private static let types: [PriceType] = {
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .regular,
allCases: PriceType.allCases)
}()

public static func valueOf(_ value: Int) -> PriceType {
return PriceType.types[value]
}
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Summary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Summary: MarketEvent, ILastingEvent, CustomStringConvertible {
var flags: Int32 = 0

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

Expand Down
12 changes: 7 additions & 5 deletions DXFeedFramework/Native/Events/EventMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class EventMapper: Mapper {
}

private let mappers: [EventCode: any Mapper] = [.quote: QuoteMapper(),
.timeAndSale: TimeAndSaleMapper(),
.profile: ProfileMapper(),
.trade: TradeMapper(),
.candle: CandleMapper()]
.timeAndSale: TimeAndSaleMapper(),
.profile: ProfileMapper(),
.trade: TradeMapper(),
.candle: CandleMapper(),
.summary: SummaryMapper()]

func fromNative(native: UnsafeMutablePointer<dxfg_event_type_t>) throws -> MarketEvent? {
let code = try EnumUtil.valueOf(value: EventCode.convert(native.pointee.clazz))
Expand All @@ -34,7 +35,8 @@ class EventMapper: Mapper {
func toNative(event: MarketEvent) throws -> UnsafeMutablePointer<dxfg_event_type_t>? {
let code = event.type
if let mapper = mappers[code] {
return try mapper.toNative(event: event)
let native = try mapper.toNative(event: event)
return native
}
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion DXFeedFramework/Native/Events/Markets/CandleMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class CandleMapper: Mapper {
func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_candle_t>.allocate(capacity: 1)
var pointee = pointer.pointee
let candle = event.candle
pointee.event_symbol = event.eventSymbol.toCStringRef()
pointee.event_time = event.eventTime

let candle = event.candle
pointee.event_flags = candle.eventFlags
pointee.index = candle.index
pointee.count = candle.count
Expand Down
3 changes: 3 additions & 0 deletions DXFeedFramework/Native/Events/Markets/ProfileMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ProfileMapper: Mapper {
func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_profile_t>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

let profile = event.profile
pointee.description = profile.descriptionStr?.toCStringRef()
pointee.status_reason = profile.statusReason?.toCStringRef()
Expand Down
3 changes: 3 additions & 0 deletions DXFeedFramework/Native/Events/Markets/QuoteMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class QuoteMapper: Mapper {
func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_quote_t>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

let quote = event.quote
pointee.time_millis_sequence = quote.timeMillisSequence
pointee.time_nano_part = quote.timeNanoPart
Expand Down
26 changes: 26 additions & 0 deletions DXFeedFramework/Native/Events/Markets/Summary+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Summary+Ext.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 06.10.23.
//

import Foundation
@_implementationOnly import graal_api

extension Summary {
convenience init(native: dxfg_summary_t) {
self.init(String(pointee: native.market_event.event_symbol))
self.eventTime = native.market_event.event_time
self.dayId = native.day_id
self.dayOpenPrice = native.day_open_price
self.dayHighPrice = native.day_high_price
self.dayLowPrice = native.day_low_price
self.dayClosePrice = native.day_close_price
self.prevDayId = native.prev_day_id
self.prevDayClosePrice = native.prev_day_close_price
self.prevDayVolume = native.prev_day_volume
self.openInterest = native.open_interest
self.flags = native.flags
}
}
45 changes: 45 additions & 0 deletions DXFeedFramework/Native/Events/Markets/SummaryMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// SummaryMapper.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 06.10.23.
//

import Foundation
@_implementationOnly import graal_api

class SummaryMapper: Mapper {
var type = dxfg_summary_t.self

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

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

let summary = event.summary
pointee.day_id = summary.dayId
pointee.day_open_price = summary.dayOpenPrice
pointee.day_high_price = summary.dayHighPrice
pointee.day_low_price = summary.dayLowPrice
pointee.day_close_price = summary.dayClosePrice
pointee.prev_day_id = summary.prevDayId
pointee.prev_day_close_price = summary.prevDayClosePrice
pointee.prev_day_volume = summary.prevDayVolume
pointee.open_interest = summary.openInterest
pointee.flags = summary.flags

let eventType = pointer.withMemoryRebound(to: dxfg_event_type_t.self, capacity: 1) { pointer in
pointer.pointee.clazz = DXFG_EVENT_SUMMARY
return pointer
}
return eventType
}
}
3 changes: 3 additions & 0 deletions DXFeedFramework/Native/Events/Markets/TimeAndSaleMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class TimeAndSaleMapper: Mapper {
func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_time_and_sale_t>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

let timeAndSale = event.timeAndSale
pointee.event_flags = timeAndSale.eventFlags
pointee.index = timeAndSale.index
Expand Down
3 changes: 3 additions & 0 deletions DXFeedFramework/Native/Events/Markets/TradeMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class TradeMapper: Mapper {
func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_trade_base_t>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

let trade = event.trade
pointee.time_sequence = trade.timeSequence
pointee.time_nano_part = trade.timeNanoPart
Expand Down

0 comments on commit 8563e43

Please sign in to comment.