Create an [[IBApiNext]] object.
Optional
options: IBApiNextCreationOptionsCreation options.
Private
_nextPrivate
Readonly
apiThe [[IBApi]] with auto-reconnect.
Readonly
errorThe IBApi error [[Subject]].
All errors from [[IBApi]] error events will be sent to this subject.
please use getMarketDataSnapshot instead of getMarketDataSingle.
Readonly
loggerThe [[IBApiNextLogger]] instance.
use getMatchingSymbols instead
Private
Readonly
subscriptionsThe subscription registry.
Get an [[Observable]] for observing the connection-state.
Get an [[Observable]] to receive errors on IB API.
Errors that have a valid request id, will additionally be sent to the observers of the request.
Returns true if currently connected, false otherwise.
Connect to the TWS or IB Gateway.
Optional
clientId: numberA 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.
[[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
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.
A comma separated list with the desired tags:
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.
Optional
acctCode: stringthe specific account to retrieve.
[[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.
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.
[[reqAllOpenOrders]], [[reqOpenOrders]], [[cancelOrder]], [[reqGlobalCancel]]
Get commication reports details of all executed trades.
filter trade data on [[ExecutionFilter]]
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.
The contract used as sample to query the available contracts.
Get execution details of all executed trades.
filter trade data on [[ExecutionFilter]]
Get the timestamp of earliest available historical data for a contract and data type.
[[Contract]] object for which head timestamp is being requested.
Type of data for head timestamp - "BID", "ASK", "TRADES", etc
Use regular trading hours only, true
for yes or false
for no.
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.
Get data histogram of specified contract.
[[Contract]] object for which histogram is being requested
Use regular trading hours only, true
for yes or false
for no.
Period duration of which data is being requested
Duration unit of which data is being requested
Get a contracts historical data.
When requesting historical data, a finishing time and date is required along with a duration string. For example, having:
It is possible to specify a timezone optionally.
The contract for which we want to retrieve the data.
Request's ending time with format yyyyMMdd HH:mm:ss {TMZ}.
The amount of time for which the data needs to be retrieved:
the size of the bar:
the kind of information being retrieved:
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
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
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.
The contract for which we want to retrieve the data.
the size of the bar:
the kind of information being retrieved:
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
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.
[[Contract]] object that is subject of query
"20170701 12:01:00". Uses TWS timezone specified at login.
"20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
Number of distinct data points. Max currently 1000 per request.
Data from regular trading hours (1), or all available hours (0)
A filter only used when the source price is Bid_Ask
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.
[[Contract]] object that is subject of query
"20170701 12:01:00". Uses TWS timezone specified at login.
"20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
Number of distinct data points. Max 1000 per request.
Data from regular trading hours (1), or all available hours (0)
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.
[[Contract]] object that is subject of query
"20170701 12:01:00". Uses TWS timezone specified at login.
"20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
Number of distinct data points. Max currently 1000 per request.
Data from regular trading hours (1), or all available hours (0)
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 regulatorySnapshot
set to true
then you should consider using getMarketDataSingle
instead.
The [[Contract]] for which the data is being requested
comma separated ids of the available generic ticks:
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.
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.
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.
The [[Contract]] for which the data is being requested
comma separated ids of the generic ticks Look at getMarketData documentation for a list of available generic ticks.
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.
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.
Get venues for which market data is returned on getMarketDepthL2 (those with market makers).
It returns an observable that will emit a list of scanner subscriptions.
ScannerSubscription
Optional
scannerSubscriptionOptions: TagValue[]An array of TagValue objects.
Optional
scannerSubscriptionFilterOptions: TagValue[]An optional array of TagValue objects.
An observable that will emit a list of items.
Search contracts where name or symbol matches the given text pattern.
Either start of ticker symbol or (for larger strings) company name.
Requests all open orders placed by this specific API client (identified by the API client id). For client ID 0, this will bind previous manual TWS orders.
Create a subscription to receive real time updates for daily PnL of individual positions.
Account in which position exists.
Model in which position exists.
Contract ID (conId) of contract to receive daily PnL updates for.
Create subscription to receive the positions on all accessible accounts.
Requests security definition option parameters for viewing a contract's option chain.
This information will be emitted as securityDefinitionOptionParameter event.
The underlying symbol to query the available contracts.
The exchange on which the returned options are trading. Can be set to the empty string "" for all exchanges.
The type of the underlying security, i.e. STK.
the contract ID of the underlying security.
Private
insertPrivate
Readonly
onResponse to API accountDownloadEnd control message.
[[reqOpenOrders]]
Private
Readonly
onPrivate
Readonly
onPrivate
Readonly
oncomissionReport event handler.
Private
Readonly
oncontractDetails event handler
Private
Readonly
oncontractDetailsEnd event handler
Private
Readonly
onPrivate
Readonly
onEnds the subscrition once all trades are recieved
Contract details that is used for order
Execution details of an order
Private
Readonly
onEnds the subscrition once all trades are recieved
Private
onPrivate
Readonly
onhistogramData event handler
Private
Readonly
onhistoricalData event handler
Private
Readonly
onhistoricalDataUpdate event handler
Private
Readonly
onhistoricalTicks event handler
Private
Readonly
onhistoricalTicksBidAsk event handler
Private
Readonly
onhistoricalTicksLast event handler
Private
onPrivate
Readonly
onmktDepthExchanges event handler
Private
Readonly
onPrivate
Readonly
onFeeds in currently open orders.
[[placeOrder]], [[reqAllOpenOrders]], [[reqAutoOpenOrders]]
Private
Readonly
onEnds the subscription once all openOrders are recieved
Private
Readonly
onEnds the subscription once all openOrders are recieved
Private
Readonly
onResponse to API bind order control message.
[[reqOpenOrders]]
Private
Readonly
onResponse to API status order control message.
Optional
permId: numberOptional
parentId: numberOptional
lastFillPrice: numberOptional
clientId: numberOptional
whyHeld: stringOptional
mktCapPrice: number[[reqOpenOrders]]
Private
onpnl event handler.
Optional
unrealizedPnL: numberOptional
realizedPnL: numberPrivate
Readonly
onpnlSingle event handler.
Private
Readonly
onposition event handler
Optional
avgCost: numberPrivate
Readonly
onPrivate
Readonly
onProvides the data resulting from the market scanner request.
the request's identifier
the ranking within the response of this bar.
the data's ContractDetails
according to query
according to query
according to query
describes the combo legs when the scanner is returning EFP
void
Private
Readonly
onIndicates the scanner data reception has terminated.
the request's identifier
Private
Readonly
onPrivate
Readonly
onsecurityDefinitionOptionParameter event handler
Private
Readonly
onsecurityDefinitionOptionParameterEnd event handler
Private
Readonly
onsymbolSamples event handler.
Private
Readonly
ontickPrice, tickSize and tickGeneric event handler
Optional
value: numberPrivate
Readonly
ontickOptionComputationHandler event handler
Private
Readonly
onPrivate
Readonly
onResponse to API updateAccountTime control message.
[[reqOpenOrders]]
Private
Readonly
onResponse to API updateAccountValue control message.
[[reqOpenOrders]]
Private
Readonly
onupdateMktDepth event handler
Private
Readonly
onmarketDepthL2 event handler
Private
Readonly
onResponse to API updatePortfolio control message.
[[reqOpenOrders]]
Private
Readonly
onPlaces 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.
[[getNextValidOrderId]]
Places or modifies an order.
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.
The order's [[Contract]].
The [[Order]] object.
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.
The requested market data type.
Generated using TypeDoc
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.