• C#
  • Java
  • VB
  • C++
  • Python
Contact us
EClient Class Referenceabstract

TWS/Gateway client class This client class contains all the available methods to communicate with IB. Up to thirty-two clients can be connected to a single instance of the TWS/Gateway simultaneously. From herein, the TWS/Gateway will be referred to as the Host. More...

Inheritance diagram for EClient:
EClientSocket

Public Member Functions

 EClient (EWrapper wrapper)
 Constructor. More...
 
void SetConnectOptions (string connectOptions)
 Ignore. Used for IB's internal purposes.
 
void DisableUseV100Plus ()
 Allows to switch between different current (V100+) and previous connection mechanisms.
 
bool IsConnected ()
 Indicates whether the API-TWS connection has been closed. Note: This function is not automatically invoked and must be by the API client. More...
 
void startApi ()
 Initiates the message exchange between the client application and the TWS/IB Gateway.
 
void Close ()
 Terminates the connection and notifies the EWrapper implementing class. More...
 
virtual void eDisconnect (bool resetState=true)
 Closes the socket connection and terminates its thread.
 
void reqCompletedOrders (bool apiOnly)
 Requests completed orders.
. More...
 
void cancelTickByTickData (int requestId)
 Cancels tick-by-tick data.
. More...
 
void reqTickByTickData (int requestId, Contract contract, string tickType, int numberOfTicks, bool ignoreSize)
 Requests tick-by-tick data.
. More...
 
void cancelHistoricalData (int reqId)
 Cancels a historical data request. More...
 
void calculateImpliedVolatility (int reqId, Contract contract, double optionPrice, double underPrice, List< TagValue > impliedVolatilityOptions)
 Calculate the volatility for an option.
Request the calculation of the implied volatility based on hypothetical option and its underlying prices.
The calculation will be return in EWrapper's tickOptionComputation callback.
. More...
 
void calculateOptionPrice (int reqId, Contract contract, double volatility, double underPrice, List< TagValue > optionPriceOptions)
 Calculates an option's price based on the provided volatility and its underlying's price.
The calculation will be return in EWrapper's tickOptionComputation callback.
. More...
 
void cancelAccountSummary (int reqId)
 Cancels the account's summary request. After requesting an account's summary, invoke this function to cancel it. More...
 
void cancelCalculateImpliedVolatility (int reqId)
 Cancels an option's implied volatility calculation request. More...
 
void cancelCalculateOptionPrice (int reqId)
 Cancels an option's price calculation request. More...
 
void cancelFundamentalData (int reqId)
 Cancels Fundamental data request. More...
 
void cancelMktData (int tickerId)
 Cancels a RT Market Data request. More...
 
void cancelMktDepth (int tickerId, bool isSmartDepth)
 Cancel's market depth's request. More...
 
void cancelNewsBulletin ()
 Cancels IB's news bulletin subscription. More...
 
void cancelOrder (int orderId, string manualOrderCancelTime)
 Cancels an active order placed by from the same API client ID.
Note: API clients cannot cancel individual orders placed by other clients. Only reqGlobalCancel is available.
. More...
 
void cancelPositions ()
 Cancels a previous position subscription request made with reqPositions. More...
 
void cancelRealTimeBars (int tickerId)
 Cancels Real Time Bars' subscription. More...
 
void cancelScannerSubscription (int tickerId)
 Cancels Scanner Subscription. More...
 
void exerciseOptions (int tickerId, Contract contract, int exerciseAction, int exerciseQuantity, string account, int ovrd, string manualOrderTime)
 Exercises an options contract
Note: this function is affected by a TWS setting which specifies if an exercise request must be finalized. More...
 
void placeOrder (int id, Contract contract, Order order)
 Places or modifies an order. More...
 
void replaceFA (int reqId, int faDataType, string xml)
 Replaces Financial Advisor's settings A Financial Advisor can define three different configurations: More...
 
void requestFA (int faDataType)
 Requests the FA configuration A Financial Advisor can define three different configurations: More...
 
void reqAccountSummary (int reqId, string group, string tags)
 Requests a specific account's summary.
This method will subscribe to the account summary as presented in the TWS' Account Summary tab. The data is returned at EWrapper::accountSummary
https://www.interactivebrokers.com/en/software/tws/accountwindowtop.htm. More...
 
void reqAccountUpdates (bool subscribe, string acctCode)
 Subscribes to a specific account's information and portfolio. Through this method, a single account's subscription can be started/stopped. As a result from the subscription, the account's information, portfolio and last update time will be received at EWrapper::updateAccountValue, EWrapper::updateAccountPortfolio, EWrapper::updateAccountTime respectively. All account values and positions will be returned initially, and then there will only be updates when there is a change in a position, or to an account value every 3 minutes if it has changed. Only one account can be subscribed at a time. A second subscription request for another account when the previous one is still active will cause the first one to be canceled in favour of the second one. Consider user reqPositions if you want to retrieve all your accounts' portfolios directly. More...
 
void reqAllOpenOrders ()
 Requests all current open orders in associated accounts at the current moment. The existing orders will be received via the openOrder and orderStatus events. Open orders are returned once; this function does not initiate a subscription. More...
 
void reqAutoOpenOrders (bool autoBind)
 Requests status updates about future orders placed from TWS. Can only be used with client ID 0. More...
 
void reqContractDetails (int reqId, Contract contract)
 Requests contract information.
