Expand description
A comprehensive Rust implementation of the Interactive Brokers TWS API, providing a robust and user-friendly interface for TWS and IB Gateway. Designed with simplicity in mind, it integrates smoothly into trading systems.
API Documentation:
- TWS API Reference - Detailed technical documentation
- IBKR Campus - IB’s official learning platform
This fully featured API enables the retrieval of account information, access to real-time and historical market data, order management, market scanning, and access to news and Wall Street Horizons (WSH) event data. Future updates will focus on bug fixes, maintaining parity with the official API, and enhancing usability.
§Example
Connect to TWS / IB Gateway and place a market order:
use ibapi::prelude::*;
#[tokio::main]
async fn main() {
let client = Client::connect("127.0.0.1:4002", 100)
.await
.expect("connection failed");
let contract = Contract::stock("AAPL").build();
let order_id = client
.order(&contract)
.buy(100)
.market()
.submit()
.await
.expect("order submission failed");
println!("submitted order id: {order_id}");
}For broader usage — quick start, examples, migration from v2, full API tour — see the
README and the
docs/ directory.
Modules§
- accounts
- Describes items present in an account.
- client
- TWS API Client.
- contracts
- A Contract object represents trading instruments such as a stocks, futures or options.
- display_
groups - Display groups subscription support
- errors
- Error types for the IBAPI library.
- fundamental
- APIs for retrieving fundamental data reports (Reuters: snapshot, financial summary, ratios, etc.). Fundamental company data: financial summaries, snapshots, ratios, and analyst estimates retrieved from Interactive Brokers.
- market_
data - APIs for retrieving market data Market data types and functionality
- news
- APIs for retrieving news data including articles, bulletins, and providers News data retrieval and management functionality.
- orders
- Data types for building and placing orders.
- prelude
- A prelude module for convenient importing of commonly used types. A prelude module for convenient importing of commonly used types and traits.
- protocol
- Protocol version checking and constants for TWS API features. Protocol version checking and constants for TWS API features.
- scanner
- APIs for working with the market scanner. Market scanner functionality for discovering trading opportunities.
- subscriptions
- Subscription types for streaming data Subscription types for sync/async streaming data.
- trace
- Server interaction tracing for debugging and monitoring Server interaction tracing for debugging and monitoring
- wsh
- APIs for working with Wall Street Horizon: Earnings Calendar & Event Data. Wall Street Horizon: Earnings Calendar & Event Data.
Structs§
- Client
- Asynchronous TWS API Client
- Client
Builder - Builder for an async
Client. Acquire viaClient::builder. - Notice
- An error message from the TWS API.
Enums§
- Error
- The main error type for IBAPI operations.
- Incoming
Messages - Messages emitted by TWS/Gateway over the market data socket.
- Notice
Category - Typed classification of a
Noticeby TWS error-code range. - Outgoing
Messages - Outgoing message opcodes understood by TWS/Gateway.
- Startup
Message - Typed handshake-time messages delivered to
ClientBuilder::startup_callback.
Constants§
- DATA_
ADVISORY_ CODES - Data-advisory codes that TWS sends on a request which then proceeds normally. The request is not rejected — the advisory announces a fallback (delayed market data) and the requested data follows, so these are informational notices, not errors. Classifying them as errors would terminate the subscription before its data arrives.
- HANDSHAKE_
DECODE_ FAILURE_ CODE - Synthesized notice code emitted when a typed handshake decoder fails for
a known
IncomingMessageskind (OpenOrder,OrderStatus,AccountValue/PortfolioValue/AccountUpdateTime/AccountDownloadEnd,ExecutionData,CommissionsReport,CompletedOrder). Distinct fromHANDSHAKE_UNKNOWN_FRAME_CODEso consumers can separate TWS schema drift from rust-ibapi decoder bugs. SeeNotice::is_handshake_synthetic. - HANDSHAKE_
UNKNOWN_ FRAME_ CODE - Synthesized notice code emitted when a handshake-time frame’s
IncomingMessageskind has no typedStartupMessagevariant. Negative (TWS uses 0+); the only other sentinel in this range is-2for the gateway-initiated shutdown signal. SeeNotice::is_handshake_synthetic. - ORDER_
CANCELLED_ CODE - Error code indicating an order was cancelled (confirmation, not an error).
- ORDER_
REJECTION_ CODE_ RANGE - Range of error codes that represent order rejections from TWS (200-399).
- SYSTEM_
MESSAGE_ CODES - System message codes indicating connectivity status.
- WARNING_
CODE_ RANGE - Range of error codes that are considered warnings (2100-2169).
Functions§
- register_
timezone_ alias - Register a custom mapping from a gateway-supplied timezone name to an IANA
zone. Call before
Client::connectfor the mapping to apply during the connection handshake.