Skip to main content

Crate ibapi

Crate ibapi 

Source
Expand description

githubcrates-iolicense


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:

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
ClientBuilder
Builder for an async Client. Acquire via Client::builder.
Notice
An error message from the TWS API.

Enums§

Error
The main error type for IBAPI operations.
IncomingMessages
Messages emitted by TWS/Gateway over the market data socket.
NoticeCategory
Typed classification of a Notice by TWS error-code range.
OutgoingMessages
Outgoing message opcodes understood by TWS/Gateway.
StartupMessage
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 IncomingMessages kind (OpenOrder, OrderStatus, AccountValue/PortfolioValue/AccountUpdateTime/AccountDownloadEnd, ExecutionData, CommissionsReport, CompletedOrder). Distinct from HANDSHAKE_UNKNOWN_FRAME_CODE so consumers can separate TWS schema drift from rust-ibapi decoder bugs. See Notice::is_handshake_synthetic.
HANDSHAKE_UNKNOWN_FRAME_CODE
Synthesized notice code emitted when a handshake-time frame’s IncomingMessages kind has no typed StartupMessage variant. Negative (TWS uses 0+); the only other sentinel in this range is -2 for the gateway-initiated shutdown signal. See Notice::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::connect for the mapping to apply during the connection handshake.