This method will provide all the contracts matching the contract provided. It can also be used to retrieve complete options and futures chains. This information will be returned at EWrapper:contractDetails. Though it is now (in API version > 9.72.12) advised to use reqSecDefOptParams for that purpose.
. More...
 
void reqCurrentTime ()
 Requests TWS's current time. More...
 
void reqExecutions (int reqId, ExecutionFilter filter)
 Requests current day's (since midnight) executions matching the filter. Only the current day's executions can be retrieved. Along with the executions, the CommissionReport will also be returned. The execution details will arrive at EWrapper:execDetails. More...
 
void reqFundamentalData (int reqId, Contract contract, string reportType, List< TagValue > fundamentalDataOptions)
 Legacy/DEPRECATED. Requests the contract's fundamental data. Fundamental data is returned at EWrapper::fundamentalData. More...
 
void reqGlobalCancel ()
 Cancels all active orders.
This method will cancel ALL open orders including those placed directly from TWS. More...
 
void reqHistoricalData (int tickerId, Contract contract, string endDateTime, string durationStr, string barSizeSetting, string whatToShow, int useRTH, int formatDate, bool keepUpToDate, List< TagValue > chartOptions)
 Requests contracts' historical data. When requesting historical data, a finishing time and date is required along with a duration string. For example, having: More...
 
void reqIds (int numIds)
 Requests the next valid order ID at the current moment. More...
 
void reqManagedAccts ()
 Requests the accounts to which the logged user has access to. More...
 
void reqMktData (int tickerId, Contract contract, string genericTickList, bool snapshot, bool regulatorySnaphsot, List< TagValue > mktDataOptions)
 Requests 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) More...
 
void reqMarketDataType (int marketDataType)
 Switches data type returned from reqMktData request to "frozen", "delayed" or "delayed-frozen" market data. Requires TWS/IBG v963+.
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 2 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. More...
 
void reqMarketDepth (int tickerId, Contract contract, int numRows, bool isSmartDepth, List< TagValue > mktDepthOptions)
 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. More...
 
void reqNewsBulletins (bool allMessages)
 Subscribes to IB's News Bulletins. More...
 
void reqOpenOrders ()
 Requests all open orders places by this specific API client (identified by the API client id). For client ID 0, this will bind previous manual TWS orders. More...
 
void reqPositions ()
 Subscribes to position updates for all accessible accounts. All positions sent initially, and then only updates as positions change. More...
 
void reqRealTimeBars (int tickerId, Contract contract, int barSize, string whatToShow, bool useRTH, List< TagValue > realTimeBarsOptions)
 Requests real time bars
Currently, only 5 seconds bars are provided. This request is subject to the same pacing as any historical data request: no more than 60 API queries in more than 600 seconds.
Real time bars subscriptions are also included in the calculation of the number of Level 1 market data subscriptions allowed in an account. More...
 
void reqScannerParameters ()
 Requests an XML list of scanner parameters valid in TWS.
Not all parameters are valid from API scanner. More...
 
void reqScannerSubscription (int reqId, ScannerSubscription subscription, List< TagValue > scannerSubscriptionOptions, List< TagValue > scannerSubscriptionFilterOptions)
 Starts a subscription to market scan results based on the provided parameters. More...
 
void reqScannerSubscription (int reqId, ScannerSubscription subscription, string scannerSubscriptionOptions, string scannerSubscriptionFilterOptions)
 
void setServerLogLevel (int logLevel)
 Changes the TWS/GW log level. The default is 2 = ERROR
5 = DETAIL is required for capturing all API messages and troubleshooting API programs
Valid values are:
1 = SYSTEM
2 = ERROR
3 = WARNING
4 = INFORMATION
5 = DETAIL
.
 
void verifyRequest (string apiName, string apiVersion)
 For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
 
void verifyMessage (string apiData)
 For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
 
void verifyAndAuthRequest (string apiName, string apiVersion, string opaqueIsvKey)
 For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
 
void verifyAndAuthMessage (string apiData, string xyzResponse)
 For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
 
void queryDisplayGroups (int requestId)
 Requests all available Display Groups in TWS. More...
 
void subscribeToGroupEvents (int requestId, int groupId)
 Integrates API client and TWS window grouping. More...
 
void updateDisplayGroup (int requestId, string contractInfo)
 Updates the contract displayed in a TWS Window Group. More...
 
void unsubscribeFromGroupEvents (int requestId)
 Cancels a TWS Window Group subscription.
 
void reqPositionsMulti (int requestId, string account, string modelCode)
 Requests position subscription for account and/or model Initially all positions are returned, and then updates are returned for any position changes in real time. More...
 
void cancelPositionsMulti (int requestId)
 Cancels positions request for account and/or model. More...
 
void reqAccountUpdatesMulti (int requestId, string account, string modelCode, bool ledgerAndNLV)
 Requests account updates for account and/or model. More...
 
void cancelAccountUpdatesMulti (int requestId)
 Cancels account updates request for account and/or model. More...
 
void reqSecDefOptParams (int reqId, string underlyingSymbol, string futFopExchange, string underlyingSecType, int underlyingConId)
 Requests security definition option parameters for viewing a contract's option chain. More...
 
void reqSoftDollarTiers (int reqId)
 Requests pre-defined Soft Dollar Tiers. This is only supported for registered professional advisors and hedge and mutual funds who have configured Soft Dollar Tiers in Account Management. Refer to: https://www.interactivebrokers.com/en/software/am/am/manageaccount/requestsoftdollars.htm?Highlight=soft%20dollar%20tier. More...
 
