TradableUtilities

@objc public class TradableUtilities: NSObject

A helper class providing methods for easy price/pip conversion and more.

  • Converts a price distance to a pip distance.

    Throws

    TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.

    Declaration

    Swift

    public static func convertToPipDistance(_ priceDistance: Double, for instrument: TradableInstrument) throws -> Double

    Parameters

    priceDistance

    The price distance to be converted.

    instrument

    The instrument for which the conversion should be made.

    Return Value

    A distance in pips.

  • Converts a difference between two prices to a pip distance.

    Throws

    TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.

    Declaration

    Swift

    public static func getPipDistance(between lowerPrice: Double, and higherPrice: Double, for instrument: TradableInstrument) throws -> Double

    Parameters

    lowerPrice

    The lower price to be used in conversion.

    higherPrice

    The higher price to be used in conversion.

    instrument

    The instrument for which the conversion should be made.

    Return Value

    A distance in pips.

  • Converts a pip distance to a price distance.

    Throws

    TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.

    Declaration

    Swift

    public static func convertToPriceDistance(_ pipDistance: Double, for instrument: TradableInstrument) throws -> Double

    Parameters

    pipDistance

    The pip distance to be converted.

    instrument

    The instrument for which the conversion should be made.

    Return Value

    A price distance.

  • Calculates a price from a price given a pip distance.

    Throws

    TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.

    Declaration

    Swift

    public static func getPrice(with distance: Double, from price: Double, for instrument: TradableInstrument) throws -> Double

    Parameters

    distance

    The pip distance to be added.

    price

    The price to which the pip distance should be added.

    instrument

    The instrument for which the conversion should be made.

    Return Value

    A price.

  • Calculates a profit or loss in whole pips.

    Throws

    TradableUtilitiesError.unsupportedInstrument if there is no possibility of making conversion for specified instrument.

    Declaration

    Swift

    public static func getProfitLossInPips(between openPrice: Double, and currentPrice: Double, for instrument: TradableInstrument) throws -> Int

    Parameters

    openPrice

    The price from which the PnL in pips should be calculated.

    currentPrice

    The price for which the PnL in pips should be calculated.

    instrument

    The instrument for which the conversion should be made.

    Return Value

    A PnL value in whole pips.