Class IBApiNext

Next-gen Typescript implementation of the Interactive Brokers TWS (or IB Gateway) API.

If you prefer to stay as close as possible to the official TWS API interfaces and functionality, use [[IBApi]].

If you prefer to use an API that provides some more convenience functions, such as auto-reconnect or RxJS Observables that stay functional during re-connect, use [[IBApiNext]].

[[IBApiNext]] does return RxJS Observables on most of the functions. The first subscriber will send the request to TWS, while the last un-subscriber will cancel it. Any subscriber in between will get a replay of the latest received value(s). This is also the case if you call same function with same arguments multiple times ([[IBApiNext]] will make sure that a similar subscription is not requested multiple times from TWS, but it will become a new observers to the existing subscription). In case of an error, a re-subscribe will send the TWS request again (it is fully compatible to RxJS operators, e.g. retry or retryWhen).

Note that connection errors are not reported to the returned Observables as returned by get-functions, but they will simply stop emitting values until TWS connection is re-established. Use [[IBApiNext.connectState]] for observing the connection state.

Hierarchy

  • IBApiNext

Constructors

Properties

Accessors

Methods

Constructors

Properties

_nextReqId: number = 1
api: IBApiAutoConnection

The [[IBApi]] with auto-reconnect.

errorSubject: Subject<IBApiNextError> = ...

The IBApi error [[Subject]].

All errors from [[IBApi]] error events will be sent to this subject.

getMarketDataSingle: ((contract, genericTickList, regulatorySnapshot) => Promise<MutableMarketData>) = ...

Type declaration

    • (contract, genericTickList, regulatorySnapshot): Promise<MutableMarketData>
    • Parameters

      • contract: Contract
      • genericTickList: string
      • regulatorySnapshot: boolean

      Returns Promise<MutableMarketData>

      Deprecated

      please use getMarketDataSnapshot instead of getMarketDataSingle.

logger: IBApiNextLogger

The [[IBApiNextLogger]] instance.

searchContracts: ((pattern) => Promise<ContractDescription[]>) = ...

Type declaration

subscriptions: IBApiNextSubscriptionRegistry

The subscription registry.

Accessors