void reqFamilyCodes ()
 Requests family codes for an account, for instance if it is a FA, IBroker, or associated account. More...
 
void reqMatchingSymbols (int reqId, string pattern)
 Requests matching stock symbols. More...
 
void reqMktDepthExchanges ()
 Requests venues for which market data is returned to updateMktDepthL2 (those with market makers) More...
 
void reqSmartComponents (int reqId, string bboExchange)
 Returns the mapping of single letter codes to exchange names given the mapping identifier. More...
 
void reqNewsProviders ()
 Requests news providers which the user has subscribed to. More...
 
void reqNewsArticle (int requestId, string providerCode, string articleId, List< TagValue > newsArticleOptions)
 Requests news article body given articleId. More...
 
void reqHistoricalNews (int requestId, int conId, string providerCodes, string startDateTime, string endDateTime, int totalResults, List< TagValue > historicalNewsOptions)
 Requests historical news headlines. More...
 
void reqHeadTimestamp (int tickerId, Contract contract, string whatToShow, int useRTH, int formatDate)
 Returns the timestamp of earliest available historical data for a contract and data type. More...
 
void cancelHeadTimestamp (int tickerId)
 Cancels a pending reqHeadTimeStamp request
. More...
 
void reqHistogramData (int tickerId, Contract contract, bool useRTH, string period)
 Returns data histogram of specified contract
. More...
 
void cancelHistogramData (int tickerId)
 Cancels an active data histogram request. More...
 
void reqMarketRule (int marketRuleId)
 Requests details about a given market rule
The market rule for an instrument on a particular exchange provides details about how the minimum price increment changes with price
A list of market rule ids can be obtained by invoking reqContractDetails on a particular contract. The returned market rule ID list will provide the market rule ID for the instrument in the correspond valid exchange list in contractDetails.
. More...
 
void reqPnL (int reqId, string account, string modelCode)
 Creates subscription for real time daily PnL and unrealized PnL updates. More...
 
void cancelPnL (int reqId)
 cancels subscription for real time updated daily PnL params reqId
 
void reqPnLSingle (int reqId, string account, string modelCode, int conId)
 Requests real time updates for daily PnL of individual positions. More...
 
void cancelPnLSingle (int reqId)
 Cancels real time subscription for a positions daily PnL information. More...
 
void reqHistoricalTicks (int reqId, Contract contract, string startDateTime, string endDateTime, int numberOfTicks, string whatToShow, int useRth, bool ignoreSize, List< TagValue > miscOptions)
 Requests historical Time&Sales data for an instrument. More...
 
void reqWshMetaData (int reqId)
 Requests metadata from the WSH calendar. More...
 
void cancelWshMetaData (int reqId)
 Cancels pending request for WSH metadata. More...
 
void reqWshEventData (int reqId, WshEventData wshEventData)
 Requests event data from the wSH calendar. More...
 
void cancelWshEventData (int reqId)
 Cancels pending WSH event data request. More...
 
void reqUserInfo (int reqId)
 Requests user info. More...
 
bool IsDataAvailable ()
 
int ReadInt ()
 
byte[] ReadAtLeastNBytes (int msgSize)
 
byte[] ReadByteArray (int msgSize)
 

Public Attributes

EWrapper Wrapper => wrapper
 Reference to the EWrapper implementing object.
 
int ServerVersion => serverVersion
 returns the Host's version. Some of the API functionality might not be available in older Hosts and therefore it is essential to keep the TWS/Gateway as up to date as possible.
 

Protected Member Functions

abstract uint prepareBuffer (BinaryWriter paramsList)
 
void sendConnectRequest ()
 
bool CheckServerVersion (int requiredVersion)
 
bool CheckServerVersion (int requestId, int requiredVersion)
 
bool CheckServerVersion (int requiredVersion, string updatetail)
 
bool CheckServerVersion (int tickerId, int requiredVersion, string updatetail)
 
void CloseAndSend (BinaryWriter paramsList, uint lengthPos, CodeMsgPair error)
 
void CloseAndSend (int reqId, BinaryWriter paramsList, uint lengthPos, CodeMsgPair error)
 
abstract void CloseAndSend (BinaryWriter request, uint lengthPos)
 
bool CheckConnection ()
 
void ReportError (int reqId, CodeMsgPair error, string tail)
 
void ReportUpdateTWS (int reqId, string tail)
 
void ReportUpdateTWS (string tail)
 
void ReportError (int reqId, int code, string message)
 
void SendCancelRequest (OutgoingMessages msgType, int version, int reqId, CodeMsgPair errorMessage)
 
void SendCancelRequest (OutgoingMessages msgType, int version, CodeMsgPair errorMessage)
 
bool VerifyOrderContract (Contract contract, int id)
 
bool VerifyOrder (Order order, int id, bool isBagOrder)
 

Protected Attributes

int serverVersion
 
ETransport socketTransport
 
EWrapper wrapper
 
volatile bool isConnected
 
int clientId
 
bool extraAuth
 
bool useV100Plus = true
 
bool allowRedirect
 
Stream tcpStream
 

Properties

bool AllowRedirect [get, set]
 
string ServerTime [get, set]
 
string optionalCapabilities [get, set]
 
bool AsyncEConnect [get, set]
 

Detailed Description

