Interface Instrument


public interface Instrument
Represents an Instrument.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a listener for Depth of Market updates.
    void
    Adds a listener for tick updates
    void
    Adds a listener for property changes (bidPrice, askPrice etc)
    double
    calcCommission(float qty)
    Calculates the commission to trade the given quantity of shares/contracts.
    double
    calcCommission(int qty)
    Calculates the commission to trade the given quantity of shares/contracts.
    double
    calcPnL(double rawMove, float qty)
    Calculates the profit or loss for the given quantity and the raw price movement.
    double
    calcPnL(double rawMove, int qty)
    Calculates the profit or loss for the given quantity and the raw price movement.
    void
    forEachBar(long startTime, long endTime, BarSize barSize, boolean rth, BarOperation operation)
    Performs the given operation on each bar that occurred between the given startTime and endTime.
    void
    forEachTick(long startTime, long endTime, boolean rth, boolean useHistoricalBars, TickOperation operation)
    Performs the given operation on each tick that occurred between the given startTime and endTime.
    default void
    forEachTick(long startTime, long endTime, boolean rth, TickOperation operation)
    Performs the given operation on each tick that occurred between the given startTime and endTime.
    default void
    forEachTick(long startTime, long endTime, TickOperation operation)
    Performs the given operation on each tick that occurred between the given startTime and endTime.
    format(double value)
    Formats the given value as a string.
    format(float value)
    Formats the given value as a string.
    float
    Gets the current ask price for this instrument.
    int
    Gets the current ask size for this instrument.
    float
    Gets the current ask size for this instrument (as a floating point for partial values).
    getBars(long endTime, int count, BarSize barSize, boolean rth)
    Loads the given number of bars from the given end time.
    getBars(long startTime, long endTime, BarSize barSize, boolean rth)
    Gets the bars that occurred between the given startTime and endTime
    float
    Gets the current bid price for this instrument.
    int
    Gets the current bid size for this instrument.
    float
    Gets the current bid size for this instrument (as a floating point for partial values).
    Gets the broker service (order fulfillment).
    float
    Gets the current price to buy this instrument.
    float
    Gets the change since the previous close for this instrument.
    Gets the data source for this instrument.
    int
    Gets the default order quantity for this instrument.
    float
    Gets the default order quantity for this instrument as a floating point (for crypto currencies).
    Gets the history of the DOM since the DOM was last opened.
    long
    getEndOfDay(long time, boolean rth)
    Gets the end of the day (in millis since 1970) for the given day.
    long
    getEndOfMonth(long time, boolean rth)
    Gets the end of the month (in millis since 1970) for the given time.
    long
    getEndOfWeek(long time, boolean rth)
    Gets the end of the week (in millis since 1970) for the given time.
    long
    getEndOfYear(long time, boolean rth)
    Gets the end of the year (in millis since 1970) for the given time.
    Gets the exchange symbol for this instrument.
    float
    Gets the daily high price.
    float
    Gets the last traded price for this instrument.
    int
    Gets the last traded size for this instrument.
    float
    Gets the last traded size for this instrument (as a floating point for partial values).
    long
    Gets the time of the last trade (in millis since 1970).
    Gets the most recent DOM history entry.
    float
    Gets the daily low price.
    float
    Gets the midpoint between the bid and ask price rounded to the minimum tick of the instrument.
    float
    Gets the daily open price.
    double
    Gets the size of a 'point'.
    double
    Gets the value of the movement of 1 point for a Futures contract.
    float
    Gets the closing price for the previous day.
    float
    Gets minimum increment for the order quantity for this instrument as a floating point.
    float
    Gets the current price to sell this instrument.
    float
    Gets the difference between the bid and ask price for this instrument.
    long
    getStartOfDay(long time, boolean rth)
    Gets the start of the day (in millis since 1970) for the given day.
    long
    Gets the start of the extended evening (in millis since 1970) for the given day.
    long
    getStartOfMonth(long time, boolean rth)
    Gets the start of the month (in millis since 1970) for the given time.
    long
    getStartOfWeek(long time, boolean rth)
    Gets the start of the week (in millis since 1970) for the given time.
    long
    getStartOfYear(long time, boolean rth)
    Gets the start of the year (in millis since 1970) for the given time.
    Gets the symbol for this instrument.
    default List<Tick>
    getTicks(long startTime, long endTime)
    Gets the ticks that occurred between the given startTime and endTime
    default List<Tick>
    getTicks(long startTime, long endTime, boolean rth)
    Gets the ticks that occurred between the given startTime and endTime
    getTicks(long startTime, long endTime, boolean rth, boolean useHistoricalBars)
    Gets the ticks that occurred between the given startTime and endTime
    double
    Gets the minimum tick size.
    Gets the time zone for the trading hours of this instrument.
    Gets the type of this instrument.
    Gets the underlying symbol for this instrument.
    boolean
    isInsideTradingHours(long time, boolean rth)
    Determines if the given time is inside the trading hours
    void
    Removes the listener from DOM updates.
    void
    Removes the listener from tick updates.
    void
    Removes the property change listener.
    double
    round(double value)
    Rounds the given value to the minimum tick size.
    float
    round(float value)
    Rounds the given value to the minimum tick size.
  • Method Details

    • getUnderlying

      String getUnderlying()
      Gets the underlying symbol for this instrument.
      Returns:
      underlying symbol
    • getSymbol

      String getSymbol()
      Gets the symbol for this instrument.
      Returns:
      instrument symbol
    • getExchangeSymbol

      String getExchangeSymbol()
      Gets the exchange symbol for this instrument.
      Returns:
      exchange symbol
    • getType

      Gets the type of this instrument.
      Returns:
      instrument type
    • getBroker

      Enums.Service getBroker()
      Gets the broker service (order fulfillment).
      Returns:
      broker
    • getDataSource

      Enums.Service getDataSource()
      Gets the data source for this instrument.
      Returns:
      data source
    • round

      float round(float value)
      Rounds the given value to the minimum tick size.
      Parameters:
      value - value to round
      Returns:
      rounded value to the minimum tick size.
    • round

      double round(double value)
      Rounds the given value to the minimum tick size.
      Parameters:
      value - value to round
      Returns:
      rounded value to the minimum tick size.
    • format

      String format(float value)
      Formats the given value as a string.
      Parameters:
      value - value to format
      Returns:
      formatted value as a String
    • format

      String format(double value)
      Formats the given value as a string.
      Parameters:
      value - value to format
      Returns:
      formatted value as a String
    • getDefaultQuantity

      int getDefaultQuantity()
      Gets the default order quantity for this instrument.
      Returns:
      default quantity
    • getDefaultQuantityAsFloat

      float getDefaultQuantityAsFloat()
      Gets the default order quantity for this instrument as a floating point (for crypto currencies).
      Returns:
      default quantity as a floating point
    • getQuantityInc

      float getQuantityInc()
      Gets minimum increment for the order quantity for this instrument as a floating point.
      Returns:
      minimum quantity increment as a floating point
    • getPointSize

      double getPointSize()
      Gets the size of a 'point'. This is most relevent when dealing with Forex instruments as the point size tends to be 10x the tick size.
      Returns:
      point size
    • getPointValue

      double getPointValue()
      Gets the value of the movement of 1 point for a Futures contract.
    • getTickSize

      double getTickSize()
      Gets the minimum tick size.
      Returns:
      tick size
    • calcPnL

      double calcPnL(double rawMove, int qty)
      Calculates the profit or loss for the given quantity and the raw price movement. This method also converts the amount to the base currency of the user's account
      Parameters:
      rawMove - raw price movement
      qty - number of traded units (negative for short)
      Returns:
      profit or loss converted to the base currency.
    • calcPnL

      double calcPnL(double rawMove, float qty)
      Calculates the profit or loss for the given quantity and the raw price movement. This method also converts the amount to the base currency of the user's account
      Parameters:
      rawMove - raw price movement
      qty - number of traded units (negative for short)
      Returns:
      profit or loss converted to the base currency.
    • calcCommission

      double calcCommission(int qty)
      Calculates the commission to trade the given quantity of shares/contracts.
      Parameters:
      qty - quantity (ie shares, contracts, dollars etc)
      Returns:
      the commission that would be charged by the broker
    • calcCommission

      double calcCommission(float qty)
      Calculates the commission to trade the given quantity of shares/contracts.
      Parameters:
      qty - quantity (ie shares, contracts, dollars etc)
      Returns:
      the commission that would be charged by the broker
    • getLastPrice

      float getLastPrice()
      Gets the last traded price for this instrument.
      Returns:
      the last traded price for this instrument.
    • getBidPrice

      float getBidPrice()
      Gets the current bid price for this instrument.
      Returns:
      the current bid price for this instrument.
    • getAskPrice

      float getAskPrice()
      Gets the current ask price for this instrument.
      Returns:
      the current ask price for this instrument.
    • getMidpoint

      float getMidpoint()
      Gets the midpoint between the bid and ask price rounded to the minimum tick of the instrument.
      Returns:
      current midpoint of the bid and ask price
    • getBuyPrice

      float getBuyPrice()
      Gets the current price to buy this instrument.
      Returns:
      the current price to buy this instrument.
    • getSellPrice

      float getSellPrice()
      Gets the current price to sell this instrument.
      Returns:
      the current price to sell this instrument.
    • getChange

      float getChange()
      Gets the change since the previous close for this instrument. If the previous close is not available, it will be calculated from the open price.
      Returns:
      the change since the previous close
    • getLastSize

      int getLastSize()
      Gets the last traded size for this instrument.
      Returns:
      the last traded size for this instrument.
    • getLastSizeAsFloat

      float getLastSizeAsFloat()
      Gets the last traded size for this instrument (as a floating point for partial values).
      Returns:
      the last traded size for this instrument as a floating point.
    • getAskSize

      int getAskSize()
      Gets the current ask size for this instrument.
      Returns:
      the current ask size for this instrument.
    • getAskSizeAsFloat

      float getAskSizeAsFloat()
      Gets the current ask size for this instrument (as a floating point for partial values).
      Returns:
      the current ask size for this instrument as a floating point.
    • getBidSize

      int getBidSize()
      Gets the current bid size for this instrument.
      Returns:
      the current bid size for this instrument.
    • getBidSizeAsFloat

      float getBidSizeAsFloat()
      Gets the current bid size for this instrument (as a floating point for partial values).
      Returns:
      the current bid size for this instrument as a floating point.
    • getSpread

      float getSpread()
      Gets the difference between the bid and ask price for this instrument.
      Returns:
      the difference between the bid and ask price
    • getHigh

      float getHigh()
      Gets the daily high price.
      Returns:
      daily high price
    • getLow

      float getLow()
      Gets the daily low price.
      Returns:
      daily low price
    • getOpen

      float getOpen()
      Gets the daily open price.
      Returns:
      daily open price
    • getPreviousClose

      float getPreviousClose()
      Gets the closing price for the previous day.
      Returns:
      the closing price for the previous day
    • getLastTimestamp

      long getLastTimestamp()
      Gets the time of the last trade (in millis since 1970).
      Returns:
      the time of the last trade
    • getStartOfDay

      long getStartOfDay(long time, boolean rth)
      Gets the start of the day (in millis since 1970) for the given day.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      start of data time in milliseconds since 1970
    • getEndOfDay

      long getEndOfDay(long time, boolean rth)
      Gets the end of the day (in millis since 1970) for the given day.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      end of data time in milliseconds since 1970
    • getStartOfWeek

      long getStartOfWeek(long time, boolean rth)
      Gets the start of the week (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      start of data time in milliseconds since 1970
    • getStartOfEveningSession

      long getStartOfEveningSession(long time)
      Gets the start of the extended evening (in millis since 1970) for the given day. This can be different than the end of day for the regular session as their could be a pause before the evening session begins.
      Parameters:
      time - specifies the day in millis.
      Returns:
      start time of the evening session
    • getEndOfWeek

      long getEndOfWeek(long time, boolean rth)
      Gets the end of the week (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      end of data time in milliseconds since 1970
    • getStartOfMonth

      long getStartOfMonth(long time, boolean rth)
      Gets the start of the month (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      start of data time in milliseconds since 1970
    • getEndOfMonth

      long getEndOfMonth(long time, boolean rth)
      Gets the end of the month (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      end of data time in milliseconds since 1970
    • getStartOfYear

      long getStartOfYear(long time, boolean rth)
      Gets the start of the year (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      start of data time in milliseconds since 1970
    • getEndOfYear

      long getEndOfYear(long time, boolean rth)
      Gets the end of the year (in millis since 1970) for the given time.
      Parameters:
      time - specifies the day in millis
      rth - specifies if regular or extended trading hours should be used.
      Returns:
      end of data time in milliseconds since 1970
    • isInsideTradingHours

      boolean isInsideTradingHours(long time, boolean rth)
      Determines if the given time is inside the trading hours
      Parameters:
      time - time in milliseconds since 1970
      rth - regular trading hours
      Returns:
      true if the time is inside the trading hours for this instrument
    • getTimeZone

      TimeZone getTimeZone()
      Gets the time zone for the trading hours of this instrument.
      Returns:
      time zone for the trading hours of this instrument
    • getTicks

      default List<Tick> getTicks(long startTime, long endTime)
      Gets the ticks that occurred between the given startTime and endTime
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      Returns:
      list of ticks that occurred in the given time
    • getTicks

      default List<Tick> getTicks(long startTime, long endTime, boolean rth)
      Gets the ticks that occurred between the given startTime and endTime
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      rth - regular trading hours
      Returns:
      list of ticks that occurred in the given time
    • getTicks

      List<Tick> getTicks(long startTime, long endTime, boolean rth, boolean useHistoricalBars)
      Gets the ticks that occurred between the given startTime and endTime
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      rth - regular trading hours
      useHistoricalBars - if true, ticks are generated from historical OHLC bars
      Returns:
      list of ticks that occurred in the given time
    • forEachTick

      default void forEachTick(long startTime, long endTime, boolean rth, TickOperation operation)
      Performs the given operation on each tick that occurred between the given startTime and endTime. If you need a large number of ticks (> 100K), this is preferred to the getTicks method since it will be less memory intensive.
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      rth - regular trading hours
      operation - operation to perform on each tick
    • forEachTick

      void forEachTick(long startTime, long endTime, boolean rth, boolean useHistoricalBars, TickOperation operation)
      Performs the given operation on each tick that occurred between the given startTime and endTime. If you need a large number of ticks (> 100K), this is preferred to the getTicks method since it will be less memory intensive.
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      rth - regular trading hours
      useHistoricalBars - if true, ticks are generated from historical OHLC bars
      operation - operation to perform on each tick
    • forEachTick

      default void forEachTick(long startTime, long endTime, TickOperation operation)
      Performs the given operation on each tick that occurred between the given startTime and endTime. If you need a large number of ticks (> 100K), this is preferred to the getTicks method since it will be less memory intensive.
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      operation - operation to perform on each tick
    • forEachBar

      void forEachBar(long startTime, long endTime, BarSize barSize, boolean rth, BarOperation operation) throws MException
      Performs the given operation on each bar that occurred between the given startTime and endTime. Note: only linear bars are currently supported (no second base bars either)
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      barSize - size of the bars
      rth - regular trading hours
      operation - operation to perform on each bar
      Throws:
      MException - if there is an error processing the tick data
    • getBars

      List<Bar> getBars(long startTime, long endTime, BarSize barSize, boolean rth) throws MException
      Gets the bars that occurred between the given startTime and endTime
      Parameters:
      startTime - start time (in milliseconds since 1970)
      endTime - end time (in milliseconds since 1970)
      barSize - size of the bars
      rth - regular trading hours
      Returns:
      list of ticks that occurred in the given time
      Throws:
      MException - if there is an error loading the bars
    • getBars

      List<Bar> getBars(long endTime, int count, BarSize barSize, boolean rth) throws MException
      Loads the given number of bars from the given end time.
      Parameters:
      endTime - end time (in milliseconds since 1970)
      count - number of bars to load
      barSize - size of the bars
      rth - regular trading hours
      Returns:
      list of ticks that occurred in the given time
      Throws:
      MException - if there is an error loading the bars
    • addListener

      void addListener(TickOperation listener)
      Adds a listener for tick updates
      Parameters:
      listener - tick listener.
    • removeListener

      void removeListener(TickOperation listener)
      Removes the listener from tick updates.
      Parameters:
      listener - tick listener.
    • addListener

      void addListener(DOMListener listener)
      Adds a listener for Depth of Market updates.
      Parameters:
      listener - Depth of Market listener.
    • removeListener

      void removeListener(DOMListener listener)
      Removes the listener from DOM updates.
      Parameters:
      listener - Depth of Market listener.
    • addPropertyChangeListener

      void addPropertyChangeListener(PropertyChangeListener listener)
      Adds a listener for property changes (bidPrice, askPrice etc)
      Parameters:
      listener - Property Change listener.
    • removePropertyChangeListener

      void removePropertyChangeListener(PropertyChangeListener listener)
      Removes the property change listener.
      Parameters:
      listener - Property Change listener.
    • getDOMHistory

      List<DOMSnapshot> getDOMHistory()
      Gets the history of the DOM since the DOM was last opened.
      Returns:
      history of DOM snapshots since the DOM was last opened
    • getLatestDOMHistory

      DOMSnapshot getLatestDOMHistory()
      Gets the most recent DOM history entry.
      Returns:
      most recent DOM history entry