Python API
The Python surface mirrors the Rust API and is generated from the same source on every release.
Python API Reference (v0.7.1)
Auto-generated from source — do not edit.
Table of Contents
- EClient: Connection
- EClient: Account & Portfolio
- EClient: Orders
- EClient: Market Data
- EClient: Reference Data
- EClient: Gateway-Local & Stubs
- EWrapper Callbacks
Connection
new
Create a new EClient (or EWrapper) instance.
def new(wrapper))
| Parameter | Type | Description |
|---|---|---|
wrapper | Py<PyAny> | Wrapper callback receiver for synchronous delivery. |
connect
Connect to IB and start the engine. Live logins (paper=False) enter a second-factor approval window and block until the factor is approved (mobile push) or the server ends the wait. As in the reference there is no client timeout by default: the server closes the login after about 18 min. The keepalives of the server are answered during the whole wait. This is a human approval gate, not a hang. To bound or avoid it: use paper=True, pass an ib_key_timeout_secs, or run connect() on a worker thread with your own timeout. Paper logins skip the gate entirely. Set RUST_LOG=info to see a log line when the wait begins. code_provider: a callable used for the typed-code variant of the second factor. When the server sends the challenge it is called once, during connect(), with a dict {"display_id": str, "avth_url": str}, and must return the code as a str; an exception it raises ends the login. It runs on its own thread while the login keeps answering the keepalives. None (default): wait for the mobile push approval. Multiple EClient instances can run concurrently in one process; each owns its own state, sockets, and engine thread, and connect() does not serialize across instances. If you pin engines via core_id, give each a distinct value. See ibx#203 / ibx#207.
def connect(host="cdc1.ibllc.com".to_string(), port=0, client_id=0, username="".to_string(), password="".to_string(), paper=true, core_id=None, ib_key_timeout_secs=None, ib_key_token_sub_type=None, code_provider=None))
| Parameter | Type | Description |
|---|---|---|
host | str | Server hostname. |
port | int | Port number (unused — ibx connects directly). |
client_id | int | Client ID (unused — single-client engine). |
username | str | Account username. |
password | str | Account password. |
paper | bool | If true, connect to paper trading. If false, connect blocks on the live second-factor approval window (see method note). |
core_id | usize or None | CPU core affinity for the hot loop thread. Use a distinct value per engine when running several in one process. A pinned engine polls without pause and keeps that core busy; without it the engine thread rests while there is nothing to do. |
ib_key_timeout_secs | int or None | Live second-factor approval timeout in seconds. Default: no client timeout, the wait ends when the server answers or closes the login (about 18 min). Set it to fail fast on unattended live logins; ignored for paper. |
ib_key_token_sub_type | str or None | Override of the second-factor token sub-type. Default: the value the server lists for the session. Ignored for paper. |
code_provider | Py<PyAny> or None | Callable for the typed-code second factor: called once during connect() with a dict {"display_id", "avth_url"}, returns the code as str. Default: wait for the mobile push approval. Ignored for paper. |
disconnect
Disconnect from IB.
def disconnect()
server_version
API level of the session: 214, the level the reference gives a current client; None when not connected (ibx#426).
def server_version()
tws_connection_time
Time the session started, as yyyyMMdd HH:mm:ss {zone} in the machine's local time; None when not connected (ibx#426).
def tws_connection_time()
is_connected
Check if connected.
def is_connected()
run
Run the event loop.
def run()
get_account_id
Get the account ID.
def get_account_id()
Account & Portfolio
req_pnl
Request P&L updates for the account.
def req_pnl(req_id, account, model_code=""))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
cancel_pnl
Cancel P&L subscription.
def cancel_pnl(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_pnl_single
Request P&L for a single position.
def req_pnl_single(req_id, account, model_code, con_id))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
con_id | int | Contract ID. Unique per instrument. |
cancel_pnl_single
Cancel single-position P&L subscription.
def cancel_pnl_single(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_account_summary
Request account summary.
def req_account_summary(req_id, group_name, tags))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
group_name | str | Account group name (e.g. "All"). |
tags | str | Comma-separated account tags: "NetLiquidation,BuyingPower,...". |
cancel_account_summary
Cancel account summary.
def cancel_account_summary(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_positions
Request all positions.
def req_positions()
cancel_positions
Cancel positions.
def cancel_positions()
req_account_updates
Request account updates.
def req_account_updates(subscribe, _acct_code=""))
| Parameter | Type | Description |
|---|---|---|
subscribe | bool | true to start updates, false to stop. |
acct_code | str | Account code (e.g. "DU1234567"). |
req_managed_accts
Request managed accounts list: every account of the logon's account list, in logon order, comma separated (ibx#420).
def req_managed_accts()
req_account_updates_multi
Request account updates across accounts / models. A subscription, as the reference (ibx#476): the rows, account_update_multi_end, then the rows that change, until cancel_account_updates_multi.
def req_account_updates_multi(req_id, account, model_code, ledger_and_nlv=false))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
ledger_and_nlv | bool | If true, include ledger and NLV data. |
cancel_account_updates_multi
Cancel multi-account updates.
def cancel_account_updates_multi(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_positions_multi
Request positions across multiple accounts/models. A subscription, as the reference (ibx#476).
def req_positions_multi(req_id, account, model_code))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
cancel_positions_multi
Cancel multi-account positions.
def cancel_positions_multi(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account_snapshot
Read account state snapshot. Returns a dict with all account values.
def account_snapshot()
Orders
place_order
Place an order.
def place_order(order_id, contract, order)
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
order | Order | Order parameters (action, quantity, type, price, TIF, etc.). |
cancel_order
Cancel an order.
def cancel_order(order_id, manual_order_cancel_time=""))
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
manual_order_cancel_time | str | Manual cancel time (empty for immediate). |
req_global_cancel
Cancel all orders globally: every order of the account the session knows, those of other clients and of earlier sessions too, as the reference cancels them.
def req_global_cancel()
req_ids
Request next valid order ID: the highest order id this client used + 1, as the reference computes it per client id (1 when none), a 32-bit id. The ids of the client's earlier sessions count as far as the server's replays of the logon show them; right after the connect the answer waits for the order replay of the logon. Nothing is reserved.
def req_ids(num_ids=1))
| Parameter | Type | Description |
|---|---|---|
num_ids | int | Number of IDs to reserve (unused). |
next_order_id
The next order id for a new order: the next valid id (see req_ids), or above the ids this method gave before. Each call reserves the id it gives.
def next_order_id()
req_open_orders
Request all open orders for this client. Before the order replay of the logon has ended, and while the auth link is lost, the request is answered only after the order replay, from the dispatch loop (ibx#251).
def req_open_orders()
req_all_open_orders
Request all open orders across all clients. Held like req_open_orders until the order replay (ibx#251).
def req_all_open_orders()
req_auto_open_orders
Automatically bind future orders to this client.
def req_auto_open_orders(b_auto_bind))
| Parameter | Type | Description |
|---|---|---|
b_auto_bind | bool | If true, auto-bind future orders to this client. |
req_executions
Request execution reports.
def req_executions(req_id, exec_filter=None))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
exec_filter | Py<PyAny> or None |
req_completed_orders
Request completed orders.
def req_completed_orders(api_only=false))
| Parameter | Type | Description |
|---|---|---|
api_only | bool |
Market Data
req_mkt_data
Request market data for a contract.
def req_mkt_data(req_id, contract, generic_tick_list="", snapshot=false, regulatory_snapshot=false, mkt_data_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
generic_tick_list | str | Comma-separated generic tick IDs (e.g. "233" for RT volume). |
snapshot | bool | If true, delivers one quote then auto-cancels. |
regulatory_snapshot | bool | If true, request a regulatory snapshot (additional fees may apply). |
mkt_data_options | list |
cancel_mkt_data
Cancel market data subscription.
def cancel_mkt_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_tick_by_tick_data
Request tick-by-tick data.
def req_tick_by_tick_data(req_id, contract, tick_type, number_of_ticks=0, ignore_size=false))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
tick_type | str | Tick type ID or tick-by-tick type string. |
number_of_ticks | int | Maximum number of ticks to return. |
ignore_size | bool | If true, ignore size in tick-by-tick data. |
cancel_tick_by_tick_data
Cancel tick-by-tick data.
def cancel_tick_by_tick_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_ping
Request an auth-connection round-trip time sample (ibx#158): sends a lightweight liveness probe with no side effects on subscriptions, contract caches, or pacing budgets. Poll last_rtt_ms() after a moment for the result.
def req_ping()
last_rtt_ms
Last measured auth-connection round-trip time in milliseconds, or None if never measured (ibx#158). A gauge, not a benchmark — see req_ping. Also sampled automatically by the engine's own liveness probes.
def last_rtt_ms()
req_market_data_type
Set the market data type (ibx#447): 1=live, 2=frozen, 3=delayed, 4=delayed-frozen, as the Rust client. With delayed on, a subscription the server rejects goes on with delayed data (type 3, error 10167). With frozen on (2, until 1), a streaming request of a contract whose data is frozen gets the frozen top of book (type 2). A value outside 1..=4 gives error 321 with id -1.
def req_market_data_type(market_data_type)
| Parameter | Type | Description |
|---|---|---|
market_data_type | int | 1=live, 2=frozen, 3=delayed, 4=delayed-frozen. |
req_mkt_depth
Request market depth (L2 order book).
def req_mkt_depth(req_id, contract, num_rows=5, is_smart_depth=false, mkt_depth_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
num_rows | int | Number of order book rows to subscribe to. |
is_smart_depth | bool | If true, aggregate depth from multiple exchanges via SMART. |
mkt_depth_options | list |
cancel_mkt_depth
Cancel market depth.
def cancel_mkt_depth(req_id, is_smart_depth=false))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
is_smart_depth | bool | If true, aggregate depth from multiple exchanges via SMART. |
req_real_time_bars
Request real-time 5-second bars.
def req_real_time_bars(req_id, contract, bar_size=5, what_to_show="TRADES", use_rth=0, real_time_bars_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
bar_size | int | Bar size: "1 min", "5 mins", "1 hour", "1 day", etc. |
what_to_show | str | Data type: "TRADES", "MIDPOINT", "BID", "ASK", "BID_ASK", etc. |
use_rth | int | If true, only return data from Regular Trading Hours. |
real_time_bars_options | list |
cancel_real_time_bars
Cancel real-time bars.
def cancel_real_time_bars(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
quote
Zero-copy SeqLock quote read by req_id. Returns a dict with bid, ask, last, bid_size, ask_size, last_size, volume, high, low, open, close, or None if the req_id is not mapped.
def quote(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
quote_by_instrument
Zero-copy SeqLock quote read by InstrumentId. Returns a dict with bid, ask, last, bid_size, ask_size, last_size, volume, high, low, open, close, or None if not connected.
def quote_by_instrument(instrument)
| Parameter | Type | Description |
|---|---|---|
instrument | int | Instrument type for scanner (e.g. "STK", "FUT"). |
Reference Data
req_historical_data
Request historical bar data.
def req_historical_data(req_id, contract, end_date_time, duration_str, bar_size_setting, what_to_show, use_rth, format_date=1, keep_up_to_date=false, chart_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
end_date_time | str | End date/time in "YYYYMMDD HH:MM:SS" format, or empty for now. |
duration_str | str | Duration string, e.g. "1 D", "1 W", "1 M", "1 Y". |
bar_size_setting | str | Bar size: "1 min", "5 mins", "1 hour", "1 day", etc. |
what_to_show | str | Data type: "TRADES", "MIDPOINT", "BID", "ASK", "BID_ASK", etc. |
use_rth | int | If true, only return data from Regular Trading Hours. |
format_date | int | Date format: 1="YYYYMMDD HH:MM:SS", 2=Unix seconds. |
keep_up_to_date | bool | If true, continue receiving updates after initial history. |
chart_options | list |
cancel_historical_data
Cancel historical data.
def cancel_historical_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_head_time_stamp
Request head timestamp.
def req_head_time_stamp(req_id, contract, what_to_show, use_rth, format_date=1))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
what_to_show | str | Data type: "TRADES", "MIDPOINT", "BID", "ASK", "BID_ASK", etc. |
use_rth | int | If true, only return data from Regular Trading Hours. |
format_date | int | Date format: 1="YYYYMMDD HH:MM:SS", 2=Unix seconds. |
cancel_head_time_stamp
Cancel head timestamp request.
def cancel_head_time_stamp(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_contract_details
Request contract details.
def req_contract_details(req_id, contract)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
req_mkt_depth_exchanges
Request available exchanges for market depth.
def req_mkt_depth_exchanges()
req_matching_symbols
Search for matching symbols.
def req_matching_symbols(req_id, pattern)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
pattern | str | Symbol search pattern. |
req_sec_def_opt_params
Request option chain parameters (ibx#440). A request the reference refuses locally gets 321; the rows come through security_definition_option_parameter, then security_definition_option_parameter_end.
def req_sec_def_opt_params(req_id, underlying_symbol, fut_fop_exchange="", underlying_sec_type="STK", underlying_con_id=0))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
underlying_symbol | str | Underlying symbol (e.g. "AAPL"). |
fut_fop_exchange | str | Exchange for futures/FOP options. |
underlying_sec_type | str | Underlying security type (e.g. "STK"). |
underlying_con_id | int | Underlying contract ID. |
req_scanner_subscription
Request scanner subscription: the whole ibapi subscription, the subscription options and the filter options (ibx#456). A local refusal comes back through error.
def req_scanner_subscription(req_id, subscription, scanner_subscription_options=Vec::new(), scanner_subscription_filter_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
subscription | Py<PyAny> | Scanner subscription parameters. |
scanner_subscription_options | list | |
scanner_subscription_filter_options | list |
cancel_scanner_subscription
Cancel scanner subscription.
def cancel_scanner_subscription(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_scanner_parameters
Request scanner parameters XML.
def req_scanner_parameters()
req_news_article
Request a news article.
def req_news_article(req_id, provider_code, article_id, news_article_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
provider_code | str | News provider code (e.g. "BRFG"). |
article_id | str | News article identifier. |
news_article_options | list |
req_historical_news
Request historical news.
def req_historical_news(req_id, con_id, provider_codes, start_date_time, end_date_time, total_results, historical_news_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
con_id | int | Contract ID. Unique per instrument. |
provider_codes | str | Pipe-separated news provider codes. |
start_date_time | str | Start date/time for tick query. |
end_date_time | str | End date/time in "YYYYMMDD HH:MM:SS" format, or empty for now. |
total_results | int | Maximum number of news results. |
historical_news_options | list |
req_fundamental_data
Request fundamental data.
def req_fundamental_data(req_id, contract, report_type, fundamental_data_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
report_type | str | Report type: "ReportSnapshot", "ReportsFinSummary", "RESC", etc. |
fundamental_data_options | list |
cancel_fundamental_data
Cancel fundamental data.
def cancel_fundamental_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_historical_ticks
Request historical tick data.
def req_historical_ticks(req_id, contract, start_date_time="", end_date_time="", number_of_ticks=1000, what_to_show="TRADES", use_rth=1, ignore_size=false, misc_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
start_date_time | str | Start date/time for tick query. |
end_date_time | str | End date/time in "YYYYMMDD HH:MM:SS" format, or empty for now. |
number_of_ticks | int | Maximum number of ticks to return. |
what_to_show | str | Data type: "TRADES", "MIDPOINT", "BID", "ASK", "BID_ASK", etc. |
use_rth | int | If true, only return data from Regular Trading Hours. |
ignore_size | bool | If true, ignore size in tick-by-tick data. |
misc_options | list |
req_market_rule
Request market rule details.
def req_market_rule(market_rule_id)
| Parameter | Type | Description |
|---|---|---|
market_rule_id | int | Market rule ID. |
req_histogram_data
Request histogram data.
def req_histogram_data(req_id, contract, use_rth, time_period))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
use_rth | bool | If true, only return data from Regular Trading Hours. |
time_period | str | Histogram time period. |
cancel_histogram_data
Cancel histogram data.
def cancel_histogram_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_historical_schedule
Request historical trading schedule.
def req_historical_schedule(req_id, contract, end_date_time="", duration_str="1 M", use_rth=true))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
end_date_time | str | End date/time in "YYYYMMDD HH:MM:SS" format, or empty for now. |
duration_str | str | Duration string, e.g. "1 D", "1 W", "1 M", "1 Y". |
use_rth | bool | If true, only return data from Regular Trading Hours. |
Gateway-Local & Stubs
calculate_implied_volatility
Implied volatility of an option price, computed locally by the option model as the reference (ibx#442). The options are not used.
def calculate_implied_volatility(req_id, contract, option_price, under_price, implied_vol_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
option_price | float | Option market price. |
under_price | float | Underlying asset price. |
implied_vol_options | list |
calculate_option_price
Price and greeks of an option at a volatility, computed locally by the option model as the reference (ibx#442). The options are not used.
def calculate_option_price(req_id, contract, volatility, under_price, opt_prc_options=Vec::new()))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
volatility | float | Implied volatility. |
under_price | float | Underlying asset price. |
opt_prc_options | list |
cancel_calculate_implied_volatility
Cancel implied volatility calculation.
def cancel_calculate_implied_volatility(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
cancel_calculate_option_price
Cancel option price calculation.
def cancel_calculate_option_price(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
exercise_options
Exercise options. Not yet implemented.
def exercise_options(req_id, contract, exercise_action, exercise_quantity, account, _override))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Contract | Contract specification (symbol, secType, exchange, currency, etc.). |
exercise_action | int | 1=exercise, 2=lapse. |
exercise_quantity | int | Number of contracts to exercise. |
account | str | Account ID. |
override | int | Override flag for exercise. |
req_news_bulletins
Subscribe to news bulletins.
def req_news_bulletins(all_msgs=true))
| Parameter | Type | Description |
|---|---|---|
all_msgs | bool | If true, receive all existing bulletins on subscribe. |
cancel_news_bulletins
Cancel news bulletin subscription.
def cancel_news_bulletins()
req_current_time
Request current server time.
def req_current_time()
request_fa
Request FA data. Not yet implemented.
def request_fa(_fa_data_type)
| Parameter | Type | Description |
|---|---|---|
fa_data_type | int | FA data type (1=Groups, 2=Profiles, 3=Aliases). |
replace_fa
Replace FA data. Not yet implemented.
def replace_fa(req_id, fa_data_type, cxml))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
fa_data_type | int | FA data type (1=Groups, 2=Profiles, 3=Aliases). |
cxml | str | FA XML configuration data. |
query_display_groups
Query display groups: the fixed list of the seven groups.
def query_display_groups(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
subscribe_to_group_events
As the reference (ibx#424): the contract of the group at once, none since no group has one; error 321 for a group outside 1 to 7 or a request id already subscribed.
def subscribe_to_group_events(req_id, group_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
group_id | int | Display group ID. |
unsubscribe_from_group_events
No answer, but error 321 for a request id that is not subscribed, as the reference (ibx#424).
def unsubscribe_from_group_events(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
update_display_group
As the reference (ibx#424): error 321 for bad input or a request id that is not subscribed, error 473 for a conId that is not a contract, and no answer for a valid update, which changes no group.
def update_display_group(req_id, contract_info)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract_info | str | Display group contract info string. |
req_smart_components
As the reference (ibx#441): the exchange map of the BBO exchange that market data made known; an unknown one gives error 321; a map not come yet is answered by the message loop, within 2 s.
def req_smart_components(req_id, bbo_exchange)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
bbo_exchange | str | BBO exchange for smart component lookup (e.g. "SMART"). |
req_news_providers
Request available news providers.
def req_news_providers()
req_soft_dollar_tiers
Request soft dollar tiers.
def req_soft_dollar_tiers(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_family_codes
Request family codes.
def req_family_codes()
set_server_log_level
Set server log level (1=error..5=trace).
def set_server_log_level(log_level=2))
| Parameter | Type | Description |
|---|---|---|
log_level | int | Log level: 1=error, 2=warn, 3=info, 4=debug, 5=trace. |
req_user_info
Request user info (white branding ID).
def req_user_info(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_wsh_meta_data
Request Wall Street Horizon metadata. Not yet implemented.
def req_wsh_meta_data(req_id)
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
req_wsh_event_data
Request Wall Street Horizon event data. Not yet implemented.
def req_wsh_event_data(req_id, wsh_event_data=None))
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
wsh_event_data | Py<PyAny> or None |
EWrapper Callbacks
new
Create a new EClient (or EWrapper) instance.
| Parameter | Type | Description |
|---|---|---|
args | Bound<'_, pyo3::types::PyTuple> | |
kwargs | Bound<'_, pyo3::types::PyDict> or None |
connect_ack
Connection acknowledged.
connection_closed
Connection has been closed.
next_valid_id
Next valid order ID from the server.
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
managed_accounts
Comma-separated list of managed account IDs.
| Parameter | Type | Description |
|---|---|---|
accounts_list | str | Comma-separated account IDs. |
error
Error or informational message from the server.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
error_code | int | Error code. |
error_string | str | Error message. |
advanced_order_reject_json | str | JSON with advanced rejection details. |
current_time
Current server time (Unix seconds).
| Parameter | Type | Description |
|---|---|---|
time | int | Tick timestamp (Unix seconds). |
tick_price
Price tick update (bid, ask, last, etc.).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
price | float | Tick price. |
attrib | Py<PyAny> | Tick attributes. |
tick_size
Size tick update (bid size, ask size, volume, etc.).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
size | float | Tick size. |
tick_string
String tick (e.g. last trade timestamp).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
value | str | Account value. |
tick_generic
Generic numeric tick value.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
value | float | Account value. |
tick_snapshot_end
Snapshot delivery complete; subscription auto-cancelled.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
market_data_type
Market data type changed (1=live, 2=frozen, 3=delayed, 4=delayed-frozen).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
market_data_type | int | 1=live, 2=frozen, 3=delayed, 4=delayed-frozen. |
order_status
Order status update (filled, remaining, avg price, etc.).
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
status | str | Order status string ("Submitted", "Filled", "Cancelled", etc.). |
filled | float | Cumulative filled quantity. |
remaining | float | Remaining quantity. |
avg_fill_price | float | Average fill price. |
perm_id | int | Permanent order ID assigned by the server. |
parent_id | int | Parent order ID (0 if no parent). |
last_fill_price | float | Price of the last fill. |
client_id | int | Client ID (unused — single-client engine). |
why_held | str | Reason the order is held (e.g. "locate"). |
mkt_cap_price | float | Market cap price for the order. |
open_order
Open order details (contract, order, state).
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
order | Py<PyAny> | Order parameters (action, quantity, type, price, TIF, etc.). |
order_state | Py<PyAny> | Order state (status, margin, commission info). |
open_order_end
End of open orders list.
exec_details
Execution fill details.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
execution | Py<PyAny> | Execution details (exec_id, time, price, shares, etc.). |
exec_details_end
End of execution details list.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
commission_and_fees_report
Commission and fees report for an execution.
| Parameter | Type | Description |
|---|---|---|
commission_and_fees_report | Py<PyAny> |
update_account_value
Account value update (key/value/currency).
| Parameter | Type | Description |
|---|---|---|
key | str | Account value key (e.g. "NetLiquidation", "BuyingPower"). |
value | str | Account value. |
currency | str | Currency code (e.g. "USD"). |
account_name | str | Account identifier. |
update_portfolio
Portfolio position update.
| Parameter | Type | Description |
|---|---|---|
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
position | float | Book position (row index) or position size. |
market_price | float | Current market price. |
market_value | float | Current market value of position. |
average_cost | float | Average cost basis. |
unrealized_pnl | float | Unrealized profit/loss. |
realized_pnl | float | Realized profit/loss. |
account_name | str | Account identifier. |
update_account_time
Account update timestamp.
| Parameter | Type | Description |
|---|---|---|
timestamp | str | Timestamp string. |
account_download_end
Account data delivery complete.
| Parameter | Type | Description |
|---|---|---|
account | str | Account ID. |
account_summary
Account summary tag/value entry.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
tag | str | Account tag name (e.g. "NetLiquidation"). |
value | str | Account value. |
currency | str | Currency code (e.g. "USD"). |
account_summary_end
End of account summary.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
position
Position entry (account, contract, size, avg cost).
| Parameter | Type | Description |
|---|---|---|
account | str | Account ID. |
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
pos | float | Position size (decimal shares). |
avg_cost | float | Average cost per share. |
position_end
End of positions list.
pnl
Account P&L update (daily, unrealized, realized).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
daily_pnl | float | Daily profit/loss. |
unrealized_pnl | float | Unrealized profit/loss. |
realized_pnl | float | Realized profit/loss. |
pnl_single
Single-position P&L update.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
pos | float | Position size (decimal shares). |
daily_pnl | float | Daily profit/loss. |
unrealized_pnl | float | Unrealized profit/loss. |
realized_pnl | float | Realized profit/loss. |
value | float | Account value. |
historical_data
Historical OHLCV bar.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
bar | Py<PyAny> | Bar data (date, open, high, low, close, volume, wap, bar_count). |
historical_data_end
End of historical data delivery.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
start | str | Period start date/time. |
end | str | Period end date/time. |
historical_data_update
Real-time bar update (keep_up_to_date=true).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
bar | Py<PyAny> | Bar data (date, open, high, low, close, volume, wap, bar_count). |
head_timestamp
Earliest available data timestamp.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
head_timestamp | str | Earliest available data timestamp string. |
contract_details
Contract definition details.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract_details | Py<PyAny> |
contract_details_end
End of contract details.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
symbol_samples
Matching symbol search results.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract_descriptions | Py<PyAny> |
tick_by_tick_all_last
Tick-by-tick last trade.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
time | int | Tick timestamp (Unix seconds). |
price | float | Tick price. |
size | float | Tick size. |
tick_attrib_last | Py<PyAny> | |
exchange | str | Exchange name. |
special_conditions | str | Special trade conditions. |
tick_by_tick_bid_ask
Tick-by-tick bid/ask quote.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
time | int | Tick timestamp (Unix seconds). |
bid_price | float | Bid price. |
ask_price | float | Ask price. |
bid_size | float | Bid size. |
ask_size | float | Ask size. |
tick_attrib_bid_ask | Py<PyAny> |
tick_by_tick_mid_point
Tick-by-tick midpoint.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
time | int | Tick timestamp (Unix seconds). |
mid_point | float | Midpoint price. |
scanner_data
Scanner result entry (rank, contract, distance).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
rank | int | Scanner result rank (0-based). |
contract_details | Py<PyAny> | |
distance | str | Scanner distance metric. |
benchmark | str | Scanner benchmark. |
projection | str | Scanner projection. |
legs_str | str | Combo legs description. |
scanner_data_end
End of scanner results.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
scanner_parameters
Scanner parameters XML.
| Parameter | Type | Description |
|---|---|---|
xml | str | XML string. |
news_providers
Available news providers list.
| Parameter | Type | Description |
|---|---|---|
news_providers | Py<PyAny> |
news_article
Full news article text.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
article_type | int | Article type: 0=plain text, 1=HTML. |
article_text | str | Full article body. |
historical_news
Historical news headline.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
time | str | Tick timestamp (Unix seconds). |
provider_code | str | News provider code (e.g. "BRFG"). |
article_id | str | News article identifier. |
headline | str | News headline text. |
historical_news_end
End of historical news.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
has_more | bool | If true, more results available. |
tick_news
Per-contract news tick.
| Parameter | Type | Description |
|---|---|---|
ticker_id | int | Ticker/request ID. |
time_stamp | int | Timestamp string. |
provider_code | str | News provider code (e.g. "BRFG"). |
article_id | str | News article identifier. |
headline | str | News headline text. |
extra_data | str | Additional tick data. |
update_mkt_depth
L2 book update (single exchange).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
position | int | Book position (row index) or position size. |
operation | int | Book operation: 0=insert, 1=update, 2=delete. |
side | int | Book side: 0=ask, 1=bid. Or order side "BOT"/"SLD". |
price | float | Tick price. |
size | float | Tick size. |
update_mkt_depth_l2
L2 book update (with market maker).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
position | int | Book position (row index) or position size. |
market_maker | str | Market maker ID. |
operation | int | Book operation: 0=insert, 1=update, 2=delete. |
side | int | Book side: 0=ask, 1=bid. Or order side "BOT"/"SLD". |
price | float | Tick price. |
size | float | Tick size. |
is_smart_depth | bool | If true, aggregate depth from multiple exchanges via SMART. |
mkt_depth_exchanges
Available exchanges for market depth.
| Parameter | Type | Description |
|---|---|---|
depth_mkt_data_descriptions | Py<PyAny> |
real_time_bar
Real-time 5-second OHLCV bar.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
date | int | Bar date string. |
open | float | Open price. |
high | float | High price. |
low | float | Low price. |
close | float | Close price. |
volume | float | Volume. |
wap | float | Volume-weighted average price. |
count | int | Trade count. |
historical_ticks
Historical tick data (Last, BidAsk, or Midpoint).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
ticks | Py<PyAny> | Historical tick data. |
done | bool | If true, all ticks have been delivered. |
historical_ticks_bid_ask
Historical bid/ask ticks.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
ticks | Py<PyAny> | Historical tick data. |
done | bool | If true, all ticks have been delivered. |
historical_ticks_last
Historical last-trade ticks.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
ticks | Py<PyAny> | Historical tick data. |
done | bool | If true, all ticks have been delivered. |
tick_option_computation
Option implied vol / greeks computation.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tick_type | int | Tick type ID or tick-by-tick type string. |
tick_attrib | int | |
implied_vol | float or None | Implied volatility. |
delta | float or None | Option delta. |
opt_price | float or None | Option theoretical price. |
pv_dividend | float or None | Present value of dividends. |
gamma | float or None | Option gamma. |
vega | float or None | Option vega. |
theta | float or None | Option theta. |
und_price | float or None | Underlying price. |
security_definition_option_parameter
Option chain parameters (strikes, expirations).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
exchange | str | Exchange name. |
underlying_con_id | int | Underlying contract ID. |
trading_class | str | Trading class. |
multiplier | str | Contract multiplier. |
expirations | Py<PyAny> | Available expiration dates. |
strikes | Py<PyAny> | Available strike prices. |
security_definition_option_parameter_end
End of option chain parameters.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
fundamental_data
Fundamental data (XML/JSON).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
data | str | Raw data string (XML/JSON). |
update_news_bulletin
News bulletin message.
| Parameter | Type | Description |
|---|---|---|
msg_id | int | Bulletin message ID. |
msg_type | int | Bulletin message type (1=regular, 2=exchange). |
message | str | Bulletin message text. |
orig_exchange | str | Originating exchange. |
receive_fa
Financial advisor data received.
| Parameter | Type | Description |
|---|---|---|
fa_data_type | int | FA data type (1=Groups, 2=Profiles, 3=Aliases). |
xml | str | XML string. |
replace_fa_end
Financial advisor replace complete.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
text | str | Informational text. |
position_multi
Multi-account position entry.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
pos | float | Position size (decimal shares). |
avg_cost | float | Average cost per share. |
position_multi_end
End of multi-account positions.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account_update_multi
Multi-account value update.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
account | str | Account ID. |
model_code | str | Model portfolio code (empty for default). |
key | str | Account value key (e.g. "NetLiquidation", "BuyingPower"). |
value | str | Account value. |
currency | str | Currency code (e.g. "USD"). |
account_update_multi_end
End of multi-account updates.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
display_group_list
Display group list.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
groups | str | FA group definitions. |
display_group_updated
Display group updated.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract_info | str | Display group contract info string. |
market_rule
Market rule: price increment schedule.
| Parameter | Type | Description |
|---|---|---|
market_rule_id | int | Market rule ID. |
price_increments | Py<PyAny> | Price increment rules [{low_edge, increment}]. |
smart_components
SMART routing component exchanges.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
smart_component_map | Py<PyAny> |
soft_dollar_tiers
Soft dollar tier list.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
tiers | Py<PyAny> | Soft dollar tier list. |
family_codes
Family codes linking related accounts.
| Parameter | Type | Description |
|---|---|---|
family_codes | Py<PyAny> |
histogram_data
Price distribution histogram.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
items | Py<PyAny> | Histogram entries [(price, count)]. |
user_info
User info (white branding ID).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
white_branding_id | str | White branding ID (empty for standard accounts). |
wsh_meta_data
Wall Street Horizon metadata.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
data_json | str |
wsh_event_data
Wall Street Horizon event data.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
data_json | str |
completed_order
Completed (filled/cancelled) order details.
| Parameter | Type | Description |
|---|---|---|
contract | Py<PyAny> | Contract specification (symbol, secType, exchange, currency, etc.). |
order | Py<PyAny> | Order parameters (action, quantity, type, price, TIF, etc.). |
order_state | Py<PyAny> | Order state (status, margin, commission info). |
completed_orders_end
End of completed orders list.
order_bound
Order bound to a perm ID.
| Parameter | Type | Description |
|---|---|---|
order_id | int | Order identifier. Must be unique per session. |
api_client_id | int | |
api_order_id | int |
tick_req_params
Tick parameters: min tick size, BBO exchange, snapshot permissions.
| Parameter | Type | Description |
|---|---|---|
ticker_id | int | Ticker/request ID. |
min_tick | float | Minimum tick size. |
bbo_exchange | str | BBO exchange for smart component lookup (e.g. "SMART"). |
snapshot_permissions | int | Snapshot permissions bitmask. |
bond_contract_details
Bond contract details.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
contract_details | Py<PyAny> |
delta_neutral_validation
Delta-neutral validation response.
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
delta_neutral_contract | Py<PyAny> |
historical_schedule
Historical trading schedule (exchange hours).
| Parameter | Type | Description |
|---|---|---|
req_id | int | Request identifier. Used to match responses to requests. |
start_date_time | str | Start date/time for tick query. |
end_date_time | str | End date/time in "YYYYMMDD HH:MM:SS" format, or empty for now. |
time_zone | str | Timezone string (e.g. "US/Eastern"). |
sessions | Py<PyAny> | Trading sessions [(ref_date, open, close)]. |