TWS/Gateway client class This client class contains all the available methods to communicate with IB. Up to thirty-two clients can be connected to a single instance of the TWS/Gateway simultaneously. From herein, the TWS/Gateway will be referred to as the Host.

Constructor & Destructor Documentation

EClient ( EWrapper  wrapper)
inline

Constructor.

Parameters
wrapperEWrapper's implementing class instance. Every message being delivered by IB to the API client will be forwarded to the EWrapper's implementing class.
See Also
EWrapper

Member Function Documentation

void calculateImpliedVolatility ( int  reqId,
Contract  contract,
double  optionPrice,
double  underPrice,
List< TagValue impliedVolatilityOptions 
)
inline

Calculate the volatility for an option.
Request the calculation of the implied volatility based on hypothetical option and its underlying prices.
The calculation will be return in EWrapper's tickOptionComputation callback.
.

Parameters
reqIdunique identifier of the request.
contractthe option's contract for which the volatility wants to be calculated.
optionPricehypothetical option price.
underPricehypothetical option's underlying price.
See Also
EWrapper::tickOptionComputation, cancelCalculateImpliedVolatility, Contract
void calculateOptionPrice ( int  reqId,
Contract  contract,
double  volatility,
double  underPrice,
List< TagValue optionPriceOptions 
)
inline

Calculates an option's price based on the provided volatility and its underlying's price.
The calculation will be return in EWrapper's tickOptionComputation callback.
.

Parameters
reqIdrequest's unique identifier.
contractthe option's contract for which the price wants to be calculated.
volatilityhypothetical volatility.
underPricehypothetical underlying's price.
See Also
EWrapper::tickOptionComputation, cancelCalculateOptionPrice, Contract
void cancelAccountSummary ( int  reqId)
inline

Cancels the account's summary request. After requesting an account's summary, invoke this function to cancel it.

Parameters
reqIdthe identifier of the previously performed account request
See Also
reqAccountSummary
void cancelAccountUpdatesMulti ( int  requestId)
inline

Cancels account updates request for account and/or model.

Parameters
requestIdaccount subscription to cancel
See Also
reqAccountUpdatesMulti
void cancelCalculateImpliedVolatility ( int  reqId)
inline

Cancels an option's implied volatility calculation request.

Parameters
reqIdthe identifier of the implied volatility's calculation request.
See Also
calculateImpliedVolatility
void cancelCalculateOptionPrice ( int  reqId)
inline

Cancels an option's price calculation request.

Parameters
reqIdthe identifier of the option's price's calculation request.
See Also
calculateOptionPrice
void cancelFundamentalData ( int  reqId)
inline

Cancels Fundamental data request.

Parameters
reqIdthe request's identifier.
See Also
reqFundamentalData
void cancelHeadTimestamp ( int  tickerId)
inline

Cancels a pending reqHeadTimeStamp request
.

Parameters
tickerIdId of the request
void cancelHistogramData ( int  tickerId)
inline

Cancels an active data histogram request.

Parameters
tickerId- identifier specified in reqHistogramData request
See Also
reqHistogramData, histogramData
void cancelHistoricalData ( int  reqId)
inline

Cancels a historical data request.

Parameters
reqIdthe request's identifier.
See Also
reqHistoricalData
void cancelMktData ( int  tickerId)
inline

Cancels a RT Market Data request.

Parameters
tickerIdrequest's identifier
See Also
reqMktData
void cancelMktDepth ( int  tickerId,
bool  isSmartDepth 
)
inline

Cancel's market depth's request.

Parameters
tickerIdrequest's identifier.
See Also
reqMarketDepth
void cancelNewsBulletin ( )
inline

Cancels IB's news bulletin subscription.

See Also
reqNewsBulletins
void cancelOrder ( int  orderId,
string  manualOrderCancelTime 
)
inline

Cancels an active order placed by from the same API client ID.
Note: API clients cannot cancel individual orders placed by other clients. Only reqGlobalCancel is available.
.

Parameters
orderIdthe order's client id
See Also
placeOrder, reqGlobalCancel
void cancelPnLSingle ( int  reqId)
inline

Cancels real time subscription for a positions daily PnL information.

Parameters
reqId
void cancelPositions ( )
inline

Cancels a previous position subscription request made with reqPositions.

See Also
reqPositions
void cancelPositionsMulti ( int  requestId)
inline

Cancels positions request for account and/or model.

Parameters
requestId- the identifier of the request to be canceled.
See Also
reqPositionsMulti
void cancelRealTimeBars ( int  tickerId)
inline

Cancels Real Time Bars' subscription.

Parameters
tickerIdthe request's identifier.
See Also
reqRealTimeBars
void cancelScannerSubscription ( int  tickerId)
inline

Cancels Scanner Subscription.

Parameters
tickerIdthe subscription's unique identifier.
See Also
reqScannerSubscription, ScannerSubscription, reqScannerParameters
void cancelTickByTickData ( int  requestId)
inline

Cancels tick-by-tick data.
.

Parameters
reqId- unique identifier of the request.
void cancelWshEventData ( int  reqId)
inline

Cancels pending WSH event data request.

Parameters
reqId
void cancelWshMetaData ( int  reqId)
inline

Cancels pending request for WSH metadata.

Parameters
reqId
void Close ( )

Terminates the connection and notifies the EWrapper implementing class.

