Skip to content

Commit

Permalink
Documentation for native wrappers and MarketEvents,
Browse files Browse the repository at this point in the history
for IPF Reader
  • Loading branch information
kosyloa committed Sep 12, 2023
1 parent f360475 commit aae57d8
Show file tree
Hide file tree
Showing 36 changed files with 336 additions and 68 deletions.
2 changes: 1 addition & 1 deletion DXFeedFramework/Api/DXFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DXFeed {
/// - Parameters:
/// - events: The list of event codes.
/// - Returns: ``DXFeedSubcription``
/// - Throws: GraalException. Rethrows exception from Java.
/// - Throws: ``GraalException``. Rethrows exception from Java., ``NativeException/nilValue``
public func createSubscription(_ events: [EventCode]) throws -> DXFeedSubcription {
return try DXFeedSubcription(native: native.createSubscription(events), events: events)
}
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Api/DXFeedSubcription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DXFeedSubcription {
/// This method does nothing if this subscription is closed.
///
/// [Javadoc](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXFeedSubscription.html#addEventListener-com.dxfeed.api.DXFeedEventListener)
/// - Throws: GraalException. Rethrows exception from Java.
/// - Throws: ``GraalException`` Rethrows exception from Java, ``NativeException.nilValue``
public func add<O>(observer: O) throws
where O: DXEventListener,
O: Hashable {
Expand Down
8 changes: 8 additions & 0 deletions DXFeedFramework/Events/EventCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@

import Foundation

/// A list of all events, that can be passed to/from native code, represented as a numeric code.
///
/// In a particular case, these are implementations ``IEventType``
public enum EventCode: CaseIterable {
/// See ``Quote``
case quote
/// See ``Profile``
case profile
case summary
case greeks
/// See ``Candle``
case candle
case dailyCandle
case underlying
case theoPrice
/// See ``Trade``
case trade
case tradeETH
case configuration
case message
/// See ``TimeAndSale``
case timeAndSale
case orderBase
case order
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/Candles/CandleAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public enum CandleAlignment: DXCandleAlignment, CaseIterable {
case midnight = "Midnight"
case session = "Session"

static let attributeKey = "a"

public static let attributeKey = "a"
/// Default alignment is ``midnight``
public static let defaultAlignment = midnight

/// A dictionary containing the matching string representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
///
/// Price interval may be equal to zero. It means every unique price creates a particular candle
/// to aggregate all events with this price for the chosen ``CandlePeriod``
/// <li>Non-zero price level creates sequence of intervals starting from 0:
/// Non-zero price level creates sequence of intervals starting from 0:
/// ...,[-pl;0),[0;pl),[pl;2*pl),...,[n*pl,n*pl+pl).
/// Events aggregated by chosen ``CandlePeriod`` and price intervals.
///
Expand Down
18 changes: 15 additions & 3 deletions DXFeedFramework/Events/Market/Direction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,35 @@
//

import Foundation

/// Direction of the price movement. For example tick direction for last trade price.
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Direction.html)
public enum Direction: Int32, CaseIterable {
// swiftlint:disable identifier_name

/// Direction is undefined, unknown or inapplicable.
/// It includes cases with undefined price value or when direction computation was not performed.
case undefined = 0
/// Current price is lower than previous price.
case down
/// Current price is the same as previous price and is lower than the last known price of different value.
case zeroDown
/// Current price is equal to the only known price value suitable for price direction computation.
/// Unlike ``undefined`` the ``zero`` direction implies that current price is defined and
/// direction computation was duly performed but has failed to detect any upward or downward price movement.
/// It is also reported for cases when price sequence was broken and direction computation was restarted anew.
case zero
/// Current price is the same as previous price and is higher than the last known price of different value.
case zeroUp
/// Current price is higher than previous price.
case up
// swiftlint:enable identifier_name

static let values: [Direction] = {
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .undefined, allCases: Direction.allCases)
}()

static func valueOf(_ value: Int) -> Direction {
/// Returns an enum constant of the ``Direction`` by integer code bit pattern.
public static func valueOf(_ value: Int) -> Direction {
return Direction.values[value]
}
}
46 changes: 43 additions & 3 deletions DXFeedFramework/Events/Market/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,61 @@
//

import Foundation

/// Profile information snapshot that contains security instrument description.
///
/// It represents the most recent information that is available about the traded security
/// on the market at any given moment of time.
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Profile.html)
public class Profile: MarketEvent, ILastingEvent, CustomStringConvertible {
public let type: EventCode = .profile
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
* +--------+----+----+----+----+
* | | SSR | Status |
* +--------+----+----+----+----+
*/

/// Gets or sets description of the security instrument.
public var descriptionStr: String?
/// Gets or sets description of the reason that trading was halted.
public var statusReason: String?
/// Gets or sets starting time of the trading halt interval.
/// Time is measured in milliseconds between the current time and midnight, January 1, 1970 UTC.
public var haltStartTime: Long = 0
// Gets or sets ending time of the trading halt interval.
/// Time is measured in milliseconds between the current time and midnight, January 1, 1970 UTC.
public var haltEndTime: Long = 0
/// Gets or sets the maximal (high) allowed price.
public var highLimitPrice: Double = .nan
/// Gets or sets the minimal (low) allowed price.
public var lowLimitPrice: Double = .nan
/// Gets or sets the maximal (high) price in last 52 weeks.
public var high52WeekPrice: Double = .nan
/// Gets or sets the minimal (low) price in last 52 weeks.
public var low52WeekPrice: Double = .nan
/// Gets or sets the correlation coefficient of the instrument to the S&amp;P500 index.
public var beta: Double = .nan
/// Gets or sets the earnings per share (the company’s profits divided by the number of shares).
public var earningsPerShare: Double = .nan
/// Gets or sets the frequency of cash dividends payments per year (calculated).
public var dividendFrequency: Double = .nan
/// Gets or sets the amount of the last paid dividend.
public var exDividendAmount: Double = .nan
/// Gets or sets the identifier of the day of the last dividend payment (ex-dividend date).
/// Identifier of the day is the number of days passed since January 1, 1970.
public var exDividendDayId: Int32 = 0
/// Gets or sets the the number of shares outstanding.
public var shares: Double = .nan
/// Gets or sets the free-float - the number of shares outstanding that are available to the public for trade.
public var freeFloat: Double = .nan
public var flags: Int32 = 0
/// Gets or sets implementation-specific flags.
/// **Do not use this method directly**
var flags: Int32 = 0

// SSR values are taken from ShortSaleRestriction enum.
private let ssrMask = 3
Expand All @@ -37,7 +70,8 @@ public class Profile: MarketEvent, ILastingEvent, CustomStringConvertible {
private let statusMask = 3
private let statusShift = 0

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

Expand Down Expand Up @@ -67,6 +101,7 @@ flags: \(flags)
}

extension Profile {
/// Gets or sets short sale restriction of the security instrument.
public var shortSaleRestriction: ShortSaleRestriction {
get {
ShortSaleRestriction.valueOf(Int(BitUtil.getBits(flags: Int(flags), mask: ssrMask, shift: ssrShift)))
Expand All @@ -76,10 +111,12 @@ extension Profile {
}
}

/// Gets a value indicating whether short sale of the security instrument is restricted.
public var isShortSaleRestricted: Bool {
shortSaleRestriction == .active
}

/// Gets or sets trading status of the security instrument.
public var tradingStatus: TradingStatus {
get {
TradingStatus.valueOf(BitUtil.getBits(flags: Int(flags), mask: statusMask, shift: statusShift))
Expand All @@ -92,14 +129,17 @@ extension Profile {
}
}

/// Gets a value indicating whether trading of the security instrument is halted.
public var isTradingHalted: Bool {
return tradingStatus == .halted
}

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

/// Returns string representation of this order fields.
func baseFieldsToString() -> String {
return """
\(eventSymbol), \
Expand Down
7 changes: 6 additions & 1 deletion DXFeedFramework/Events/Market/ShortSaleRestriction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@

import Foundation

/// Short sale restriction on an instrument.
public enum ShortSaleRestriction: Int, CaseIterable {
/// Short sale restriction is undefined, unknown or inapplicable.
case undefined = 0
/// Short sale restriction is active.
case active
/// Short sale restriction is inactive.
case inactive

static let values: [ShortSaleRestriction] = {
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .undefined, allCases: ShortSaleRestriction.allCases)
}()

static func valueOf(_ value: Int) -> ShortSaleRestriction {
/// Returns an enum constant of the ``ShortSaleRestriction`` by integer code bit pattern.
public static func valueOf(_ value: Int) -> ShortSaleRestriction {
return ShortSaleRestriction.values[value]
}
}
11 changes: 8 additions & 3 deletions DXFeedFramework/Events/Market/Side.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
//

import Foundation

/// Side of an order or a trade.
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/Side.html)
public enum Side: Int, CaseIterable {
/// Side is undefined, unknown or inapplicable.
case undefined = 0
/// Buy side (bid).
case buy
/// Sell side (ask or offer).
case sell

static let values: [Side] = {
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .undefined, allCases: Side.allCases)
}()

static func valueOf(_ value: Int) -> Side {
/// Returns an enum constant of the ``Side`` by integer code bit pattern.
public static func valueOf(_ value: Int) -> Side {
return Side.values[value]
}
}
24 changes: 21 additions & 3 deletions DXFeedFramework/Events/Market/TimeAndSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class TimeAndSale: MarketEvent, ITimeSeriesEvent, CustomStringConvertible
/// This field format is specific for every particular data feed.
public var exchangeSaleConditions: String?
/// Gets or sets implementation-specific flags.
/// Do not use this method directly.
public var flags: Int32 = 0
/// **Do not use this method directly**.
var flags: Int32 = 0
/// Gets or sets buyer of this time and sale event.
public var buyer: String?
/// Gets or sets seller of this time and sale event.
Expand Down Expand Up @@ -118,6 +118,9 @@ extension TimeAndSale {

}

/// 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))
Expand All @@ -127,6 +130,10 @@ extension TimeAndSale {
Long((TimeUtil.getMillisFromTime(newValue)) << 22) | Long(getSequence())
}
}

/// Gets or sets timestamp of the original event in nanoseconds.
///
/// Time is measured in nanoseconds between the current time and midnight, January 1, 1970 UTC.
public var timeNanos: Int64 {
get {
TimeNanosUtil.getNanosFromMillisAndNanoPart(time, timeNanoPart)
Expand Down Expand Up @@ -181,6 +188,7 @@ extension TimeAndSale {
}

/// Gets or sets a value indicating whether this event represents a valid intraday tick.
///
/// Note, that a correction for a previously distributed valid tick represents a new valid tick itself,
/// but a cancellation of a previous valid tick does not.
public var isValidTick: Bool {
Expand All @@ -203,20 +211,30 @@ extension TimeAndSale {
}

/// Gets a value indicating whether this is a new event (not cancellation or correction).
///
/// It is true for newly created time and sale event.
public var isNew: Bool {
timeAndSaleType == .new
}

/// Gets a value indicating whether this is a correction of a previous event.
///
/// It is false for newly created time and sale event.
/// true if this is a correction of a previous event.
public var isCorrection: Bool {
timeAndSaleType == .correction
}

/// Gets a value indicating whether this is a cancellation of a previous event.
///
/// It is false for newly created time and sale event.
/// true if this is a cancellation of a previous event.
public var isCancel: Bool {
timeAndSaleType == .cancel
}

func toString() -> String {
/// Returns string representation of this time and sale event.
public func toString() -> String {
return """
TimeAndSale{"\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
Expand Down
11 changes: 8 additions & 3 deletions DXFeedFramework/Events/Market/TimeAndSaleType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
//

import Foundation

/// Type of a time and sale event.
///
/// [For more details see](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/event/market/TimeAndSaleType.html)
public enum TimeAndSaleType: Int, CaseIterable {
/// Represents new time and sale event.
case new = 0
/// Represents correction time and sale event.
case correction
/// Represents cancel time and sale event.
case cancel

static let values: [TimeAndSaleType] = {
EnumUtil.createEnumBitMaskArrayByValue(defaultValue: .new, allCases: TimeAndSaleType.allCases)
}()

static func valueOf(_ value: Int) -> TimeAndSaleType {
/// Returns an enum constant of the ``TimeAndSaleType`` by integer code bit pattern.
public static func valueOf(_ value: Int) -> TimeAndSaleType {
return TimeAndSaleType.values[value]
}
}
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Trade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation

public class Trade: TradeBase {
/// Returns string representation of this trade event.
override func toString() -> String {
public override func toString() -> String {
return "Trade{\(baseFieldsToString())}"
}
}
Loading

0 comments on commit aae57d8

Please sign in to comment.