Skip to content

Commit

Permalink
AnalyticOrder ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 11, 2023
1 parent 1439d00 commit 106c378
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 9 deletions.
4 changes: 4 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
64BDDB202AD6CC8300694210 /* AnalyticOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB1F2AD6CC8300694210 /* AnalyticOrder.swift */; };
64BDDB222AD6CC9A00694210 /* SpreadOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB212AD6CC9A00694210 /* SpreadOrder.swift */; };
64BDDB242AD6F10200694210 /* Scope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB232AD6F10200694210 /* Scope.swift */; };
64BDDB262AD6F6B500694210 /* IcebergType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BDDB252AD6F6B500694210 /* IcebergType.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 Down Expand Up @@ -723,6 +724,7 @@
64BDDB1F2AD6CC8300694210 /* AnalyticOrder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticOrder.swift; sourceTree = "<group>"; };
64BDDB212AD6CC9A00694210 /* SpreadOrder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpreadOrder.swift; sourceTree = "<group>"; };
64BDDB232AD6F10200694210 /* Scope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scope.swift; sourceTree = "<group>"; };
64BDDB252AD6F6B500694210 /* IcebergType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IcebergType.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 Down Expand Up @@ -1133,6 +1135,7 @@
6486B97A2AD0517A00D8D5FA /* OrderAction.swift */,
6486B97C2AD057F200D8D5FA /* OrderSource.swift */,
64BDDB232AD6F10200694210 /* Scope.swift */,
64BDDB252AD6F6B500694210 /* IcebergType.swift */,
);
path = Extra;
sourceTree = "<group>";
Expand Down Expand Up @@ -2120,6 +2123,7 @@
6469F8C82A3B25C900846831 /* MarketEvent+Access.swift in Sources */,
640C3FD22A6178D200555161 /* CandleSession.swift in Sources */,
6498E6BD2AB1E0510093A065 /* ScheduleSession.swift in Sources */,
64BDDB262AD6F6B500694210 /* IcebergType.swift in Sources */,
8088D76529C0FBCE00F240CB /* ThreadManager.swift in Sources */,
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift in Sources */,
64656F732A1D0A84006A0B19 /* EndpointListener.swift in Sources */,
Expand Down
33 changes: 33 additions & 0 deletions DXFeedFramework/Events/Market/Extra/IcebergType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// IcebergType.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 11.10.23.
//

import Foundation

/// Type of an iceberg order.
public enum IcebergType: Int, CaseIterable {
/// Iceberg type is undefined, unknown or inapplicable.
case undefined = 0
/// Represents native (exchange-managed) iceberg type.
case native
/// Represents synthetic (managed outside of the exchange) iceberg type.
case synthetic
}

/// Class extension for ``IcebergType`` enum.
public class IcebergTypeExt {
private static let values: [IcebergType] =
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .undefined, allCases: IcebergType.allCases)


/// Returns an enum constant of the``IcebergType`` by integer code bit pattern.
/// - Parameters:
/// - value: Property value
/// - Returns: The enum constant of the specified enum type with the specified value
public static func valueOf(value: Int) -> IcebergType {
return values[value]
}
}
12 changes: 5 additions & 7 deletions DXFeedFramework/Events/Market/Extra/OrderBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ tradePrice: \(tradePrice), \
tradeSize: \(tradeSize)
"""
}

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

extension OrderBase {
/// Gets a value indicating whether this order has some size
func hsaSize() -> Bool {
public func hsaSize() -> Bool {
return size != 0 && !size.isNaN
}
/// Gets exchange code of this order.
Expand Down Expand Up @@ -273,11 +276,6 @@ extension OrderBase {
}
}

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

/// Returns string representation of this candle fields.
func baseFieldsToString() -> String {
return
Expand Down
6 changes: 6 additions & 0 deletions DXFeedFramework/Events/Market/Extra/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ public enum Scope: Int, CaseIterable {
case order
}


/// Class extension for ``ScopeExt`` enum.
public class ScopeExt {
private static let values: [Scope] =
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .composite, allCases: Scope.allCases)

/// Returns an enum constant of the``ScopeExt`` by integer code bit pattern.
/// - Parameters:
/// - value: Property value
/// - Returns: The enum constant of the specified enum type with the specified value
public static func valueOf(value: Int) -> Scope {
return values[value]
}
Expand Down
64 changes: 62 additions & 2 deletions DXFeedFramework/Native/Events/Markets/AnalyticOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,67 @@
//

import Foundation

/// Represents an extension of ``Order`` introducing analytics information,
/// e.g. adding to this order iceberg related information ``icebergPeakSize``, ``IcebergHiddenSize``, ``IcebergExecutedSize``
///
/// The collection of analytic order events of a symbol represents the most recent analytic information
/// that is available about orders on the market at any given moment of time.
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/AnalyticOrder.html)
public class AnalyticOrder: OrderBase {

/*
* Analytic flags property has several significant bits that are packed into an integer in the following way:
* 31...2 1 0
* +--------------+-------+-------+
* | | IcebergType |
* +--------------+-------+-------+
*/

// TYPE values are taken from Type enum.
private let icebergTypeMask = 3
private let icebergTypeShift = 0

/// Gets or sets iceberg peak size of this analytic order.
public var icebergPeakSize: Double = .nan
/// Gets or sets iceberg hidden size of this analytic order.
public var icebergHiddenSize: Double = .nan
/// Gets or sets iceberg executed size of this analytic 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)
}

/// Returns string representation of this candle event.
override func toString() -> String {
return
"""
AnalyticOrder{\(baseFieldsToString()), \
icebergPeakSize=\(icebergPeakSize), \
icebergHiddenSize=\(icebergHiddenSize) +
icebergExecutedSize=\(icebergExecutedSize) +
icebergType=\(icebergType)}
"""
}
}

extension AnalyticOrder {
/// Gets or sets iceberg type of this analytic order.
public var icebergType: IcebergType {
get {
IcebergTypeExt.valueOf(value: BitUtil.getBits(flags: Int(icebergFlags),
mask: icebergTypeMask,
shift: icebergTypeShift))
}
set {
icebergFlags = Int32(BitUtil.setBits(flags: Int(icebergFlags),
mask: icebergTypeMask,
shift: icebergTypeShift,
bits: newValue.rawValue))
}
}
}


0 comments on commit 106c378

Please sign in to comment.