See Also
EWrapper::connectionClosed, eDisconnect
void exerciseOptions ( int  tickerId,
Contract  contract,
int  exerciseAction,
int  exerciseQuantity,
string  account,
int  ovrd,
string  manualOrderTime 
)
inline

Exercises an options contract
Note: this function is affected by a TWS setting which specifies if an exercise request must be finalized.

Parameters
tickerIdexercise request's identifier
contractthe option Contract to be exercised.
exerciseActionset to 1 to exercise the option, set to 2 to let the option lapse.
exerciseQuantitynumber of contracts to be exercised
accountdestination account
ovrdSpecifies whether your setting will override the system's natural action. For example, if your action is "exercise" and the option is not in-the-money, by natural action the option would not exercise. If you have override set to "yes" the natural action would be overridden and the out-of-the money option would be exercised. Set to 1 to override, set to 0 not to.
manualOrderTimeManual Order Time
bool IsConnected ( )

Indicates whether the API-TWS connection has been closed. Note: This function is not automatically invoked and must be by the API client.

Returns
true if connection has been established, false if it has not.
void placeOrder ( int  id,
Contract  contract,
Order  order 
)
inline

Places or modifies an order.

Parameters
idthe 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.
contractthe order's contract
orderthe order
See Also
EWrapper::nextValidId, reqAllOpenOrders, reqAutoOpenOrders, reqOpenOrders, cancelOrder, reqGlobalCancel, EWrapper::openOrder, EWrapper::orderStatus, Order, Contract
void queryDisplayGroups ( int  requestId)
inline

Requests all available Display Groups in TWS.

Parameters
requestIdis the ID of this request
void replaceFA ( int  reqId,
int  faDataType,
string  xml 
)
inline

Replaces Financial Advisor's settings A Financial Advisor can define three different configurations:

  1. Groups: offer traders a way to create a group of accounts and apply a single allocation method to all accounts in the group.
  2. Account Aliases: let you easily identify the accounts by meaningful names rather than account numbers. More information at https://www.interactivebrokers.com/en/?f=%2Fen%2Fsoftware%2Fpdfhighlights%2FPDF-AdvisorAllocations.php%3Fib_entity%3Dllc
    Parameters
    faDataTypethe configuration to change. Set to 1 or 3 as defined above.
    xmlthe xml-formatted configuration string
    See Also
    requestFA
void reqAccountSummary ( int  reqId,
string  group,
string  tags 
)
inline

Requests a specific account's summary.
This method will subscribe to the account summary as presented in the TWS' Account Summary tab. The data is returned at EWrapper::accountSummary
https://www.interactivebrokers.com/en/software/tws/accountwindowtop.htm.

Parameters
reqIdthe unique request identifier.
groupset 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.
tagsa 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
  • PreviousEquityWithLoanValue — 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.
See Also
cancelAccountSummary, EWrapper::accountSummary, EWrapper::accountSummaryEnd
void reqAccountUpdates ( bool  subscribe,
string  acctCode 
)
inline

Subscribes to a specific account's information and portfolio. Through this method, a single account's subscription can be started/stopped. As a result from the subscription, the account's information, portfolio and last update time will be received at EWrapper::updateAccountValue, EWrapper::updateAccountPortfolio, EWrapper::updateAccountTime respectively. All account values and positions will be returned initially, and then there will only be updates when there is a change in a position, or to an account value every 3 minutes if it has changed. Only one account can be subscribed at a time. A second subscription request for another account when the previous one is still active will cause the first one to be canceled in favour of the second one. Consider user reqPositions if you want to retrieve all your accounts' portfolios directly.

Parameters
subscribeset to true to start the subscription and to false to stop it.
acctCodethe account id (i.e. U123456) for which the information is requested.
See Also
reqPositions, EWrapper::updateAccountValue, EWrapper::updatePortfolio, EWrapper::updateAccountTime
void reqAccountUpdatesMulti ( int  requestId,
string  account,
string  modelCode,
bool  ledgerAndNLV 
)
inline

Requests account updates for account and/or model.

Parameters
reqIdidentifier to label the request
accountaccount values can be requested for a particular account
modelCodevalues can also be requested for a model
ledgerAndNLVreturns light-weight request; only currency positions as opposed to account values and currency positions
See Also
cancelAccountUpdatesMulti, EWrapper::accountUpdateMulti, EWrapper::accountUpdateMultiEnd
void reqAllOpenOrders ( )
inline

Requests all current open orders in associated accounts at the current moment. The existing orders will be received via the openOrder and orderStatus events. Open orders are returned once; this function does not initiate a subscription.

See Also
reqAutoOpenOrders, reqOpenOrders, EWrapper::openOrder, EWrapper::orderStatus, EWrapper::openOrderEnd
void reqAutoOpenOrders ( bool  autoBind)
inline

Requests status updates about future orders placed from TWS. Can only be used with client ID 0.

Parameters
autoBindif 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.
See Also
reqAllOpenOrders, reqOpenOrders, cancelOrder, reqGlobalCancel, EWrapper::openOrder, EWrapper::orderStatus
void reqCompletedOrders ( bool  apiOnly)
inline

Requests completed orders.
.

Parameters
apiOnly- request only API orders.
See Also
EWrapper::completedOrder, EWrapper::completedOrdersEnd
void reqContractDetails ( int  reqId,
Contract  contract 
)
inline

