Skip to content

Commit

Permalink
Merge branch 'feature/hash_code' into swift
Browse files Browse the repository at this point in the history
* feature/hash_code:
  add hash code
  • Loading branch information
kosyloa committed Dec 13, 2023
2 parents da791d2 + 941888e commit e37d5f7
Show file tree
Hide file tree
Showing 29 changed files with 259 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "PerfTest localhost:6666 TimeAndSale YQKNT"
isEnabled = "NO">
argument = "PerfTest localhost:7777 TimeAndSale YQKNT"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = " qds post :6666"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Dump"
Expand Down
9 changes: 3 additions & 6 deletions DXFeedFramework/Events/Market/AnalyticOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import Foundation
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/AnalyticOrder.html)
public class AnalyticOrder: Order {
public override var type: EventCode {
return .analyticOrder
}
/*
* Analytic flags property has several significant bits that are packed into an integer in the following way:
* 31...2 1 0
Expand All @@ -36,9 +33,9 @@ public class AnalyticOrder: Order {
public var icebergExecutedSize: Double = .nan
/// Gets or sets iceberg type of this analytic order.
public var icebergFlags: Int32 = 0
/// Initializes a new instance of the <see cref="AnalyticOrder"/> class.
public override init(_ eventSymbol: String) {
super.init(eventSymbol)
/// Initializes a new instance of the ``AnalyticOrder`` class.
public init(_ eventSymbol: String) {
super.init(eventSymbol: eventSymbol, type: .analyticOrder)
}

/// Returns string representation of this candle event.
Expand Down
17 changes: 7 additions & 10 deletions DXFeedFramework/Events/Market/Candles/Candle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ 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 let type: EventCode = .candle

/// Gets or sets candle symbol object.
public var eventSymbol: String {
public override var eventSymbol: String {
get {
candleSymbol?.toString() ?? ""
}
set {
candleSymbol = try? CandleSymbol.valueOf(newValue)
}
}
public var eventTime: Int64 = 0

/*
* EventFlags property has several significant bits that are packed into an integer in the following way:
Expand Down Expand Up @@ -65,7 +62,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()
self.init(type: .candle)
self.candleSymbol = symbol
}

Expand All @@ -91,6 +88,11 @@ impVolatility: \(impVolatility), \
openInterest: \(openInterest)
"""
}

/// Returns string representation of this candle event.
public override func toString() -> String {
return "Candle{\(baseFieldsToString())}"
}
}

extension Candle {
Expand Down Expand Up @@ -126,11 +128,6 @@ extension Candle {
}
}

/// Returns string representation of this candle event.
public func toString() -> String {
return "Candle{\(baseFieldsToString())}"
}

/// Returns string representation of this candle fields.
func baseFieldsToString() -> String {
return """
Expand Down
2 changes: 2 additions & 0 deletions DXFeedFramework/Events/Market/Candles/CandleAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ public enum CandleAlignment: DXCandleAlignment, CaseIterable {
}
return try parse(attribute)
}

/// Returns string representation of this candle alignment.
/// The string representation of candle alignment "m" for ``midnight``
/// and "s" for ``session``.
public func toString() -> String {
return self.rawValue.string
}

/// Returns full string representation of this candle alignment.
///
/// It is contains attribute key and its value.
Expand Down
1 change: 1 addition & 0 deletions DXFeedFramework/Events/Market/Candles/CandleExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CandleExchange {
public static func getAttribute(_ symbol: String?) -> CandleExchange {
return valueOf(MarketEventSymbols.getExchangeCode(symbol))
}

/// Returns string representation of this exchange.
/// It is the string "COMPOSITE" for ``Composite`` exchange or
/// exchange character otherwise.
Expand Down
1 change: 1 addition & 0 deletions DXFeedFramework/Events/Market/Candles/CandlePeriod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class CandlePeriod {
self.type = type
self.periodIntervalMillis = type.rawValue.periodIntervalMillis * Long(value)
}

/// Returns string representation of this candle period.
///
/// - Returns: The string representation.
Expand Down
1 change: 1 addition & 0 deletions DXFeedFramework/Events/Market/Candles/CandlePrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public enum CandlePrice: DXCandlePrice, CaseIterable {
}
return sValue
}

/// Returns string representation of this candle price.
///
/// - Returns: The string representation.
Expand Down
1 change: 1 addition & 0 deletions DXFeedFramework/Events/Market/Candles/CandleSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public enum CandleSession: DXCandleSession, CaseIterable {
}
return sValue
}

/// Returns string representation of this candle session.
///
/// - Returns: The string representation.
Expand Down
1 change: 1 addition & 0 deletions DXFeedFramework/Events/Market/Candles/CandleType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public enum CandleType: DXCandleType, CaseIterable {
}
return sValue
}

/// Returns string representation of this candle type.
///
/// The string representation of candle type is the shortest unique prefix of the
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 @@ -25,4 +25,7 @@ public protocol IEventType {
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/EventType.html#getEventTime--)
var eventTime: Int64 { get set }

/// Hashcode fot perftest and other purposes.
var hashCode: Int { get }
}
21 changes: 18 additions & 3 deletions DXFeedFramework/Events/Market/Extra/MarketEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ import Foundation
/// extend this class. Market event classes are simple beans with setter and getter methods for their
/// properties and minimal business logic. All market events have ``type``
/// property that is defined by this class.
public protocol MarketEvent: IEventType {
var type: EventCode { get }
func toString() -> String
public class MarketEvent: IEventType {
public var eventSymbol: String = ""

public var eventTime: Int64 = 0

public lazy var hashCode: Int = {
return Int(bitPattern: Unmanaged.passUnretained(self).toOpaque())
}()

public var type: EventCode

public func toString() -> String {
return "Override toString() method"
}

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

public struct MarketEventConst {
Expand Down
16 changes: 6 additions & 10 deletions DXFeedFramework/Events/Market/Extra/OrderBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import Foundation

public class OrderBase: MarketEvent, IIndexedEvent, CustomStringConvertible {

public private(set) var type: EventCode = .orderBase

public var eventSource: IndexedEventSource {
get {
var sourceId = index >> 48
Expand All @@ -32,9 +29,6 @@ public class OrderBase: MarketEvent, IIndexedEvent, CustomStringConvertible {

public private(set) var index: Long = 0

public var eventSymbol: String

public var eventTime: Int64 = 0
/*
* Flags property has several significant bits that are packed into an integer in the following way:
* 31..15 14..11 10..4 3 2 1 0
Expand Down Expand Up @@ -123,7 +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) {
init(eventSymbol: String, type: EventCode) {
super.init(type: type)
self.eventSymbol = eventSymbol
}

Expand All @@ -148,9 +143,10 @@ tradeId: \(tradeId), \
tradePrice: \(tradePrice), \
tradeSize: \(tradeSize)
"""
}
}

/// Returns string representation of this candle event.
public func toString() -> String {
public override func toString() -> String {
return "OrderBase{\(baseFieldsToString())}"
}
}
Expand All @@ -164,7 +160,7 @@ extension OrderBase {
}
self.index = value
}

/// Gets a value indicating whether this order has some size
public func hsaSize() -> Bool {
return size != 0 && !size.isNaN
Expand Down
12 changes: 3 additions & 9 deletions DXFeedFramework/Events/Market/Extra/TradeBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import Foundation
///
/// [For more details see] (https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/TradeBase.html)
public class TradeBase: MarketEvent, ILastingEvent {
public var type: EventCode {
return .trade
}

public var eventSymbol: String
public var eventTime: Int64 = 0

/*
* 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 @@ -55,7 +48,8 @@ public class TradeBase: MarketEvent, ILastingEvent {
/// Do not use this method directly.
var flags: Int32 = 0

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

Expand All @@ -78,7 +72,7 @@ flags: \(flags)
}

/// Returns string representation of this base trade event's.
public func toString() -> String {
public override func toString() -> String {
return "\(typeName){\(baseFieldsToString())}"
}

Expand Down
43 changes: 20 additions & 23 deletions DXFeedFramework/Events/Market/Greeks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ 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 var type: EventCode = .greeks

public var eventSymbol: String

public var eventTime: Int64 = 0

public var eventSource: IndexedEventSource = .defaultSource

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

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

Expand All @@ -79,6 +74,24 @@ gamma: \(gamma), \
theta: \(theta), \
rho: \(rho), \
vega: \(vega)
"""
}

/// Returns string representation of this greeks fields.
public override func toString() -> String {
return """
Greeks{\(eventSymbol), \
eventTime=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: eventTime)) ?? ""), \
eventFlags=\(eventFlags.toHexString()), \
time=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: time)) ?? ""), \
sequence=\(self.getSequence()), \
price=\(price), \
volatility=\(volatility), \
delta=\(delta), \
gamma=\(gamma), \
theta=\(theta), \
rho=\(rho), \
vega=\(vega)}
"""
}
}
Expand Down Expand Up @@ -114,21 +127,5 @@ extension Greeks {
}
index = Long(index & ~Long(MarketEventConst.maxSequence)) | Long(sequence)
}
/// Returns string representation of this greeks fields.
public func toString() -> String {
return """
Greeks{\(eventSymbol), \
eventTime=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: eventTime)) ?? ""), \
eventFlags=\(eventFlags.toHexString()), \
time=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: time)) ?? ""), \
sequence=\(self.getSequence()), \
price=\(price), \
volatility=\(volatility), \
delta=\(delta), \
gamma=\(gamma), \
theta=\(theta), \
rho=\(rho), \
vega=\(vega)}
"""
}

}
Loading

0 comments on commit e37d5f7

Please sign in to comment.