Skip to content

Commit

Permalink
fixes for new(not published graal)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Mar 15, 2024
1 parent 95b3df3 commit edea479
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 82 deletions.
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/EventCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public enum EventCode: CaseIterable {
case order
/// See ``AnalyticOrder``
case analyticOrder
/// See ``OtcMarketsOrder``
case otcMarketsOrder
/// See ``SpreadOrder``
case spreadOrder
/// See ``Series``
case series
/// See ``OptionSale``
case optionSale
/// See ``OtcMarketsOrder``
case otcMarketsOrder
}
65 changes: 32 additions & 33 deletions DXFeedFramework/Events/Market/OtcMarketsOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@ public class OtcMarketsOrder: Order {
/// | Extended Quote Flags | Quote Flags |
/// +-----------------------------------------------------+-------------------------------------+
*/
// swiftlint:disable identifier_name
private static let NMS_CONDITIONAL: Long = 1 << 6
private static let AUTO_EXECUTION: Long = 1 << 5
private static let SATURATED: Long = 1 << 4

private static let nmsConditional = 1 << 6
private static let autoExecution = 1 << 5
private static let saturated = 1 << 4

// OTC_PRICE_TYPE values are taken from OtcMarketsPriceType enum.
private static let OTC_PRICE_TYPE_MASK: Long = 3
private static let OTC_PRICE_TYPE_SHIFT: Long = 2
private static let otcPriceTypeMask = 3
private static let otcPriceTypeShift = 2

private static let UNSOLICITED: Long = 1 << 1
private static let OPEN: Long = 1
// swiftlint:enable identifier_name
private static let unsolicited = 1 << 1
private static let open = 1

/// Returns Quote Access Payment (QAP) of this OTC Markets order.
/// QAP functionality allows participants to dynamically set access fees or rebates,
/// in real-time and on a per-security basis through OTC Dealer or OTC FIX connections.
/// Positive integers (1 to 30) indicate a rebate, and negative integers (-1 to -30) indicate an access fee.
/// 0 indicates no rebate or access fee.
private var quoteAccessPayment: Long = 0
var otcMarketsFlags: Long = 0
internal var quoteAccessPayment: Int32 = 0
internal var otcMarketsFlags: Int32 = 0

/// Creates new OTC Markets order event with default values.
public convenience init(_ eventSymbol: String) {
Expand All @@ -51,65 +50,65 @@ public class OtcMarketsOrder: Order {
/// All quotes will be closed at the start of the trading day and will remain closed until the traders open theirs.
public var isOpen: Bool {
get {
(otcMarketsFlags & OtcMarketsOrder.OPEN) != 0
(otcMarketsFlags & Int32(OtcMarketsOrder.open)) != 0
}
set {
otcMarketsFlags = newValue ?
otcMarketsFlags | OtcMarketsOrder.OPEN :
otcMarketsFlags & ~OtcMarketsOrder.OPEN
otcMarketsFlags | Int32(OtcMarketsOrder.open) :
otcMarketsFlags & ~Int32(OtcMarketsOrder.open)
}
}

/// Gets or sets a value indicating whether this event is unsolicited.
public var isUnsolicited: Bool {
get {
(otcMarketsFlags & OtcMarketsOrder.UNSOLICITED) != 0
(otcMarketsFlags & Int32(OtcMarketsOrder.unsolicited)) != 0
}
set {
otcMarketsFlags = newValue ? otcMarketsFlags |
OtcMarketsOrder.UNSOLICITED :
otcMarketsFlags & ~OtcMarketsOrder.UNSOLICITED
Int32(OtcMarketsOrder.unsolicited) :
otcMarketsFlags & ~Int32(OtcMarketsOrder.unsolicited)
}
}

/// Gets or sets OTC Markets price type of this OTC Markets order events.
public var otcMarketsPriceType: OtcMarketsPriceType {
get {
return OtcMarketsPriceType.valueOf(
Int(BitUtil.getBits(flags: otcMarketsFlags,
mask: OtcMarketsOrder.OTC_PRICE_TYPE_MASK,
shift: OtcMarketsOrder.OTC_PRICE_TYPE_SHIFT)))
Int(BitUtil.getBits(flags: Int(otcMarketsFlags),
mask: OtcMarketsOrder.otcPriceTypeMask,
shift: OtcMarketsOrder.otcPriceTypeShift)))
}
set {
otcMarketsFlags = BitUtil.setBits(flags: otcMarketsFlags,
mask: OtcMarketsOrder.OTC_PRICE_TYPE_MASK,
shift: OtcMarketsOrder.OTC_PRICE_TYPE_SHIFT,
bits: Long(newValue.rawValue.code))
otcMarketsFlags = Int32(BitUtil.setBits(flags: Int(otcMarketsFlags),
mask: OtcMarketsOrder.otcPriceTypeMask,
shift: OtcMarketsOrder.otcPriceTypeShift,
bits: newValue.rawValue.code))
}
}

/// Gets or sets a value indicating whether this event should NOT be considered for the inside price.
public var isSaturated: Bool {
get {
(otcMarketsFlags & OtcMarketsOrder.SATURATED) != 0
(otcMarketsFlags & Int32(OtcMarketsOrder.saturated)) != 0
}
set {
otcMarketsFlags = newValue ?
otcMarketsFlags | OtcMarketsOrder.SATURATED :
otcMarketsFlags & ~OtcMarketsOrder.SATURATED
otcMarketsFlags | Int32(OtcMarketsOrder.saturated) :
otcMarketsFlags & ~Int32(OtcMarketsOrder.saturated)
}
}

/// Gets or sets a value indicating whether this event is in 'AutoEx' mode.
/// If this event is in 'AutoEx' mode then a response to an OTC Link trade message will be immediate.
public var isAutoExecution: Bool {
get {
(otcMarketsFlags & OtcMarketsOrder.AUTO_EXECUTION) != 0
(otcMarketsFlags & Int32(OtcMarketsOrder.autoExecution)) != 0
}
set {
otcMarketsFlags = newValue ?
otcMarketsFlags | OtcMarketsOrder.AUTO_EXECUTION :
otcMarketsFlags & ~OtcMarketsOrder.AUTO_EXECUTION
otcMarketsFlags | Int32(OtcMarketsOrder.autoExecution) :
otcMarketsFlags & ~Int32(OtcMarketsOrder.autoExecution)
}
}

Expand All @@ -119,12 +118,12 @@ public class OtcMarketsOrder: Order {
/// and a trade message relating to the event cannot be sent or filled for less than the displayed size.
public var isNmsConditional: Bool {
get {
(otcMarketsFlags & OtcMarketsOrder.NMS_CONDITIONAL) != 0
(otcMarketsFlags & Int32(OtcMarketsOrder.nmsConditional)) != 0
}
set {
otcMarketsFlags = newValue ?
otcMarketsFlags | OtcMarketsOrder.NMS_CONDITIONAL :
otcMarketsFlags & ~OtcMarketsOrder.NMS_CONDITIONAL
otcMarketsFlags | Int32(OtcMarketsOrder.nmsConditional) :
otcMarketsFlags & ~Int32(OtcMarketsOrder.nmsConditional)
}
}

Expand Down
40 changes: 21 additions & 19 deletions DXFeedFramework/Native/Events/Markets/OtcMarketsOrder+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ import Foundation
@_implementationOnly import graal_api

extension OtcMarketsOrder {
convenience init(otcNative: dxfg_order_t) {
self.init(String(pointee: otcNative.order_base.market_event.event_symbol))
convenience init(otcNative: dxfg_otc_markets_order_t) {
self.init(String(pointee: otcNative.order_base.order_base.market_event.event_symbol))

self.eventTime = otcNative.order_base.market_event.event_time
self.eventFlags = otcNative.order_base.event_flags
try? self.setIndex(otcNative.order_base.index)
self.timeSequence = otcNative.order_base.time_sequence
self.timeNanoPart = otcNative.order_base.time_nano_part
self.actionTime = otcNative.order_base.action_time
self.orderId = otcNative.order_base.order_id
self.auxOrderId = otcNative.order_base.aux_order_id
self.price = otcNative.order_base.price
self.size = otcNative.order_base.size
self.executedSize = otcNative.order_base.executed_size
self.count = otcNative.order_base.count
self.flags = otcNative.order_base.flags
self.tradeId = otcNative.order_base.trade_id
self.tradePrice = otcNative.order_base.trade_price
self.tradeSize = otcNative.order_base.trade_size
self.eventTime = otcNative.order_base.order_base.market_event.event_time
self.eventFlags = otcNative.order_base.order_base.event_flags
try? self.setIndex(otcNative.order_base.order_base.index)
self.timeSequence = otcNative.order_base.order_base.time_sequence
self.timeNanoPart = otcNative.order_base.order_base.time_nano_part
self.actionTime = otcNative.order_base.order_base.action_time
self.orderId = otcNative.order_base.order_base.order_id
self.auxOrderId = otcNative.order_base.order_base.aux_order_id
self.price = otcNative.order_base.order_base.price
self.size = otcNative.order_base.order_base.size
self.executedSize = otcNative.order_base.order_base.executed_size
self.count = otcNative.order_base.order_base.count
self.flags = otcNative.order_base.order_base.flags
self.tradeId = otcNative.order_base.order_base.trade_id
self.tradePrice = otcNative.order_base.order_base.trade_price
self.tradeSize = otcNative.order_base.order_base.trade_size

self.marketMaker = String(nullable: otcNative.market_maker)
self.marketMaker = String(nullable: otcNative.order_base.market_maker)
self.quoteAccessPayment = otcNative.quote_access_payment
self.otcMarketsFlags = otcNative.otc_markets_flags
}
}
54 changes: 28 additions & 26 deletions DXFeedFramework/Native/Events/Markets/OtcMarketsOrderMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,45 @@ import Foundation
@_implementationOnly import graal_api

class OtcMarketsOrderMapper: Mapper {
let type = dxfg_order_t.self
let type = dxfg_otc_markets_order_t.self

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

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

let order = event.order

pointer.pointee.order_base.market_event.event_time = order.eventTime
pointer.pointee.order_base.event_flags = order.eventFlags
pointer.pointee.order_base.index = order.index
pointer.pointee.order_base.time_sequence = order.timeSequence
pointer.pointee.order_base.time_nano_part = order.timeNanoPart
pointer.pointee.order_base.action_time = order.actionTime
pointer.pointee.order_base.order_id = order.orderId
pointer.pointee.order_base.aux_order_id = order.auxOrderId
pointer.pointee.order_base.price = order.price
pointer.pointee.order_base.size = order.size
pointer.pointee.order_base.executed_size = order.executedSize
pointer.pointee.order_base.count = order.count
pointer.pointee.order_base.flags = order.flags
pointer.pointee.order_base.trade_id = order.tradeId
pointer.pointee.order_base.trade_price = order.tradePrice
pointer.pointee.order_base.trade_size = order.tradeSize

pointer.pointee.market_maker = order.marketMaker?.toCStringRef()
pointer.pointee.order_base.order_base.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointer.pointee.order_base.order_base.market_event.event_time = event.eventTime

let order = event.otcMarketsOrder

pointer.pointee.order_base.order_base.market_event.event_time = order.eventTime
pointer.pointee.order_base.order_base.event_flags = order.eventFlags
pointer.pointee.order_base.order_base.index = order.index
pointer.pointee.order_base.order_base.time_sequence = order.timeSequence
pointer.pointee.order_base.order_base.time_nano_part = order.timeNanoPart
pointer.pointee.order_base.order_base.action_time = order.actionTime
pointer.pointee.order_base.order_base.order_id = order.orderId
pointer.pointee.order_base.order_base.aux_order_id = order.auxOrderId
pointer.pointee.order_base.order_base.price = order.price
pointer.pointee.order_base.order_base.size = order.size
pointer.pointee.order_base.order_base.executed_size = order.executedSize
pointer.pointee.order_base.order_base.count = order.count
pointer.pointee.order_base.order_base.flags = order.flags
pointer.pointee.order_base.order_base.trade_id = order.tradeId
pointer.pointee.order_base.order_base.trade_price = order.tradePrice
pointer.pointee.order_base.order_base.trade_size = order.tradeSize

pointer.pointee.order_base.market_maker = order.marketMaker?.toCStringRef()
pointer.pointee.quote_access_payment = order.quoteAccessPayment
pointer.pointee.otc_markets_flags = order.otcMarketsFlags

let eventType = pointer.withMemoryRebound(to: dxfg_event_type_t.self, capacity: 1) { pointer in
pointer.pointee.clazz = DXFG_EVENT_ORDER
pointer.pointee.clazz = DXFG_EVENT_OTC_MARKETS_ORDER
return pointer
}
return eventType
Expand Down
6 changes: 4 additions & 2 deletions DXFeedFramework/Native/Feed/EventCode+Native.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extension EventCode {
return .order
case DXFG_EVENT_ANALYTIC_ORDER:
return .analyticOrder
case DXFG_EVENT_OTC_MARKETS_ORDER:
return .otcMarketsOrder
case DXFG_EVENT_SPREAD_ORDER:
return .spreadOrder
case DXFG_EVENT_SERIES:
Expand Down Expand Up @@ -86,14 +88,14 @@ extension EventCode {
return DXFG_EVENT_ORDER
case .analyticOrder:
return DXFG_EVENT_ANALYTIC_ORDER
case .otcMarketsOrder:
return DXFG_EVENT_OTC_MARKETS_ORDER
case .spreadOrder:
return DXFG_EVENT_SPREAD_ORDER
case .series:
return DXFG_EVENT_SERIES
case .optionSale:
return DXFG_EVENT_OPTION_SALE
case .otcMarketsOrder:
return DXFG_EVENT_ORDER
}
}
}

0 comments on commit edea479

Please sign in to comment.