Q26 ALPHA-TRADING SYSTEM
|
Public Member Functions | |
def | __init__ (self, wrapper) |
def | reset (self) |
def | setConnState (self, connState) |
def | sendMsg (self, msg) |
def | logRequest (self, fnName, fnParams) |
def | startApi (self) |
def | connect (self, host, port, clientId) |
def | disconnect (self) |
def | isConnected (self) |
def | keyboardInterrupt (self) |
def | keyboardInterruptHard (self) |
def | run (self) |
def | reqCurrentTime (self) |
def | serverVersion (self) |
def | setServerLogLevel (self, int logLevel) |
def | twsConnectionTime (self) |
def | reqMktData (self, TickerId reqId, Contract contract, str genericTickList, bool snapshot, bool regulatorySnapshot, TagValueList mktDataOptions) |
Market Data. More... | |
def | cancelMktData (self, TickerId reqId) |
def | reqMarketDataType (self, int marketDataType) |
def | reqSmartComponents (self, int reqId, str bboExchange) |
def | reqMarketRule (self, int marketRuleId) |
def | reqTickByTickData (self, int reqId, Contract contract, str tickType, int numberOfTicks, bool ignoreSize) |
def | cancelTickByTickData (self, int reqId) |
def | calculateImpliedVolatility (self, TickerId reqId, Contract contract, float optionPrice, float underPrice, TagValueList implVolOptions) |
Options. More... | |
def | cancelCalculateImpliedVolatility (self, TickerId reqId) |
def | calculateOptionPrice (self, TickerId reqId, Contract contract, float volatility, float underPrice, TagValueList optPrcOptions) |
def | cancelCalculateOptionPrice (self, TickerId reqId) |
def | exerciseOptions (self, TickerId reqId, Contract contract, int exerciseAction, int exerciseQuantity, str account, int override) |
def | placeOrder (self, OrderId orderId, Contract contract, Order order) |
Orders. More... | |
def | cancelOrder (self, OrderId orderId) |
def | reqOpenOrders (self) |
def | reqAutoOpenOrders (self, bool bAutoBind) |
def | reqAllOpenOrders (self) |
def | reqGlobalCancel (self) |
def | reqIds (self, int numIds) |
def | reqAccountUpdates (self, bool subscribe, str acctCode) |
Account and Portfolio. More... | |
def | reqAccountSummary (self, int reqId, str groupName, str tags) |
def | cancelAccountSummary (self, int reqId) |
def | reqPositions (self) |
def | cancelPositions (self) |
def | reqPositionsMulti (self, int reqId, str account, str modelCode) |
def | cancelPositionsMulti (self, int reqId) |
def | reqAccountUpdatesMulti (self, int reqId, str account, str modelCode, bool ledgerAndNLV) |
def | cancelAccountUpdatesMulti (self, int reqId) |
def | reqPnL (self, int reqId, str account, str modelCode) |
Daily PnL. | |
def | cancelPnL (self, int reqId) |
def | reqPnLSingle (self, int reqId, str account, str modelCode, int conid) |
def | cancelPnLSingle (self, int reqId) |
def | reqExecutions (self, int reqId, ExecutionFilter execFilter) |
Executions. More... | |
def | reqContractDetails (self, int reqId, Contract contract) |
Contract Details. More... | |
def | reqMktDepthExchanges (self) |
Market Depth. | |
def | reqMktDepth (self, TickerId reqId, Contract contract, int numRows, bool isSmartDepth, TagValueList mktDepthOptions) |
def | cancelMktDepth (self, TickerId reqId, bool isSmartDepth) |
def | reqNewsBulletins (self, bool allMsgs) |
News Bulletins. More... | |
def | cancelNewsBulletins (self) |
def | reqManagedAccts (self) |
Financial Advisors. More... | |
def | requestFA (self, FaDataType faData) |
def | replaceFA (self, FaDataType faData, str cxml) |
def | reqHistoricalData (self, TickerId reqId, Contract contract, str endDateTime, str durationStr, str barSizeSetting, str whatToShow, int useRTH, int formatDate, bool keepUpToDate, TagValueList chartOptions) |
Historical Data. More... | |
def | cancelHistoricalData (self, TickerId reqId) |
def | reqHeadTimeStamp (self, TickerId reqId, Contract contract, str whatToShow, int useRTH, int formatDate) |
def | cancelHeadTimeStamp (self, TickerId reqId) |
def | reqHistogramData (self, int tickerId, Contract contract, bool useRTH, str timePeriod) |
def | cancelHistogramData (self, int tickerId) |
def | reqHistoricalTicks (self, int reqId, Contract contract, str startDateTime, str endDateTime, int numberOfTicks, str whatToShow, int useRth, bool ignoreSize, TagValueList miscOptions) |
def | reqScannerParameters (self) |
Market Scanners. More... | |
def | reqScannerSubscription (self, int reqId, ScannerSubscription subscription, TagValueList scannerSubscriptionOptions, TagValueList scannerSubscriptionFilterOptions) |
def | cancelScannerSubscription (self, int reqId) |
def | reqRealTimeBars (self, TickerId reqId, Contract contract, int barSize, str whatToShow, bool useRTH, TagValueList realTimeBarsOptions) |
Real Time Bars. More... | |
def | cancelRealTimeBars (self, TickerId reqId) |
def | reqFundamentalData (self, TickerId reqId, Contract contract, str reportType, TagValueList fundamentalDataOptions) |
Fundamental Data. More... | |
def | cancelFundamentalData (self, TickerId reqId) |
def | reqNewsProviders (self) |
News. | |
def | reqNewsArticle (self, int reqId, str providerCode, str articleId, TagValueList newsArticleOptions) |
def | reqHistoricalNews (self, int reqId, int conId, str providerCodes, str startDateTime, str endDateTime, int totalResults, TagValueList historicalNewsOptions) |
def | queryDisplayGroups (self, int reqId) |
Display Groups. More... | |
def | subscribeToGroupEvents (self, int reqId, int groupId) |
def | updateDisplayGroup (self, int reqId, str contractInfo) |
def | unsubscribeFromGroupEvents (self, int reqId) |
def | verifyRequest (self, str apiName, str apiVersion) |
def | verifyMessage (self, str apiData) |
def | verifyAndAuthRequest (self, str apiName, str apiVersion, str opaqueIsvKey) |
def | verifyAndAuthMessage (self, str apiData, str xyzResponse) |
def | reqSecDefOptParams (self, int reqId, str underlyingSymbol, str futFopExchange, str underlyingSecType, int underlyingConId) |
def | reqSoftDollarTiers (self, int reqId) |
def | reqFamilyCodes (self) |
def | reqMatchingSymbols (self, int reqId, str pattern) |
def | reqCompletedOrders (self, bool apiOnly) |
Public Attributes | |
msg_queue | |
wrapper | |
decoder | |
done | |
nKeybIntHard | |
conn | |
host | |
port | |
extraAuth | |
clientId | |
serverVersion_ | |
connTime | |
connState | |
optCapab | |
asynchronous | |
reader | |
decode | |
Static Public Attributes | |
DISCONNECTED | |
CONNECTING | |
CONNECTED | |
REDIRECT | |
def calculateImpliedVolatility | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
float | optionPrice, | ||
float | underPrice, | ||
TagValueList | implVolOptions | ||
) |
Options.
Call this function to calculate volatility for a supplied option price and underlying price. Result will be delivered via EWrapper.tickOptionComputation() reqId:TickerId - The request id. contract:Contract - Describes the contract. optionPrice:double - The price of the option. underPrice:double - Price of the underlying.
def calculateOptionPrice | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
float | volatility, | ||
float | underPrice, | ||
TagValueList | optPrcOptions | ||
) |
Call this function to calculate option price and greek values for a supplied volatility and underlying price. reqId:TickerId - The ticker ID. contract:Contract - Describes the contract. volatility:double - The volatility. underPrice:double - Price of the underlying.
def cancelAccountSummary | ( | self, | |
int | reqId | ||
) |
Cancels the request for Account Window Summary tab data. reqId:int - The ID of the data request being canceled.
def cancelCalculateImpliedVolatility | ( | self, | |
TickerId | reqId | ||
) |
Call this function to cancel a request to calculate volatility for a supplied option price and underlying price. reqId:TickerId - The request ID.
def cancelCalculateOptionPrice | ( | self, | |
TickerId | reqId | ||
) |
Call this function to cancel a request to calculate the option price and greek values for a supplied volatility and underlying price. reqId:TickerId - The request ID.
def cancelFundamentalData | ( | self, | |
TickerId | reqId | ||
) |
Call this function to stop receiving fundamental data. reqId:TickerId - The ID of the data request.
def cancelHistoricalData | ( | self, | |
TickerId | reqId | ||
) |
Used if an internet disconnect has occurred or the results of a query are otherwise delayed and the application is no longer interested in receiving the data. reqId:TickerId - The ticker ID. Must be a unique value.
def cancelMktData | ( | self, | |
TickerId | reqId | ||
) |
After calling this function, market data for the specified id will stop flowing. reqId: TickerId - The ID that was specified in the call to reqMktData().
def cancelMktDepth | ( | self, | |
TickerId | reqId, | ||
bool | isSmartDepth | ||
) |
After calling this function, market depth data for the specified id will stop flowing. reqId:TickerId - The ID that was specified in the call to reqMktDepth(). isSmartDepth:bool - specifies SMART depth request
def cancelNewsBulletins | ( | self | ) |
Call this function to stop receiving news bulletins.
def cancelOrder | ( | self, | |
OrderId | orderId | ||
) |
Call this function to cancel an order. orderId:OrderId - The order ID that was specified previously in the call to placeOrder()
def cancelPositions | ( | self | ) |
Cancels real-time position updates.
def cancelRealTimeBars | ( | self, | |
TickerId | reqId | ||
) |
Call the cancelRealTimeBars() function to stop receiving real time bar results. reqId:TickerId - The Id that was specified in the call to reqRealTimeBars().
def cancelScannerSubscription | ( | self, | |
int | reqId | ||
) |
reqId:int - The ticker ID. Must be a unique value.
def connect | ( | self, | |
host, | |||
port, | |||
clientId | |||
) |
This function must be called before any other. There is no feedback for a successful connection, but a subsequent attempt to connect will return the message \"Already connected.\" host:str - The host name or IP address of the machine where TWS is running. Leave blank to connect to the local host. port:int - Must match the port specified in TWS on the Configure>API>Socket Port field. clientId:int - A number used to identify this client connection. All orders placed/modified from this client will be associated with this client identifier. Note: Each client MUST connect with a unique clientId.
def disconnect | ( | self | ) |
Call this function to terminate the connections with TWS. Calling this function does not cancel orders that have already been sent.
def exerciseOptions | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
int | exerciseAction, | ||
int | exerciseQuantity, | ||
str | account, | ||
int | override | ||
) |
reqId:TickerId - The ticker id. multipleust be a unique value. contract:Contract - This structure contains a description of the contract to be exercised exerciseAction:int - Specifies whether you want the option to lapse or be exercised. Values are 1 = exercise, 2 = lapse. exerciseQuantity:int - The quantity you want to exercise. account:str - destination account override:int - Specifies 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. Values are: 0 = no, 1 = yes.
def isConnected | ( | self | ) |
Call this function to check if there is a connection with TWS
Orders.
Call this function to place an order. The order status will be returned by the orderStatus event. orderId:OrderId - The order id. You must specify a unique value. When the order START_APItus returns, it will be identified by this tag. This tag is also used when canceling the order. contract:Contract - This structure contains a description of the contract which is being traded. order:Order - This structure contains the details of tradedhe order. Note: Each client MUST connect with a unique clientId.
def queryDisplayGroups | ( | self, | |
int | reqId | ||
) |
Display Groups.
API requests used to integrate with TWS color-grouped windows (display groups). TWS color-grouped windows are identified by an integer number. Currently that number ranges from 1 to 7 and are mapped to specific colors, as indicated in TWS. reqId:int - The unique number that will be associated with the response
def replaceFA | ( | self, | |
FaDataType | faData, | ||
str | cxml | ||
) |
Call this function to modify FA configuration information from the API. Note that this can also be done manually in TWS itself. faData:FaDataType - Specifies the type of Financial Advisor configuration data beingingg requested. Valid values include: 1 = GROUPS 2 = PROFILE 3 = ACCOUNT ALIASES cxml: str - The XML string containing the new FA configuration information.
def reqAccountSummary | ( | self, | |
int | reqId, | ||
str | groupName, | ||
str | tags | ||
) |
Call this method to request and keep up to date the data that appears on the TWS Account Window Summary tab. The data is returned by accountSummary(). Note: This request is designed for an FA managed account but can be used for any multi-account structure. reqId:int - The ID of the data request. Ensures that responses are matched to requests If several requests are in process. groupName:str - Set to All to returnrn 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:str - A comma-separated list of account tags. Available tags are: accountountType NetLiquidation, TotalCashValue - Total cash including futures pnl SettledCash - For cash accounts, this is the same as TotalCashValue AccruedCash - Net accrued interest BuyingPower - The maximum amount of marginable US stocks the account can buy EquityWithLoanValue - Cash + stocks + bonds + mutual funds PreviousDayEquityWithLoanValue, GrossPositionValue - The sum of the absolute value of all stock and equity option positions RegTEquity, RegTMargin, SMA - Special Memorandum Account InitMarginReq, MaintMarginReq, AvailableFunds, ExcessLiquidity, Cushion - Excess liquidity as a percentage of net liquidation value FullInitMarginReq, FullMaintMarginReq, FullAvailableFunds, FullExcessLiquidity, LookAheadNextChange - Time when look-ahead values take effect LookAheadInitMarginReq, LookAheadMaintMarginReq, LookAheadAvailableFunds, LookAheadExcessLiquidity, 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.
def reqAccountUpdates | ( | self, | |
bool | subscribe, | ||
str | acctCode | ||
) |
Account and Portfolio.
Call this function to start getting account values, portfolio, and last update time information via EWrapper.updateAccountValue(), EWrapperi.updatePortfolio() and Wrapper.updateAccountTime(). subscribe:bool - If set to TRUE, the client will start receiving account and Portfoliolio updates. If set to FALSE, the client will stop receiving this information. acctCode:str -The account code for which to receive account and portfolio updates.
def reqAccountUpdatesMulti | ( | self, | |
int | reqId, | ||
str | account, | ||
str | modelCode, | ||
bool | ledgerAndNLV | ||
) |
Requests account updates for account and/or model.
def reqAllOpenOrders | ( | self | ) |
Call this function to request the open orders placed from all clients and also from TWS. Each open order will be fed back through the openOrder() and orderStatus() functions on the EWrapper. Note: No association is made between the returned orders and the requesting client.
def reqAutoOpenOrders | ( | self, | |
bool | bAutoBind | ||
) |
Call this function to request that newly created TWS orders be implicitly associated with the client. When a new TWS order is created, the order will be associated with the client, and fed back through the openOrder() and orderStatus() functions on the EWrapper. Note: This request can only be made from a client with clientId of 0. bAutoBind: If set to TRUE, newly created TWS orders will be implicitly associated with the client. If set to FALSE, no association will be made.
def reqCompletedOrders | ( | self, | |
bool | apiOnly | ||
) |
Call this function to request the completed orders. If apiOnly parameter is true, then only completed orders placed from API are requested. Each completed order will be fed back through the completedOrder() function on the EWrapper.
def reqContractDetails | ( | self, | |
int | reqId, | ||
Contract | contract | ||
) |
Contract Details.
Call this function to download all details for a particular underlying. The contract details will be received via the contractDetails() function on the EWrapper. reqId:int - The ID of the data request. Ensures that responses are make_fieldatched to requests if several requests are in process. contract:Contract - The summary description of the contract being looked up.
def reqCurrentTime | ( | self | ) |
Asks the current system time on the server side.
def reqExecutions | ( | self, | |
int | reqId, | ||
ExecutionFilter | execFilter | ||
) |
Executions.
When this function is called, the execution reports that meet the filter criteria are downloaded to the client via the execDetails() function. To view executions beyond the past 24 hours, open the Trade Log in TWS and, while the Trade Log is displayed, request the executions again from the API. reqId:int - The ID of the data request. Ensures that responses are matched to requests if several requests are in process. execFilter:ExecutionFilter - This object contains attributes that describe the filter criteria used to determine which execution reports are returned. NOTE: Time format must be 'yyyymmdd-hh:mm:ss' Eg: '20030702-14:55'
def reqFundamentalData | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
str | reportType, | ||
TagValueList | fundamentalDataOptions | ||
) |
Fundamental Data.
Call this function to receive fundamental data for stocks. The appropriate market data subscription must be set up in Account Management before you can receive this data. Fundamental data will be returned at EWrapper.fundamentalData(). reqFundamentalData() can handle conid specified in the Contract object, but not tradingClass or multiplier. This is because reqFundamentalData() is used only for stocks and stocks do not have a multiplier and trading class. reqId:tickerId - The ID of the data request. Ensures that responses are matched to requests if several requests are in process. contract:Contract - This structure contains a description of the contract for which fundamental data is being requested. reportType:str - One of the following XML reports: ReportSnapshot (company overview) ReportsFinSummary (financial summary) ReportRatios (financial ratios) ReportsFinStatements (financial statements) RESC (analyst estimates) CalendarReport (company calendar)
def reqGlobalCancel | ( | self | ) |
Use this function to cancel all open orders globally. It cancels both API and TWS open orders. If the order was created in TWS, it also gets canceled. If the order was initiated in the API, it also gets canceled.
def reqHistoricalData | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
str | endDateTime, | ||
str | durationStr, | ||
str | barSizeSetting, | ||
str | whatToShow, | ||
int | useRTH, | ||
int | formatDate, | ||
bool | keepUpToDate, | ||
TagValueList | chartOptions | ||
) |
Historical Data.
Requests contracts' historical data. When requesting historical data, a finishing time and date is required along with a duration string. The resulting bars will be returned in EWrapper.historicalData() reqId:TickerId - The id of the request. Must be a unique value. When the market data returns, it whatToShowill be identified by this tag. This is also used when canceling the market data. contract:Contract - This object contains a description of the contract for which market data is being requested. endDateTime:str - Defines a query end date and time at any point during the past 6 mos. Valid values include any date/time within the past six months in the format: yyyymmdd HH:mm:ss ttt where "ttt" is the optional time zone. durationStr:str - Set the query duration up to one week, using a time unit of seconds, days or weeks. Valid values include any integer followed by a space and then S (seconds), D (days) or W (week). If no unit is specified, seconds is used. barSizeSetting:str - Specifies the size of the bars that will be returned (within IB/TWS listimits). Valid values include: 1 sec 5 secs 15 secs 30 secs 1 min 2 mins 3 mins 5 mins 15 mins 30 mins 1 hour 1 day whatToShow:str - Determines the nature of data beinging extracted. Valid values include: TRADES MIDPOINT BID ASK BID_ASK HISTORICAL_VOLATILITY OPTION_IMPLIED_VOLATILITY useRTH:int - Determines whether to return all data available during the requested time span, or only data that falls within regular trading hours. Valid values include: 0 - all data is returned even where the market in question was outside of its regular trading hours. 1 - only data within the regular trading hours is returned, even if the requested time span falls partially or completely outside of the RTH. formatDate: int - Determines the date format applied to returned bars. validd values include: 1 - dates applying to bars returned in the format: yyyymmdd{space}{space}hh:mm:dd 2 - dates are returned as a long integer specifying the number of seconds since 1/1/1970 GMT. chartOptions:TagValueList - For internal use only. Use default value XYZ.
def reqIds | ( | self, | |
int | numIds | ||
) |
Call this function to request from TWS the next valid ID that can be used when placing an order. After calling this function, the nextValidId() event will be triggered, and the id returned is that next valid ID. That ID will reflect any autobinding that has occurred (which generates new IDs and increments the next valid ID therein). numIds:int - deprecated
def reqManagedAccts | ( | self | ) |
Financial Advisors.
Call this function to request the list of managed accounts. The list will be returned by the managedAccounts() function on the EWrapper. Note: This request can only be made when connected to a FA managed account.
def reqMarketDataType | ( | self, | |
int | marketDataType | ||
) |
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. If you use this function, you are telling TWS to automatically switch to frozen market data after the close. Then, before the opening of the next trading day, market data will automatically switch back to real-time market data. marketDataType:int - 1 for real-time streaming market data or 2 for frozen market data
def reqMktData | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
str | genericTickList, | ||
bool | snapshot, | ||
bool | regulatorySnapshot, | ||
TagValueList | mktDataOptions | ||
) |
Market Data.
Call this function to request market data. The market data will be returned by the tickPrice and tickSize events. reqId: TickerId - The ticker id. Must be a unique value. When the market data returns, it will be identified by this tag. This is also used when canceling the market data. contract:Contract - This structure contains a description of the Contractt for which market data is being requested. genericTickList:str - A commma delimited list of generic tick types. Tick types can be found in the Generic Tick Types page. Prefixing w/ 'mdoff' indicates that top mkt data shouldn't tick. You can specify the news source by postfixing w/ ':<source>. Example: "mdoff,292:FLY+BRF" snapshot:bool - Check to return a single snapshot of Market data and have the market data subscription cancel. Do not enter any genericTicklist values if you use snapshots. regulatorySnapshot: bool - With the US Value Snapshot Bundle for stocks, regulatory snapshots are available for 0.01 USD each. mktDataOptions:TagValueList - For internal use only. Use default value XYZ.
def reqMktDepth | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
int | numRows, | ||
bool | isSmartDepth, | ||
TagValueList | mktDepthOptions | ||
) |
Call this function to request market depth for a specific contract. The market depth will be returned by the updateMktDepth() and updateMktDepthL2() events. Requests the contract's market depth (order book). Note 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. reqId:TickerId - The ticker id. Must be a unique value. When the market depth data returns, it will be identified by this tag. This is also used when canceling the market depth contract:Contact - This structure contains a description of the contract for which market depth data is being requested. numRows:int - Specifies the numRowsumber of market depth rows to display. isSmartDepth:bool - specifies SMART depth request mktDepthOptions:TagValueList - For internal use only. Use default value XYZ.
def reqNewsBulletins | ( | self, | |
bool | allMsgs | ||
) |
News Bulletins.
Call this function to start receiving news bulletins. Each bulletin will be returned by the updateNewsBulletin() event. allMsgs:bool - If set to TRUE, returns all the existing bulletins for the currencyent day and any new ones. If set to FALSE, will only return new bulletins.
def reqOpenOrders | ( | self | ) |
Call this function to request the open orders that were placed from this client. Each open order will be fed back through the openOrder() and orderStatus() functions on the EWrapper. Note: The client with a clientId of 0 will also receive the TWS-owned open orders. These orders will be associated with the client and a new orderId will be generated. This association will persist over multiple API and TWS sessions.
def reqPositions | ( | self | ) |
Requests real-time position data for all accounts.
def reqPositionsMulti | ( | self, | |
int | reqId, | ||
str | account, | ||
str | modelCode | ||
) |
Requests positions for account and/or model. Results are delivered via EWrapper.positionMulti() and EWrapper.positionMultiEnd()
def reqRealTimeBars | ( | self, | |
TickerId | reqId, | ||
Contract | contract, | ||
int | barSize, | ||
str | whatToShow, | ||
bool | useRTH, | ||
TagValueList | realTimeBarsOptions | ||
) |
Real Time Bars.
Call the reqRealTimeBars() function to start receiving real time bar results through the realtimeBar() EWrapper function. reqId:TickerId - The Id for the request. Must be a unique value. When the data is received, it will be identified by this Id. This is also used when canceling the request. contract:Contract - This object contains a description of the contract for which real time bars are being requested barSize:int - Currently only 5 second bars are supported, if any other value is used, an exception will be thrown. whatToShow:str - Determines the nature of the data extracted. Valid values include: TRADES BID ASK MIDPOINT useRTH:bool - Regular Trading Hours only. Valid values include: 0 = all data available during the time span requested is returned, including time intervals when the market in question was outside of regular trading hours. 1 = only data within the regular trading hours for the product requested is returned, even if the time time span falls partially or completely outside. realTimeBarOptions:TagValueList - For internal use only. Use default value XYZ.
def reqScannerParameters | ( | self | ) |
Market Scanners.
Requests an XML string that describes all possible scanner queries.
def reqScannerSubscription | ( | self, | |
int | reqId, | ||
ScannerSubscription | subscription, | ||
TagValueList | scannerSubscriptionOptions, | ||
TagValueList | scannerSubscriptionFilterOptions | ||
) |
reqId:int - The ticker ID. Must be a unique value. scannerSubscription:ScannerSubscription - This structure contains possible parameters used to filter results. scannerSubscriptionOptions:TagValueList - For internal use only. Use default value XYZ.
def reqSecDefOptParams | ( | self, | |
int | reqId, | ||
str | underlyingSymbol, | ||
str | futFopExchange, | ||
str | underlyingSecType, | ||
int | underlyingConId | ||
) |
Requests security definition option parameters for viewing a contract's option chain reqId the ID chosen for the request underlyingSymbol futFopExchange The exchange on which the returned options are trading. Can be set to the empty string "" for all exchanges. underlyingSecType The type of the underlying security, i.e. STK underlyingConId the contract ID of the underlying security. Response comes via EWrapper.securityDefinitionOptionParameter()
def reqSoftDollarTiers | ( | self, | |
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.
def requestFA | ( | self, | |
FaDataType | faData | ||
) |
Call this function to request FA configuration information from TWS. The data returns in an XML string via a "receiveFA" ActiveX event. faData:FaDataType - Specifies the type of Financial Advisor configuration data beingingg requested. Valid values include: 1 = GROUPS 2 = PROFILE 3 = ACCOUNT ALIASES
def run | ( | self | ) |
This is the function that has the message loop.
def serverVersion | ( | self | ) |
Returns the version of the TWS instance to which the API application is connected.
def setServerLogLevel | ( | self, | |
int | logLevel | ||
) |
The default detail level is ERROR. For more details, see API Logging.
def startApi | ( | self | ) |
Initiates the message exchange between the client application and the TWS/IB Gateway.
def subscribeToGroupEvents | ( | self, | |
int | reqId, | ||
int | groupId | ||
) |
reqId:int - The unique number associated with the notification. groupId:int - The ID of the group, currently it is a number from 1 to 7. This is the display group subscription request sent by the API to TWS.
def twsConnectionTime | ( | self | ) |
Returns the time the API application made a connection to TWS.
def unsubscribeFromGroupEvents | ( | self, | |
int | reqId | ||
) |
reqId:int - The requestId specified in subscribeToGroupEvents().
def updateDisplayGroup | ( | self, | |
int | reqId, | ||
str | contractInfo | ||
) |
reqId:int - The requestId specified in subscribeToGroupEvents(). contractInfo:str - The encoded value that uniquely represents the contract in IB. Possible values include: none = empty selection contractID@exchange - any non-combination contract. Examples: 8314@SMART for IBM SMART; 8314@ARCA for IBM @ARCA. combo = if any combo is selected.
def verifyAndAuthMessage | ( | self, | |
str | apiData, | ||
str | xyzResponse | ||
) |
For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
def verifyAndAuthRequest | ( | self, | |
str | apiName, | ||
str | apiVersion, | ||
str | opaqueIsvKey | ||
) |
For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
def verifyMessage | ( | self, | |
str | apiData | ||
) |
For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.
def verifyRequest | ( | self, | |
str | apiName, | ||
str | apiVersion | ||
) |
For IB's internal purpose. Allows to provide means of verification between the TWS and third party programs.