Requests contract information.
This method will provide all the contracts matching the contract provided. It can also be used to retrieve complete options and futures chains. This information will be returned at EWrapper:contractDetails. Though it is now (in API version > 9.72.12) advised to use reqSecDefOptParams for that purpose.
.

Parameters
reqIdthe unique request identifier.
contractthe contract used as sample to query the available contracts. Typically, it will contain the Contract::Symbol, Contract::Currency, Contract::SecType, Contract::Exchange
See Also
EWrapper::contractDetails, EWrapper::contractDetailsEnd
void reqCurrentTime ( )
inline

Requests TWS's current time.

See Also
EWrapper::currentTime
void reqExecutions ( int  reqId,
ExecutionFilter  filter 
)
inline

Requests current day's (since midnight) executions matching the filter. Only the current day's executions can be retrieved. Along with the executions, the CommissionReport will also be returned. The execution details will arrive at EWrapper:execDetails.

Parameters
reqIdthe request's unique identifier.
filterthe filter criteria used to determine which execution reports are returned.
See Also
EWrapper::execDetails, EWrapper::commissionReport, ExecutionFilter
void reqFamilyCodes ( )
inline

Requests family codes for an account, for instance if it is a FA, IBroker, or associated account.

See Also
EWrapper::familyCodes
void reqFundamentalData ( int  reqId,
Contract  contract,
string  reportType,
List< TagValue fundamentalDataOptions 
)
inline

Legacy/DEPRECATED. Requests the contract's fundamental data. Fundamental data is returned at EWrapper::fundamentalData.

Parameters
reqIdthe request's unique identifier.
contractthe contract's description for which the data will be returned.
reportTypethere are three available report types:
  • ReportSnapshot: Company overview
  • ReportsFinSummary: Financial summary
  • ReportRatios: Financial ratios
  • ReportsFinStatements: Financial statements
  • RESC: Analyst estimates
See Also
EWrapper::fundamentalData
void reqGlobalCancel ( )
inline

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

See Also
cancelOrder
void reqHeadTimestamp ( int  tickerId,
Contract  contract,
string  whatToShow,
int  useRTH,
int  formatDate 
)
inline

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

Parameters
tickerId- an identifier for the request
contract- contract object for which head timestamp is being requested
whatToShow- type of data for head timestamp - "BID", "ASK", "TRADES", etc
useRTH- use regular trading hours only, 1 for yes or 0 for no
formatDate-
formatDateset to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds
See Also
headTimeStamp
void reqHistogramData ( int  tickerId,
Contract  contract,
bool  useRTH,
string  period 
)
inline

Returns data histogram of specified contract
.

Parameters
tickerId- an identifier for the request
contract- Contract object for which histogram is being requested
useRTH- use regular trading hours only, 1 for yes or 0 for no
period- period of which data is being requested, e.g. "3 days"
See Also
histogramData
void reqHistoricalData ( int  tickerId,
Contract  contract,
string  endDateTime,
string  durationStr,
string  barSizeSetting,
string  whatToShow,
int  useRTH,
int  formatDate,
bool  keepUpToDate,
List< TagValue chartOptions 
)
inline

Requests 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. The resulting bars will be returned in EWrapper::historicalData

Parameters
tickerIdthe request's unique identifier.
contractthe contract for which we want to retrieve the data.
endDateTimerequest's ending time with format yyyyMMdd HH:mm:ss {TMZ}
durationStrthe amount of time for which the data needs to be retrieved:
  • " S (seconds) - " D (days)
  • " W (weeks) - " M (months)
  • " Y (years)
barSizeSettingthe size of the bar:
  • 1 sec
  • 5 secs
  • 15 secs
  • 30 secs
  • 1 min
  • 2 mins
  • 3 mins
  • 5 mins
  • 15 mins
  • 30 mins
  • 1 hour
  • 1 day
whatToShowthe kind of information being retrieved:
  • TRADES
  • MIDPOINT
  • BID
  • ASK
  • BID_ASK
  • HISTORICAL_VOLATILITY
  • OPTION_IMPLIED_VOLATILITY
  • FEE_RATE
  • SCHEDULE
useRTHset 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
formatDateset to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds
keepUpToDateset to True to received continuous updates on most recent bar data. If True, and endDateTime cannot be specified.
See Also
EWrapper::historicalData
void reqHistoricalNews ( int  requestId,
int  conId,
string  providerCodes,
string  startDateTime,
string  endDateTime,
int  totalResults,
List< TagValue historicalNewsOptions 
)
inline

Requests historical news headlines.

Parameters
requestId
conId- contract id of ticker
providerCodes- a '+'-separated list of provider codes
startDateTime- marks the (exclusive) start of the date range. The format is yyyy-MM-dd HH:mm:ss.0
endDateTime- marks the (inclusive) end of the date range. The format is yyyy-MM-dd HH:mm:ss.0
totalResults- the maximum number of headlines to fetch (1 - 300)
historicalNewsOptionsreserved for internal use. Should be defined as null.
See Also
EWrapper::historicalNews, EWrapper::historicalNewsEnd
void reqHistoricalTicks ( int  reqId,
Contract  contract,
string  startDateTime,
string  endDateTime,
int  numberOfTicks,
string  whatToShow,
int  useRth,
bool  ignoreSize,
List< TagValue miscOptions 
)
inline

Requests historical Time&Sales data for an instrument.