Methods

  • Cancels all active orders. This method will cancel ALL open orders including those placed directly from TWS.

    Returns void

    See

    [[cancelOrder]]

  • Cancels an active order placed by from the same API client ID.

    Note: API clients cannot cancel individual orders placed by other clients. Use [[cancelAllOrders]] instead.

    Parameters

    • id: number

      The order id.

    Returns void

  • Connect to the TWS or IB Gateway.

    Parameters

    • Optional clientId: number

      A fixed client id to be used on all connection attempts. If not specified, the first connection will use the default client id (0) and increment it with each re-connection attempt.

    Returns IBApiNext

    Sse

    [[connectionState]] for observing the connection state.

  • Create subscription to receive the account summaries of all linked accounts as presented in the TWS' Account Summary tab.

    All account summaries are sent on the first event. Use incrementalUpdates argument to switch between incremental or full update mode. With incremental updates, only changed account summary values will be sent after the initial complete list. Without incremental updates, the complete list of account summaries will be sent again if any value has changed.

    https://www.interactivebrokers.com/en/software/tws/accountwindowtop.htm

    Parameters

    • group: string

      Set to "All" to return account summary data for all accounts, or set to a specific Advisor Account Group name that has already been created in TWS Global Configuration.

    • tags: string

      A comma separated list with the desired tags:

      • AccountType — Identifies the IB account structure
      • NetLiquidation — The basis for determining the price of the assets in your account. Total cash value + stock value + options value + bond value
      • TotalCashValue — Total cash balance recognized at the time of trade + futures PNL
      • SettledCash — Cash recognized at the time of settlement - purchases at the time of trade - commissions - taxes - fees
      • AccruedCash — Total accrued cash value of stock, commodities and securities
      • BuyingPower — Buying power serves as a measurement of the dollar value of securities that one may purchase in a securities account without depositing additional funds
      • EquityWithLoanValue — Forms the basis for determining whether a client has the necessary assets to either initiate or maintain security positions. Cash + stocks + bonds + mutual funds
      • PreviousDayEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
      • GrossPositionValue — The sum of the absolute value of all stock and equity option positions
      • RegTEquity — Regulation T equity for universal account
      • RegTMargin — Regulation T margin for universal account
      • SMA — Special Memorandum Account: Line of credit created when the market value of securities in a Regulation T account increase in value
      • InitMarginReq — Initial Margin requirement of whole portfolio
      • MaintMarginReq — Maintenance Margin requirement of whole portfolio
      • AvailableFunds — This value tells what you have available for trading
      • ExcessLiquidity — This value shows your margin cushion, before liquidation
      • Cushion — Excess liquidity as a percentage of net liquidation value
      • FullInitMarginReq — Initial Margin of whole portfolio with no discounts or intraday credits
      • FullMaintMarginReq — Maintenance Margin of whole portfolio with no discounts or intraday credits
      • FullAvailableFunds — Available funds of whole portfolio with no discounts or intraday credits
      • FullExcessLiquidity — Excess liquidity of whole portfolio with no discounts or intraday credits
      • LookAheadNextChange — Time when look-ahead values take effect
      • LookAheadInitMarginReq — Initial Margin requirement of whole portfolio as of next period's margin change
      • LookAheadMaintMarginReq — Maintenance Margin requirement of whole portfolio as of next period's margin change
      • LookAheadAvailableFunds — This value reflects your available funds at the next margin change
      • LookAheadExcessLiquidity — This value reflects your excess liquidity at the next margin change
      • HighestSeverity — A measure of how close the account is to liquidation
      • DayTradesRemaining — The Number of Open/Close trades a user could put on before Pattern Day Trading is detected. A value of "-1" means that the user can put on unlimited day trades.
      • Leverage — GrossPositionValue / NetLiquidation
      • $LEDGER — Single flag to relay all cash balance tags*, only in base currency.
      • $LEDGER:CURRENCY — Single flag to relay all cash balance tags*, only in the specified currency.
      • $LEDGER:ALL — Single flag to relay all cash balance tags* in all currencies.

    Returns Observable<AccountSummariesUpdate>

  • The getAccountUpdates function creates a subscription to the TWS through which account and portfolio information is delivered. This information is the exact same as the one displayed within the TWS' Account Window. In a single account structure, the account number is not necessary. Just as with the TWS' Account Window, unless there is a position change this information is updated at a fixed interval of three minutes.

    Parameters

    • Optional acctCode: string

      the specific account to retrieve.

    Returns Observable<AccountUpdatesUpdate>

    See

    [[reqAccountUpdates]], [[reqGlobalCancel]]

  • Requests status updates AND (IB documentation not correct on this point) future orders placed from TWS. Can only be used with client ID 0.

    Parameters

    • autoBind: boolean

      if set to true, the newly created orders will be assigned an API order ID and implicitly associated with this client. If set to `false, future orders will not be.

    Returns Observable<OpenOrdersUpdate>

    See

    [[reqAllOpenOrders]], [[reqOpenOrders]], [[cancelOrder]], [[reqGlobalCancel]]

  • Request contract information from TWS. This method will provide all the contracts matching the contract provided.

    It can also be used to retrieve complete options and futures chains. Though it is now (in API version > 9.72.12) advised to use reqSecDefOptParams for that purpose.

    This information will be emitted as contractDetails event.

    Parameters

    • contract: Contract

      The contract used as sample to query the available contracts.

    Returns Promise<ContractDetails[]>

  • Get the timestamp of earliest available historical data for a contract and data type.

    Parameters

    • contract: Contract

      [[Contract]] object for which head timestamp is being requested.

    • whatToShow: WhatToShow

      Type of data for head timestamp - "BID", "ASK", "TRADES", etc

    • useRTH: boolean

      Use regular trading hours only, true for yes or false for no.

    • formatDate: number

      Set to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds.

    Returns Promise<string>

  • Get data histogram of specified contract.

    Parameters

    • contract: Contract

      [[Contract]] object for which histogram is being requested

    • useRTH: boolean

      Use regular trading hours only, true for yes or false for no.

    • duration: number

      Period duration of which data is being requested

    • durationUnit: DurationUnit

      Duration unit of which data is being requested

    Returns Promise<HistogramEntry[]>

  • Get a contracts historical data.

    When requesting historical data, a finishing time and date is required along with a duration string. For example, having:

    • endDateTime: 20130701 23:59:59 GMT
    • durationStr: 3 D will return three days of data counting backwards from July 1st 2013 at 23:59:59 GMT resulting in all the available bars of the last three days until the date and time specified.

    It is possible to specify a timezone optionally.

    Parameters

    • contract: Contract

      The contract for which we want to retrieve the data.

    • endDateTime: string

      Request's ending time with format yyyyMMdd HH:mm:ss {TMZ}.

    • durationStr: string

      The amount of time for which the data needs to be retrieved:

      • [n] S (seconds)
      • [n] D (days)
      • [n] W (weeks)
      • [n] M (months)
      • [n] Y (years)
    • barSizeSetting: BarSizeSetting

      the size of the bar:

      • 1 secs
      • 5 secs
      • 15 secs
      • 30 secs
      • 1 min
      • 2 mins
      • 3 mins
      • 5 mins
      • 15 mins
      • 30 mins
      • 1 hour
      • 1 day
    • whatToShow: WhatToShow

      the kind of information being retrieved:

      • TRADES
      • MIDPOINT
      • BID
      • ASK
      • BID_ASK
      • HISTORICAL_VOLATILITY
      • OPTION_IMPLIED_VOLATILITY
      • FEE_RATE
      • REBATE_RATE
    • useRTH: number

      Set to 0 to obtain the data which was also generated outside of the Regular Trading Hours, set to 1 to obtain only the RTH data

    • formatDate: number

      Set to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds

    Returns Promise<Bar[]>

  • Create a subscription to receive update on the most recent historical data bar of a contract.

    Use IBApiNext.getHistoricalData to receive history data and use this function if you want to continue receiving real-time updates on most recent bar.

    Parameters

    • contract: Contract

      The contract for which we want to retrieve the data.

    • barSizeSetting: BarSizeSetting

      the size of the bar:

      • 1 secs
      • 5 secs
      • 15 secs
      • 30 secs
      • 1 min
      • 2 mins
      • 3 mins
      • 5 mins
      • 15 mins
      • 30 mins
      • 1 hour
      • 1 day
    • whatToShow: WhatToShow

      the kind of information being retrieved:

      • TRADES
      • MIDPOINT
      • BID
      • ASK
      • BID_ASK
      • HISTORICAL_VOLATILITY
      • OPTION_IMPLIED_VOLATILITY
      • FEE_RATE
      • REBATE_RATE
    • formatDate: number

      Set to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds

    Returns Observable<Bar>

  • Create a subscription to receive historical bid and ask prices from Time&Sales data of an instrument. The next callback will be invoked each time a new tick is received from TWS. The complete callback will be invoked when all required ticks have been received.

    Parameters

    • contract: Contract

      [[Contract]] object that is subject of query

    • startDateTime: string

      "20170701 12:01:00". Uses TWS timezone specified at login.

    • endDateTime: string

      "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.

    • numberOfTicks: number

      Number of distinct data points. Max currently 1000 per request.

    • useRTH: number

      Data from regular trading hours (1), or all available hours (0)

    • ignoreSize: boolean

      A filter only used when the source price is Bid_Ask

    Returns Observable<HistoricalTickBidAsk[]>

  • Create a subscription to receive historical last trade prices from Time&Sales data of an instrument. The next callback will be invoked each time a new tick is received from TWS. The complete callback will be invoked when all required ticks have been received.

    Parameters

    • contract: Contract

      [[Contract]] object that is subject of query

    • startDateTime: string

      "20170701 12:01:00". Uses TWS timezone specified at login.

    • endDateTime: string

      "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.

    • numberOfTicks: number

      Number of distinct data points. Max 1000 per request.

    • useRTH: number

      Data from regular trading hours (1), or all available hours (0)

    Returns Observable<HistoricalTickLast[]>

  • Create a subscription to receive historical mid prices from Time&Sales data of an instrument. The next callback will be invoked each time a new tick is received from TWS. The complete callback will be invoked when all required ticks have been received.

    Parameters

    • contract: Contract

      [[Contract]] object that is subject of query

    • startDateTime: string

      "20170701 12:01:00". Uses TWS timezone specified at login.

    • endDateTime: string

      "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.

    • numberOfTicks: number

      Number of distinct data points. Max currently 1000 per request.

    • useRTH: number

      Data from regular trading hours (1), or all available hours (0)

    Returns Observable<HistoricalTick[]>

  • Get the accounts to which the logged user has access to.

    Returns Promise<string[]>

  • Create a subscription to receive real time market data. Returns market data for an instrument either in real time or 10-15 minutes delayed (depending on the market data type specified, see [[setMarketDataType]]). If you plan to use getMarketData with either snapshot or regulatorySnapshotset to true then you should consider using getMarketDataSingle instead.

    Parameters

    • contract: Contract

      The [[Contract]] for which the data is being requested

    • genericTickList: string

      comma separated ids of the available generic ticks:

      • 100 Option Volume (currently for stocks)
      • 101 Option Open Interest (currently for stocks)
      • 104 Historical Volatility (currently for stocks)
      • 105 Average Option Volume (currently for stocks)
      • 106 Option Implied Volatility (currently for stocks)
      • 162 Index Future Premium
      • 165 Miscellaneous Stats
      • 221 Mark Price (used in TWS P&L computations)
      • 225 Auction values (volume, price and imbalance)
      • 233 RTVolume - contains the last trade price, last trade size, last trade time, total volume, VWAP, and single trade flag.
      • 236 Shortable
      • 256 Inventory
      • 258 Fundamental Ratios
      • 411 Realtime Historical Volatility
      • 456 IBDividends
    • snapshot: boolean

      For users with corresponding real time market data subscriptions. A true value will return a one-time snapshot, completing the Observable when finished, after 11s latest. A false value will provide endless streaming data, never completing the Observable.

    • regulatorySnapshot: boolean

      Snapshot for US stocks requests NBBO snapshots for users which have "US Securities Snapshot Bundle" subscription but not corresponding Network A, B, or C subscription necessary for streaming * market data. One-time snapshot of current market price that will incur a fee of 1 cent to the account per snapshot.

    Returns Observable<MarketDataUpdate>

  • Fetch a snapshot of real time market data. Returns market data for an instrument either in real time or 10-15 minutes delayed (depending on the market data type specified, see [[setMarketDataType]]). getMarketDataSingle will collect market data for a maximum of 11 seconds and then return the result.

    Parameters

    • contract: Contract

      The [[Contract]] for which the data is being requested

    • genericTickList: string

      comma separated ids of the generic ticks Look at getMarketData documentation for a list of available generic ticks.

    • regulatorySnapshot: boolean

      Snapshot for US stocks requests NBBO snapshots for users which have "US Securities Snapshot Bundle" subscription but not corresponding Network A, B, or C subscription necessary for streaming * market data. One-time snapshot of current market price that will incur a fee of 1 cent to the account per snapshot.

    Returns Promise<MutableMarketData>

  • Requests the contract's market depth (order book).

    This request must be direct-routed to an exchange and not smart-routed.

    The number of simultaneous market depth requests allowed in an account is calculated based on a formula that looks at an accounts equity, commissions, and quote booster packs.

    Parameters

    • contract: Contract

      The [[Contract]] for which the depth is being requested.

    • numRows: number

      The number of rows on each side of the order book.

    • isSmartDepth: boolean

      Flag indicates that this is smart depth request.

    • Optional mktDepthOptions: TagValue[]

      TODO document

    Returns Observable<OrderBookUpdate>

  • It returns an observable that will emit a list of scanner subscriptions.

    Parameters

    • scannerSubscription: ScannerSubscription

      ScannerSubscription

    • Optional scannerSubscriptionOptions: TagValue[]

      An array of TagValue objects.

    • Optional scannerSubscriptionFilterOptions: TagValue[]

      An optional array of TagValue objects.

    Returns Observable<MarketScannerUpdate>

    An observable that will emit a list of items.

  • Requests the next valid order ID at the current moment.

    Returns Promise<number>

  • Create a subscription to receive real time daily PnL and unrealized PnL updates.

    Parameters

    • account: string

      Account for which to receive PnL updates.

    • Optional model: string

    Returns Observable<PnL>

  • Create a subscription to receive real time updates for daily PnL of individual positions.

    Parameters

    • account: string

      Account in which position exists.

    • modelCode: string

      Model in which position exists.

    • conId: number

      Contract ID (conId) of contract to receive daily PnL updates for.

    Returns Observable<PnLSingle>

  • Requests an XML string that describes all possible scanner queries.

    Returns Promise<string>

  • Requests security definition option parameters for viewing a contract's option chain.

    This information will be emitted as securityDefinitionOptionParameter event.

    Parameters

    • underlyingSymbol: string

      The underlying symbol to query the available contracts.

    • futFopExchange: string

      The exchange on which the returned options are trading. Can be set to the empty string "" for all exchanges.

    • underlyingSecType: SecType

      The type of the underlying security, i.e. STK.

    • underlyingConId: number

      the contract ID of the underlying security.

    Returns Promise<SecurityDefinitionOptionParameterType[]>

  • Type Parameters

    • T extends number

    • R

    Parameters

    • index: number
    • key: T
    • value: R
    • map: Map<T, R>

    Returns Map<T, R>

  • Places new order.

    Parameters

    • id: number

      The order's unique identifier.

    • contract: Contract

      The order's [[Contract]].

    • order: Order

      The [[Order]] object.

    Returns void

  • Response to API accountDownloadEnd control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<AccountUpdate>>
    • accountName: string

    Returns void

    See

    [[reqOpenOrders]]

  • accountSummary event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableAccountSummaries>>
    • reqId: number
    • account: string
    • tag: string
    • value: string
    • currency: string

    Returns void

  • accountSummaryEnd event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableAccountSummaries>>
    • reqId: number

    Returns void

  • contractDetailsEnd event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<ContractDetails[]>>
    • reqId: number

    Returns void

  • currentTime event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<number>>
    • time: number

    Returns void

  • Ends the subscrition once all trades are recieved

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<ExecutionDetail[]>>
    • reqId: number
    • contract: Contract

      Contract details that is used for order

    • execution: Execution

      Execution details of an order

    Returns void

  • headTimestamp event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<string>>
    • reqId: number
    • headTimestamp: string

    Returns void

  • historicalData event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<Bar[]>>
    • reqId: number
    • time: string
    • open: number
    • high: number
    • low: number
    • close: number
    • volume: number
    • count: number
    • WAP: number

    Returns void

  • historicalDataUpdate event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<Bar>>
    • reqId: number
    • time: string
    • open: number
    • high: number
    • low: number
    • close: number
    • volume: number
    • count: number
    • WAP: number

    Returns void

  • managedAccounts event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<string[]>>
    • accountsList: string

    Returns void

  • nextValidId event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<number>>
    • orderId: number

    Returns void

  • Feeds in currently open orders.

    Parameters

    Returns void

    See

    [[placeOrder]], [[reqAllOpenOrders]], [[reqAutoOpenOrders]]

  • Ends the subscription once all openOrders are recieved

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OpenOrder[]>>

    Returns void

  • Ends the subscription once all openOrders are recieved

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OpenOrder[]>>

    Returns void

  • Response to API bind order control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OpenOrder[]>>
    • orderId: number
    • apiClientId: number
    • apiOrderId: number

    Returns void

    See

    [[reqOpenOrders]]

  • Response to API status order control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OpenOrder[]>>
    • orderId: number
    • status: OrderStatus
    • filled: number
    • remaining: number
    • avgFillPrice: number
    • Optional permId: number
    • Optional parentId: number
    • Optional lastFillPrice: number
    • Optional clientId: number
    • Optional whyHeld: string
    • Optional mktCapPrice: number

    Returns void

    See

    [[reqOpenOrders]]

  • pnl event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<PnL>>
    • reqId: number
    • dailyPnL: number
    • Optional unrealizedPnL: number
    • Optional realizedPnL: number

    Returns void

  • pnlSingle event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<PnLSingle>>
    • reqId: number
    • pos: number
    • dailyPnL: number
    • unrealizedPnL: number
    • realizedPnL: number
    • value: number

    Returns void

  • position event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableAccountPositions>>
    • account: string
    • contract: Contract
    • pos: number
    • Optional avgCost: number

    Returns void

  • position end enumeration event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableAccountPositions>>

    Returns void

  • Provides the data resulting from the market scanner request.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MarketScannerRows>>
    • reqId: number

      the request's identifier

    • rank: number

      the ranking within the response of this bar.

    • contract: ContractDetails

      the data's ContractDetails

    • distance: string

      according to query

    • benchmark: string

      according to query

    • projection: string

      according to query

    • legStr: string

      describes the combo legs when the scanner is returning EFP

    Returns void

    void

  • Indicates the scanner data reception has terminated.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MarketScannerRows>>
    • reqId: number

      the request's identifier

    Returns void

  • Parameters

    • subscriptions: Map<number, IBApiNextSubscription<string>>
    • xml: string

    Returns void

  • securityDefinitionOptionParameter event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<SecurityDefinitionOptionParameterType[]>>
    • reqId: number
    • exchange: string
    • underlyingConId: number
    • tradingClass: string
    • multiplier: string
    • expirations: string[]
    • strikes: number[]

    Returns void

  • tickPrice, tickSize and tickGeneric event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableMarketData>>
    • reqId: number
    • tickType: IBApiTickType
    • Optional value: number

    Returns void

  • tickOptionComputationHandler event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableMarketData>>
    • reqId: number
    • field: number
    • impliedVolatility: number
    • delta: number
    • optPrice: number
    • pvDividend: number
    • gamma: number
    • vega: number
    • theta: number
    • undPrice: number

    Returns void

  • tickSnapshotEnd event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<MutableMarketData>>
    • reqId: number

    Returns void

  • Response to API updateAccountTime control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<AccountUpdate>>
    • timeStamp: string

    Returns void

    See

    [[reqOpenOrders]]

  • Response to API updateAccountValue control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<AccountUpdate>>
    • tag: string
    • value: string
    • currency: string
    • account: string

    Returns void

    See

    [[reqOpenOrders]]

  • updateMktDepth event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OrderBook>>
    • reqId: number
    • position: number
    • operation: number
    • side: number
    • price: number
    • size: number

    Returns void

  • marketDepthL2 event handler

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<OrderBook>>
    • reqId: number
    • position: number
    • marketMaker: string
    • operation: number
    • side: number
    • price: number
    • size: number
    • isSmartDepth: boolean

    Returns void

  • Response to API updatePortfolio control message.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<AccountUpdate>>
    • contract: Contract
    • pos: number
    • marketPrice: number
    • marketValue: number
    • avgCost: number
    • unrealizedPNL: number
    • realizedPNL: number
    • account: string

    Returns void

    See

    [[reqOpenOrders]]

  • userInfo event handler.

    Parameters

    • subscriptions: Map<number, IBApiNextSubscription<string>>
    • reqId: number
    • whiteBrandingId: string

    Returns void

  • Places new order. This method does use the order id as returned by getNextValidOrderId() method and returns it as a result. If you want to send multiple orders, consider using placeOrder method instead and increase the order id manually for each new order, avoiding the overhead of calling getNextValidOrderId() for each.

    Parameters

    • contract: Contract

      The order's [[Contract]].

    • order: Order

      The [[Order]] object.

    Returns Promise<number>

    See

    [[getNextValidOrderId]]

  • Places or modifies an order.

    Parameters

    • id: number

      The order's unique identifier. Use a sequential id starting with the id received at the nextValidId method. If a new order is placed with an order ID less than or equal to the order ID of a previous order an error will occur.

    • contract: Contract

      The order's [[Contract]].

    • order: Order

      The [[Order]] object.

    Returns void

  • Switches data type returned from reqMktData request to "frozen", "delayed" or "delayed-frozen" market data. Requires TWS/IBG v963+.

    By default only real-time [[MarketDataType.REALTIME]] market data is enabled.

    The API can receive frozen market data from Trader Workstation. Frozen market data is the last data recorded in our system. During normal trading hours, the API receives real-time market data. Invoking this function with argument [[MarketDataType.FROZEN]] requests a switch to frozen data immediately or after the close. When the market reopens, the market data type will automatically switch back to real time if available.

    Parameters

    Returns void

Generated using TypeDoc