diff --git a/.swiftlint.yml b/.swiftlint.yml index ddaf324b4..e0cdcb744 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -3,4 +3,5 @@ cyclomatic_complexity: file_length: warning: 800 error: 1500 - +line_length: + ignores_comments: true diff --git a/DXFeedFramework.xcodeproj/project.pbxproj b/DXFeedFramework.xcodeproj/project.pbxproj index 7e1068e4c..b29cc631e 100644 --- a/DXFeedFramework.xcodeproj/project.pbxproj +++ b/DXFeedFramework.xcodeproj/project.pbxproj @@ -160,6 +160,7 @@ 646D19E22A3C994000C82315 /* DXFTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646D19E02A3C970700C82315 /* DXFTimer.swift */; }; 646D19E32A3C994100C82315 /* DXFTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646D19E02A3C970700C82315 /* DXFTimer.swift */; }; 6479BC2B2A4F35A300A3D404 /* QuoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6479BC2A2A4F35A300A3D404 /* QuoteView.swift */; }; + 648E98AA2AAF625800BFD219 /* IIndexedEvent+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */; }; 64963B6A2A8E545C001E40F7 /* IEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64963B692A8E545C001E40F7 /* IEventType.swift */; }; 649F48862A615BC90016FDD1 /* CandleSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649F48852A615BC90016FDD1 /* CandleSymbol.swift */; }; 649F48882A615BED0016FDD1 /* CandleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649F48872A615BED0016FDD1 /* CandleType.swift */; }; @@ -502,6 +503,7 @@ 6469F8D22A3B401700846831 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; 646D19E02A3C970700C82315 /* DXFTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXFTimer.swift; sourceTree = ""; }; 6479BC2A2A4F35A300A3D404 /* QuoteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteView.swift; sourceTree = ""; }; + 648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IIndexedEvent+Ext.swift"; sourceTree = ""; }; 64963B692A8E545C001E40F7 /* IEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IEventType.swift; sourceTree = ""; }; 649F48852A615BC90016FDD1 /* CandleSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleSymbol.swift; sourceTree = ""; }; 649F48872A615BED0016FDD1 /* CandleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleType.swift; sourceTree = ""; }; @@ -862,6 +864,7 @@ isa = PBXGroup; children = ( 6469F8C72A3B25C900846831 /* MarketEvent+Access.swift */, + 648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */, ); path = Extensions; sourceTree = ""; @@ -1706,6 +1709,7 @@ 64656F6D2A1CFB10006A0B19 /* DXEndpointState.swift in Sources */, 6464074D2A9E352E006FF769 /* InstrumentProfileField.swift in Sources */, 64E342522AAB29CF00457994 /* InstrumentProfileType.swift in Sources */, + 648E98AA2AAF625800BFD219 /* IIndexedEvent+Ext.swift in Sources */, 6447A5E32A8F611700739CCF /* IObservableSubscription.swift in Sources */, 64104FC92A26298D00D1FC41 /* DXFeedSubcription.swift in Sources */, 64104FD32A277B2D00D1FC41 /* ListNative.swift in Sources */, diff --git a/DXFeedFramework/Events/Market/Candles/Candle.swift b/DXFeedFramework/Events/Market/Candles/Candle.swift index 3dc081a14..5073d834e 100644 --- a/DXFeedFramework/Events/Market/Candles/Candle.swift +++ b/DXFeedFramework/Events/Market/Candles/Candle.swift @@ -6,10 +6,15 @@ // import Foundation - +/// Candle event with open, high, low, close prices and other information for a specific period. +/// +/// Candles are build with a specified ``CandlePeriod`` using a specified ``CandlePrice`` type +/// 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 { get { candleSymbol?.toString() ?? "" @@ -18,26 +23,49 @@ public class Candle: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringC candleSymbol = try? CandleSymbol.valueOf(newValue) } } + + /* + * EventFlags property has several significant bits that are packed into an integer in the following way: + * 31..7 6 5 4 3 2 1 0 + * +---------+----+----+----+----+----+----+----+ + * | | SM | | SS | SE | SB | RE | TX | + * +---------+----+----+----+----+----+----+----+ + */ + public var eventTime: Int64 = 0 + /// Gets or sets candle symbol object. public var candleSymbol: CandleSymbol? - + /// Gets or sets total number of original trade (or quote) events in this candle. public var count: Long = 0 + /// Gets or sets the first (open) price of this candle. public var open: Double = .nan + /// Gets or sets the maximal (high) price of this candle. public var high: Double = .nan + /// Gets or sets the minimal (low) price of this candle. public var low: Double = .nan + /// Gets or sets the last (close) price of this candle. public var close: Double = .nan + /// Gets or sets total volume in this candle as floating number with fractions. + /// Total turnover in this candle can be computed with ``vwap`` * ``volume``. public var volume: Double = .nan + /// Gets or sets volume-weighted average price (VWAP) in this candle. + /// Total turnover in this candle can be computed with ``vwap`` * ``volume``. public var vwap: Double = .nan + /// Gets or sets bid volume in this candle as floating number with fractions. public var bidVolume: Double = .nan + /// Gets or sets ask volume in this candle as floating number with fractions. public var askVolume: Double = .nan + /// Gets or sets implied volatility. public var impVolatility: Double = .nan + /// Gets or sets open interest as floating number with fractions. public var openInterest: Double = .nan public var eventSource = IndexedEventSource.defaultSource public var eventFlags: Int32 = 0 public var index: Long = 0 - convenience init(_ symbol: CandleSymbol) { + /// Initializes a new instance of the ``Candle`` class with the specified event symbol. + public convenience init(_ symbol: CandleSymbol) { self.init() self.candleSymbol = symbol } @@ -80,7 +108,8 @@ extension Candle { } index = (index & ~Int64(MarketEventConst.maxSequence)) | Int64(sequence) } - + /// Gets or sets timestamp of the original event. + /// Time is measured in milliseconds between the current time and midnight, January 1, 1970 UTC. public var time: Int64 { get { Int64(((self.index >> 32) * 1000) + ((self.index >> 22) & 0x3ff)) @@ -91,10 +120,12 @@ extension Candle { } } + /// Returns string representation of this candle event. func toString() -> String { return "Candle{\(baseFieldsToString())}" } + /// Returns string representation of this candle fields. func baseFieldsToString() -> String { return """ \(eventSymbol), \ diff --git a/DXFeedFramework/Events/Market/Candles/CandleAlignment.swift b/DXFeedFramework/Events/Market/Candles/CandleAlignment.swift index a2e08e398..3d3154ced 100644 --- a/DXFeedFramework/Events/Market/Candles/CandleAlignment.swift +++ b/DXFeedFramework/Events/Market/Candles/CandleAlignment.swift @@ -7,8 +7,15 @@ import Foundation +/// This `DXCandleAlignment` structure is created to circumvent the limitation that enums in Swift cannot contain stored properties. +/// The "Enums must not contain stored properties" error occurs when attempting to add a stored property to an enum. Instead, we use this structure to store data that we would like to include in the enum. public struct DXCandleAlignment: Equatable { + /// Gets full name this ``CandleAlignment`` instance. + /// For example, + /// ``CandleAlignment/midnight`` returns "Midnight" + /// ``CandleAlignment/session`` returns "Session" public let name: String + /// Get string value of alignment public let string: String } @@ -28,14 +35,19 @@ extension DXCandleAlignment: ExpressibleByStringLiteral { } } +/// Candle alignment attribute of ``CandleSymbol`` defines how candle are aligned with respect to time. +/// +/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/candle/CandleAlignment.html) public enum CandleAlignment: DXCandleAlignment, CaseIterable { case midnight = "Midnight" case session = "Session" static let attributeKey = "a" - static let defaultAlignment = midnight + public static let defaultAlignment = midnight + /// A dictionary containing the matching string representation + /// of the candle alignment attribute ``DXCandleAlignment/string`` and the ``CandleAlignment`` instance. static let byString = { let myDict = Self.allCases.reduce(into: [String: CandleAlignment]()) { $0[$1.toString()] = $1 @@ -43,7 +55,12 @@ public enum CandleAlignment: DXCandleAlignment, CaseIterable { return myDict }() - static func normalizeAttributeForSymbol(_ symbol: String?) -> String? { + /// Normalizes candle symbol string with representation of the candle alignment attribute. + /// + /// - Parameters: + /// - symbol: The candle symbol string. + /// - Returns: Returns candle symbol string with the normalized representation of the candle alignment attribute. + public static func normalizeAttributeForSymbol(_ symbol: String?) -> String? { let attribute = try? MarketEventSymbols.getAttributeStringByKey(symbol, attributeKey) guard let attribute = attribute else { return symbol @@ -64,7 +81,15 @@ public enum CandleAlignment: DXCandleAlignment, CaseIterable { return symbol } - static func parse(_ symbol: String) throws -> CandleAlignment { + /// Parses string representation of candle alignment into object. + /// Any string that was returned by ``toString()`` can be parsed + /// and case is ignored for parsing. + /// + /// - Parameters: + /// - symbol: The string representation of candle alignment + /// - Returns: The candle alignment. + /// - Throws: ``ArgumentException/unknowCandleAlignment`` + public static func parse(_ symbol: String) throws -> CandleAlignment { // Fast path to reverse toString result. if let fvalue = byString[symbol] { return fvalue @@ -78,26 +103,41 @@ public enum CandleAlignment: DXCandleAlignment, CaseIterable { } return sValue } - - static func getAttribute(_ symbol: String?) throws -> CandleAlignment { + /// Gets candle alignment of the given candle symbol string. + /// + /// The result is ``defaultAlignment`` if the symbol does not have candle alignment attribute. + /// + /// - Parameters: + /// - symbol: The candle symbol string. + /// - Returns: The candle alignment of the given candle symbol string. + /// - Throws: ``ArgumentException/argumentNil`` + public static func getAttribute(_ symbol: String?) throws -> CandleAlignment { let attribute = try MarketEventSymbols.getAttributeStringByKey(symbol, attributeKey) guard let attribute = attribute else { return defaultAlignment } return try parse(attribute) } - - func toString() -> String { + /// 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 } - - func toFullString() -> String { + /// Returns full string representation of this candle alignment. + /// + /// It is contains attribute key and its value. + /// For example, the full string representation of ``midnight`` is "a=m". + /// - Returns: The string representation + public func toFullString() -> String { return "\(CandleAlignment.attributeKey)=\(self.rawValue.string)" } } +/// Property of the ``CandleSymbol`` extension CandleAlignment: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + /// Returns candle event symbol string with this candle alignment set. + public func changeAttributeForSymbol(symbol: String?) -> String? { if self == CandleAlignment.defaultAlignment { return MarketEventSymbols.removeAttributeStringByKey(symbol, CandleAlignment.attributeKey) } else { @@ -113,7 +153,8 @@ extension CandleAlignment: ICandleSymbolProperty { return symbol } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + /// Internal method that initializes attribute in the candle symbol. + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.alignment != nil { throw ArgumentException.invalidOperationException("Already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandleExchange.swift b/DXFeedFramework/Events/Market/Candles/CandleExchange.swift index e5e05c2ed..9ad743229 100644 --- a/DXFeedFramework/Events/Market/Candles/CandleExchange.swift +++ b/DXFeedFramework/Events/Market/Candles/CandleExchange.swift @@ -37,11 +37,11 @@ public class CandleExchange { } extension CandleExchange: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + public func changeAttributeForSymbol(symbol: String?) -> String? { return MarketEventSymbols.changeExchangeCode(symbol, exchangeCode) } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.exchange != nil { throw ArgumentException.invalidOperationException("Already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandlePeriod.swift b/DXFeedFramework/Events/Market/Candles/CandlePeriod.swift index e9cf94714..06f11f5e1 100644 --- a/DXFeedFramework/Events/Market/Candles/CandlePeriod.swift +++ b/DXFeedFramework/Events/Market/Candles/CandlePeriod.swift @@ -106,7 +106,7 @@ extension CandlePeriod: Equatable { } extension CandlePeriod: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + public func changeAttributeForSymbol(symbol: String?) -> String? { if self === CandlePeriod.defaultPeriod { return MarketEventSymbols.removeAttributeStringByKey(symbol, CandlePeriod.attributeKey) } else { @@ -114,7 +114,7 @@ extension CandlePeriod: ICandleSymbolProperty { } } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.period != nil { throw ArgumentException.invalidOperationException("already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandlePrice.swift b/DXFeedFramework/Events/Market/Candles/CandlePrice.swift index 354905c39..fee6acf78 100644 --- a/DXFeedFramework/Events/Market/Candles/CandlePrice.swift +++ b/DXFeedFramework/Events/Market/Candles/CandlePrice.swift @@ -107,13 +107,13 @@ public enum CandlePrice: DXCandlePrice, CaseIterable { } extension CandlePrice: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + public func changeAttributeForSymbol(symbol: String?) -> String? { self == CandlePrice.defaultPrice ? MarketEventSymbols.removeAttributeStringByKey(symbol, CandlePrice.attributeKey) : try? MarketEventSymbols.changeAttributeStringByKey(symbol, CandlePrice.attributeKey, toString()) } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.price != nil { throw ArgumentException.invalidOperationException("Already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift b/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift index 1302820e4..0f9dae3e2 100644 --- a/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift +++ b/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift @@ -81,13 +81,13 @@ extension CandlePriceLevel: Equatable { } extension CandlePriceLevel: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + public func changeAttributeForSymbol(symbol: String?) -> String? { self == CandlePriceLevel.defaultCandlePriceLevel ? MarketEventSymbols.removeAttributeStringByKey(symbol, CandlePriceLevel.attributeKey) : try? MarketEventSymbols.changeAttributeStringByKey(symbol, CandlePriceLevel.attributeKey, toString()) } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.priceLevel != nil { throw ArgumentException.invalidOperationException("Already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandleSession.swift b/DXFeedFramework/Events/Market/Candles/CandleSession.swift index a8374c96e..843363453 100644 --- a/DXFeedFramework/Events/Market/Candles/CandleSession.swift +++ b/DXFeedFramework/Events/Market/Candles/CandleSession.swift @@ -86,7 +86,7 @@ public enum CandleSession: DXCandleSession, CaseIterable { } extension CandleSession: ICandleSymbolProperty { - func changeAttributeForSymbol(symbol: String?) -> String? { + public func changeAttributeForSymbol(symbol: String?) -> String? { if self == CandleSession.defaultSession { return MarketEventSymbols.removeAttributeStringByKey(symbol, CandleSession.attributeKey) } else { @@ -94,7 +94,7 @@ extension CandleSession: ICandleSymbolProperty { } } - func checkInAttribute(candleSymbol: CandleSymbol) throws { + public func checkInAttribute(candleSymbol: CandleSymbol) throws { if candleSymbol.session != nil { throw ArgumentException.invalidOperationException("Already initialized") } diff --git a/DXFeedFramework/Events/Market/Candles/CandleSymbol.swift b/DXFeedFramework/Events/Market/Candles/CandleSymbol.swift index 89e6258bb..b6c9958ae 100644 --- a/DXFeedFramework/Events/Market/Candles/CandleSymbol.swift +++ b/DXFeedFramework/Events/Market/Candles/CandleSymbol.swift @@ -7,14 +7,27 @@ import Foundation +/// Symbol that should be used with``DXFeedSubcription`` class +/// to subscribe for``Candle`` events.``DXFeedSubcription`` also accepts a string +/// representation of the candle symbol for subscription. +/// +/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/candle/CandleSymbol.html) public class CandleSymbol { + /// Returns string representation of this symbol. public private(set) var symbol: String? + /// Gets base market symbol without attributes. public private(set) var baseSymbol: String? + /// Gets exchange attribute of this symbol. public internal(set) var exchange: CandleExchange? + /// Gets price type attribute of this symbol. public internal(set) var price: CandlePrice? + /// Gets session attribute of this symbol. public internal(set) var session: CandleSession? + /// Gets aggregation period of this symbol. public internal(set) var period: CandlePeriod? + /// Gets alignment attribute of this symbol. public internal(set) var alignment: CandleAlignment? + /// Gets price level attribute of this symbol. public internal(set) var priceLevel: CandlePriceLevel? private init(_ symbol: String) throws { @@ -70,18 +83,21 @@ public class CandleSymbol { return symbol } - public convenience init(symbol: String) throws { - try self.init(symbol) - } - func toString() -> String { return symbol ?? "null" } - + /// Converts the given string symbol into the candle symbol object. + /// + /// - Throws: ArgumentException/invalidOperationException(_:) static func valueOf(_ symbol: String) throws -> CandleSymbol { - return try CandleSymbol(symbol: symbol) + return try CandleSymbol(symbol) } - + /// Converts the given string symbol into the candle symbol object with the specified attribute set. + /// + /// - Parameters: + /// - symbol:The string symbol. + /// - attributes: The attributes to set. + /// - Throws: ArgumentException/invalidOperationException(_:) static func valueOf(_ symbol: String, _ properties: [ICandleSymbolProperty]) -> CandleSymbol { return CandleSymbol(symbol, properties) } diff --git a/DXFeedFramework/Events/Market/Candles/ICandleSymbolProperty.swift b/DXFeedFramework/Events/Market/Candles/ICandleSymbolProperty.swift index 96ab1d614..cb0203c95 100644 --- a/DXFeedFramework/Events/Market/Candles/ICandleSymbolProperty.swift +++ b/DXFeedFramework/Events/Market/Candles/ICandleSymbolProperty.swift @@ -7,7 +7,19 @@ import Foundation -protocol ICandleSymbolProperty { +/// Property of the ``CandleSymbol`` +public protocol ICandleSymbolProperty { + /// Change candle event symbol string with this attribute set + /// and returns new candle event symbol string. + /// + /// - Parameters: + /// - symbol: The original candle event symbol. + /// - Returns: Returns candle event symbol string with this attribute set. func changeAttributeForSymbol(symbol: String?) -> String? + /// Internal method that initializes attribute in the candle symbol. + /// + /// - Parameters: + /// - candleSymbol: The candle symbol + /// - Throws: ``ArgumentException/invalidOperationException(_:)`` func checkInAttribute(candleSymbol: CandleSymbol) throws } diff --git a/DXFeedFramework/Events/Market/Extensions/IIndexedEvent+Ext.swift b/DXFeedFramework/Events/Market/Extensions/IIndexedEvent+Ext.swift new file mode 100644 index 000000000..02442fa59 --- /dev/null +++ b/DXFeedFramework/Events/Market/Extensions/IIndexedEvent+Ext.swift @@ -0,0 +1,29 @@ +// +// IIndexedEvent+Ext.swift +// DXFeedFramework +// +// Created by Aleksey Kosylo on 11.09.23. +// + +import Foundation + +public extension IIndexedEvent { + static var txPending: Int32 { + return 0x01 + } + static var removeEvent: Int32 { + return 0x02 + } + static var snapshotBegin: Int32 { + return 0x04 + } + static var snapshotEnd: Int32 { + return 0x08 + } + static var snapshotSnip: Int32 { + return 0x10 + } + static var snapShotMode: Int32 { + return 0x40 + } +} diff --git a/DXFeedFramework/Events/Market/IEventType.swift b/DXFeedFramework/Events/Market/IEventType.swift index 273520b02..650406dd2 100644 --- a/DXFeedFramework/Events/Market/IEventType.swift +++ b/DXFeedFramework/Events/Market/IEventType.swift @@ -7,7 +7,23 @@ import Foundation +/// Marks all event types that can be received via dxFeed API. +/// +/// Events are considered instantaneous, non-persistent, and unconflateable +/// (each event is individually delivered) unless they implement one of interfaces +/// defined in this package to further refine their meaning. +/// +/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/EventType.html) public protocol IEventType { + /// Gets or sets event symbol that identifies this event type . + /// + /// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/EventType.html#getEventSymbol--) var eventSymbol: String { get set } + /// Gets or sets time when event was created or zero when time is not available. + /// + /// The difference, measured in milliseconds, between the event creation time and midnight, + /// January 1, 1970 UTC or zero when time is not available. + /// + /// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/EventType.html#getEventTime--) var eventTime: Int64 { get set } } diff --git a/DXFeedFramework/Events/Market/IIndexedEvent.swift b/DXFeedFramework/Events/Market/IIndexedEvent.swift index 58446043c..c100c97b7 100644 --- a/DXFeedFramework/Events/Market/IIndexedEvent.swift +++ b/DXFeedFramework/Events/Market/IIndexedEvent.swift @@ -7,40 +7,53 @@ import Foundation +/// Represents an indexed collection of up-to-date information about some +/// condition or state of an external entity that updates in real-time. +/// +/// For example, ``Order`` represents an order to buy or to sell some market instrument +/// that is currently active on a market exchange and multiple +/// orders are active for each symbol at any given moment in time. +/// +/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/IndexedEvent.html) public protocol IIndexedEvent: IEventType { + /// Indicates a pending transactional update. When is 1, + /// it means that an ongoing transaction update, that spans multiple events, is in process. static var txPending: Int32 { get } + /// Indicates that the event with the corresponding index has to be removed. static var removeEvent: Int32 { get } + /// Indicates when the loading of a snapshot starts. static var snapshotBegin: Int32 { get } + /// ``snapshotEnd-5csc3`` or ``snapshotSnip-le44``indicates the end of a snapshot. + /// The difference between ``snapshotEnd-3emwu`` and ``snapshotSnip-7nvc9`` is the following: + /// ``snapshotEnd-5csc3``indicates that the data source sent all the data pertaining to + /// the subscription for the corresponding indexed event, + /// while ``snapshotSnip-le44``indicates that some limit on the amount of data was reached + /// and while there still might be more data available, it will not be provided. static var snapshotEnd: Int32 { get } + /// ``snapshotEnd-5csc3``or ``snapshotSnip-7nvc9``indicates the end of a snapshot. + /// The difference between ``snapshotEnd-5csc3`` and ``snapshotSnip-7nvc9``is the following: + /// ``snapshotEnd-3emwu``indicates that the data source sent all the data pertaining to + /// the subscription for the corresponding indexed event, + /// while ``snapshotSnip-7nvc9``indicates that some limit on the amount of data was reached + /// and while there still might be more data available, it will not be provided. static var snapshotSnip: Int32 { get } + /// Is used to instruct dxFeed to use snapshot mode. + /// It is intended to be used only for publishing to activate (if not yet activated) snapshot mode. + /// The difference from ``snapshotBegin-8p34e`` flag is that ``snapShotMode-8tvrw`` + /// only switches on snapshot mode without starting snapshot synchronization protocol. static var snapShotMode: Int32 { get } + /// Gets source of this event. var eventSource: IndexedEventSource { get } + /// Gets or sets transactional event flags. var eventFlags: Int32 { get set } + /// Gets or sets unique per-symbol index of this event. var index: Long { get set } } -public extension IIndexedEvent { - static var txPending: Int32 { - return 0x01 - } - static var removeEvent: Int32 { - return 0x02 - } - static var snapshotBegin: Int32 { - return 0x04 - } - static var snapshotEnd: Int32 { - return 0x08 - } - static var snapshotSnip: Int32 { - return 0x10 - } - static var snapShotMode: Int32 { - return 0x40 - } -} - +/// Just wrapper around event flags. +/// +/// To simplify checking in clientside code public extension IIndexedEvent { func snapshotBegin() -> Bool { return (eventFlags & Self.snapshotBegin) != 0 diff --git a/DXFeedFramework/Events/Market/IndexedEventSource.swift b/DXFeedFramework/Events/Market/IndexedEventSource.swift index 65fc6ef83..d961eedb5 100644 --- a/DXFeedFramework/Events/Market/IndexedEventSource.swift +++ b/DXFeedFramework/Events/Market/IndexedEventSource.swift @@ -6,19 +6,31 @@ // import Foundation - +/// Source identifier for . +/// +/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/IndexedEventSource.html) public class IndexedEventSource { - let identifier: Int - let name: String + /// Gets a source identifier. Source identifier is non-negative. + public let identifier: Int + /// Gets a name of identifier. + public let name: String + /// The default source with zero identifier for all events that do not support multiple sources. static let defaultSource = IndexedEventSource(identifier: 0, name: "DEFAULT") - init(identifier: Int, name: String) { + /// Initializes a new instance of the class. + /// + /// - Parameters: + /// - identifier: The identifier + /// - name: The name of identifier + public init(identifier: Int, name: String) { self.name = name self.identifier = identifier } - - func toString() -> String { + /// Returns a string representation of the object. + /// + /// - Returns: A string representation of the object. + public func toString() -> String { return name } } diff --git a/DXFeedFramework/Events/Market/MarketEvent.swift b/DXFeedFramework/Events/Market/MarketEvent.swift index 57c09faf9..53cb83f2a 100644 --- a/DXFeedFramework/Events/Market/MarketEvent.swift +++ b/DXFeedFramework/Events/Market/MarketEvent.swift @@ -12,5 +12,6 @@ public protocol MarketEvent: IEventType { } struct MarketEventConst { + /// Maximum allowed sequence value. static let maxSequence = Int32((1 << 22) - 1) } diff --git a/DXFeedFramework/Native/ErrorHandling/ArgumentException.swift b/DXFeedFramework/Native/ErrorHandling/ArgumentException.swift index b29ffb3e8..0ea81e77c 100644 --- a/DXFeedFramework/Native/ErrorHandling/ArgumentException.swift +++ b/DXFeedFramework/Native/ErrorHandling/ArgumentException.swift @@ -7,7 +7,7 @@ import Foundation -enum ArgumentException: Error { +public enum ArgumentException: Error { case missingCandleType case missingCandlePrice case missingCandleSession diff --git a/DXFeedFrameworkTests/FeedTest.swift b/DXFeedFrameworkTests/FeedTest.swift index 280b6c30b..d8d48471e 100644 --- a/DXFeedFrameworkTests/FeedTest.swift +++ b/DXFeedFrameworkTests/FeedTest.swift @@ -43,11 +43,11 @@ final class FeedTest: XCTestCase { print("asd".description) XCTAssertNotNil((WildcardSymbol.all as Any) as? Symbol, "String is not a symbol") print(WildcardSymbol.all.stringValue) - let symbol = try CandleSymbol(symbol: "test") + let symbol = try CandleSymbol.valueOf("test") XCTAssertNotNil((TimeSeriesSubscriptionSymbol(symbol: symbol, fromTime: 0) as Any) as? Symbol, "String is not a symbol") - let symbol1 = try CandleSymbol(symbol: "test") + let symbol1 = try CandleSymbol.valueOf("test") let testString = TimeSeriesSubscriptionSymbol(symbol: symbol1, fromTime: 10).stringValue print(testString) }