Parameters
reqIdid of the request
contractContract object that is subject of query
startDateTime,i.e."20170701 12:01:00". Uses TWS timezone specified at login.
endDateTime,i.e."20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
numberOfTicksNumber of distinct data points. Max currently 1000 per request.
whatToShow(Bid_Ask, Midpoint, Trades) Type of data requested.
useRthData from regular trading hours (1), or all available hours (0)
ignoreSizeA filter only used when the source price is Bid_Ask
miscOptionsshould be defined as null, reserved for internal use
void reqIds ( int  numIds)
inline

Requests the next valid order ID at the current moment.

Parameters
numIdsdeprecated- this parameter will not affect the value returned to nextValidId
See Also
EWrapper::nextValidId
void reqManagedAccts ( )
inline

Requests the accounts to which the logged user has access to.

See Also
EWrapper::managedAccounts
void reqMarketDataType ( int  marketDataType)
inline

Switches data type returned from reqMktData request to "frozen", "delayed" or "delayed-frozen" market data. Requires TWS/IBG v963+.
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 2 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
marketDataType,:by default only real-time (1) market data is enabled sending 1 (real-time) disables frozen, delayed and delayed-frozen market data sending 2 (frozen) enables frozen market data sending 3 (delayed) enables delayed and disables delayed-frozen market data sending 4 (delayed-frozen) enables delayed and delayed-frozen market data
void reqMarketDepth ( int  tickerId,
Contract  contract,
int  numRows,
bool  isSmartDepth,
List< TagValue mktDepthOptions 
)
inline

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
tickerIdthe request's identifier
contractthe Contract for which the depth is being requested
numRowsthe number of rows on each side of the order book
isSmartDepthflag indicates that this is smart depth request
See Also
cancelMktDepth, EWrapper::updateMktDepth, EWrapper::updateMktDepthL2
void reqMarketRule ( int  marketRuleId)
inline

Requests details about a given market rule
The market rule for an instrument on a particular exchange provides details about how the minimum price increment changes with price
A list of market rule ids can be obtained by invoking reqContractDetails on a particular contract. The returned market rule ID list will provide the market rule ID for the instrument in the correspond valid exchange list in contractDetails.
.

Parameters
marketRuleId- the id of market rule
See Also
EWrapper::marketRule
void reqMatchingSymbols ( int  reqId,
string  pattern 
)
inline

Requests matching stock symbols.

Parameters
reqIdid to specify the request
pattern- either start of ticker symbol or (for larger strings) company name
See Also
EWrapper::symbolSamples
void reqMktData ( int  tickerId,
Contract  contract,
string  genericTickList,
bool  snapshot,
bool  regulatorySnaphsot,
List< TagValue mktDataOptions 
)
inline

Requests 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)

Parameters
tickerIdthe request's identifier
contractthe Contract for which the data is being requested
genericTickListcomma 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
snapshotfor users with corresponding real time market data subscriptions. A true value will return a one-time snapshot, while a false value will provide streaming data.
regulatorysnapshot 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.
See Also
cancelMktData, EWrapper::tickPrice, EWrapper::tickSize, EWrapper::tickString, EWrapper::tickEFP, EWrapper::tickGeneric, EWrapper::tickOptionComputation, EWrapper::tickSnapshotEnd
void reqMktDepthExchanges ( )
inline

Requests venues for which market data is returned to updateMktDepthL2 (those with market makers)

See Also
EWrapper::mktDepthExchanges
void reqNewsArticle ( int  requestId,
string  providerCode,
string  articleId,
List< TagValue newsArticleOptions 
)
inline

Requests news article body given articleId.

Parameters
requestIdid of the request
providerCodeshort code indicating news provider, e.g. FLY
articleIdid of the specific article
newsArticleOptionsreserved for internal use. Should be defined as null.
See Also
EWrapper::newsArticle,
void reqNewsBulletins ( bool  allMessages)
inline

Subscribes to IB's News Bulletins.

Parameters
allMessagesif set to true, will return all the existing bulletins for the current day, set to false to receive only the new bulletins.
See Also
cancelNewsBulletin, EWrapper::updateNewsBulletin
void reqNewsProviders ( )
inline

Requests news providers which the user has subscribed to.

See Also
EWrapper::newsProviders
void reqOpenOrders ( )
inline

Requests all open orders places by this specific API client (identified by the API client id). For client ID 0, this will bind previous manual TWS orders.

See Also
reqAllOpenOrders, reqAutoOpenOrders, placeOrder, cancelOrder, reqGlobalCancel, EWrapper::openOrder, EWrapper::orderStatus, EWrapper::openOrderEnd
void reqPnL ( int  reqId,
string  account,
string  modelCode 
)
inline

Creates subscription for real time daily PnL and unrealized PnL updates.

Parameters
accountaccount for which to receive PnL updates
modelCodespecify to request PnL updates for a specific model
void reqPnLSingle ( int  reqId,
string  account,
string  modelCode,
int  conId 
)
inline

Requests real time updates for daily PnL of individual positions.

Parameters
reqId
accountaccount in which position exists
modelCodemodel in which position exists
conIdcontract ID (conId) of contract to receive daily PnL updates for. Note: does not return message if invalid conId is entered
void reqPositions ( )
inline

Subscribes to position updates for all accessible accounts. All positions sent initially, and then only updates as positions change.

See Also
cancelPositions, EWrapper::position, EWrapper::positionEnd
void reqPositionsMulti ( int  requestId,
string  account,
string  modelCode 
)
inline

Requests position subscription for account and/or model Initially all positions are returned, and then updates are returned for any position changes in real time.

Parameters
requestId- Request's identifier
account- If an account Id is provided, only the account's positions belonging to the specified model will be delivered
modelCode- The code of the model's positions we are interested in.
See Also
cancelPositionsMulti, EWrapper::positionMulti, EWrapper::positionMultiEnd
void reqRealTimeBars ( int  tickerId,
Contract  contract,
int  barSize,
string  whatToShow,
bool  useRTH,
List< TagValue realTimeBarsOptions 
)
inline

Requests real time bars
Currently, only 5 seconds bars are provided. This request is subject to the same pacing as any historical data request: no more than 60 API queries in more than 600 seconds.
Real time bars subscriptions are also included in the calculation of the number of Level 1 market data subscriptions allowed in an account.

Parameters
tickerIdthe request's unique identifier.
contractthe Contract for which the depth is being requested
barSizecurrently being ignored
whatToShowthe nature of the data being retrieved:
  • TRADES
  • MIDPOINT
  • BID
  • ASK
useRTHset to 0 to obtain the data which was also generated ourside of the Regular Trading Hours, set to 1 to obtain only the RTH data
See Also
cancelRealTimeBars, EWrapper::realtimeBar
void reqScannerParameters ( )
inline

Requests an XML list of scanner parameters valid in TWS.
Not all parameters are valid from API scanner.

See Also
reqScannerSubscription
void reqScannerSubscription ( int  reqId,
ScannerSubscription  subscription,
List< TagValue scannerSubscriptionOptions,
List< TagValue scannerSubscriptionFilterOptions 
)

Starts a subscription to market scan results based on the provided parameters.

Parameters
reqIdthe request's identifier
subscriptionsummary of the scanner subscription including its filters.
See Also
reqScannerParameters, ScannerSubscription, EWrapper::scannerData
void reqSecDefOptParams ( int  reqId,
string  underlyingSymbol,
string  futFopExchange,
string  underlyingSecType,
int  underlyingConId 
)
inline

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

Parameters
reqIdthe ID chosen for the request
underlyingSymbol
futFopExchangeThe exchange on which the returned options are trading. Can be set to the empty string "" for all exchanges.
underlyingSecTypeThe type of the underlying security, i.e. STK
underlyingConIdthe contract ID of the underlying security
See Also
EWrapper::securityDefinitionOptionParameter
void reqSmartComponents ( int  reqId,
string  bboExchange 
)
inline

Returns the mapping of single letter codes to exchange names given the mapping identifier.

Parameters
reqIdid of the request
bboExchangemapping identifier received from EWrapper.tickReqParams
See Also
EWrapper::smartComponents
void reqSoftDollarTiers ( int  reqId)
inline

Requests pre-defined Soft Dollar Tiers. This is only supported for registered professional advisors and hedge and mutual funds who have configured Soft Dollar Tiers in Account Management. Refer to: https://www.interactivebrokers.com/en/software/am/am/manageaccount/requestsoftdollars.htm?Highlight=soft%20dollar%20tier.

See Also
EWrapper::softDollarTiers
void reqTickByTickData ( int  requestId,
Contract  contract,
string  tickType,
int  numberOfTicks,
bool  ignoreSize 
)
inline

Requests tick-by-tick data.
.

Parameters
reqId- unique identifier of the request.
contract- the contract for which tick-by-tick data is requested.
tickType- tick-by-tick data type: "Last", "AllLast", "BidAsk" or "MidPoint".
numberOfTicks- number of ticks.
ignoreSize- ignore size flag.
See Also
EWrapper::tickByTickAllLast, EWrapper::tickByTickBidAsk, EWrapper::tickByTickMidPoint, Contract
void requestFA ( int  faDataType)
inline

Requests the FA configuration A Financial Advisor can define three different configurations:

 1. Groups: offer traders a way to create a group of accounts and apply a single allocation method to all accounts in the group.
 3. Account Aliases: let you easily identify the accounts by meaningful names rather than account numbers.

More information at https://www.interactivebrokers.com/en/?f=%2Fen%2Fsoftware%2Fpdfhighlights%2FPDF-AdvisorAllocations.php%3Fib_entity%3Dllc

Parameters
faDataTypethe configuration to change. Set to 1 or 3 as defined above.
See Also
replaceFA
void reqUserInfo ( int  reqId)
inline

Requests user info.

Parameters
reqId
void reqWshEventData ( int  reqId,
WshEventData  wshEventData 
)
inline

Requests event data from the wSH calendar.

Parameters
reqId
conIdcontract ID (conId) of contract to receive WSH Event Data for.
void reqWshMetaData ( int  reqId)
inline

Requests metadata from the WSH calendar.

Parameters
reqId
void subscribeToGroupEvents ( int  requestId,
int  groupId 
)
inline

Integrates API client and TWS window grouping.

Parameters
requestIdis the Id chosen for this subscription request
groupIdis the display group for integration
void updateDisplayGroup ( int  requestId,
string  contractInfo 
)
inline

Updates the contract displayed in a TWS Window Group.

Parameters
requestIdis the ID chosen for this request
contractInfois an encoded value designating a unique IB contract. Possible values include:
  1. none = empty selection
  2. contractID - any non-combination contract. Examples 8314 for IBM SMART; 8314 for IBM ARCA
  3. combo= if any combo is selected Note: This request from the API does not get a TWS response unless an error occurs.