api — Low-level REST client¶
The O2Api class provides typed wrappers for every REST endpoint
exposed by the O2 Exchange. All methods return typed response objects and
raise O2Error on failures.
For most use cases, use O2Client instead, which
provides a higher-level interface with automatic market resolution, signing,
and nonce management.
The O2Api instance is accessible on the client as client.api for
advanced use cases.
See also
The O2 Exchange REST API is documented at https://docs.o2.app.
O2Api¶
- class o2_sdk.api.O2Api(config, session=None)[source]¶
Low-level REST API client for the O2 Exchange.
Includes automatic rate-limit handling with exponential backoff retries and network error retries (up to 3 attempts).
- Parameters:
config (
NetworkConfig) – Network configuration.session (aiohttp.ClientSession | None) – Optional
aiohttp.ClientSessionto reuse. IfNone, a new session is created automatically.
Market data endpoints¶
- async O2Api.get_markets()[source]¶
GET /v1/markets— Get all available markets and exchange metadata.- Returns:
Exchange metadata and market definitions.
- Return type:
- async O2Api.get_market_summary(market_id)[source]¶
GET /v1/markets/summary— Get summary data for a market.- Parameters:
market_id (str) – The market ID.
- Return type:
- async O2Api.get_market_ticker(market_id)[source]¶
GET /v1/markets/ticker— Get ticker data for a market.- Parameters:
market_id (str) – The market ID.
- Return type:
- async O2Api.get_depth(market_id, precision=10)[source]¶
GET /v1/depth— Get order book depth snapshot.- Parameters:
- Return type:
- async O2Api.get_trades(market_id, direction='desc', count=50, start_timestamp=None, start_trade_id=None)[source]¶
GET /v1/trades— Get recent trades for a market.- Parameters:
- Return type:
list[
Trade]
- async O2Api.get_trades_by_account(market_id, contract, direction='desc', count=50)[source]¶
GET /v1/trades_by_account— Get trades for a specific account.
Account and balance endpoints¶
- async O2Api.create_account(owner_address)[source]¶
POST /v1/accounts— Create a new trading account.- Parameters:
owner_address (str) – The owner’s B256 address.
- Return type:
- async O2Api.get_account(owner=None, trade_account_id=None)[source]¶
GET /v1/accounts— Get account information.Provide either
owner(B256 address) ortrade_account_id.- Parameters:
- Return type:
Order endpoints¶
- async O2Api.get_orders(market_id, contract=None, account=None, direction='desc', count=20, is_open=None, start_timestamp=None, start_order_id=None)[source]¶
GET /v1/orders— Get orders for a market and account.- Parameters:
market_id (str) – The market ID.
contract (str | None) – The trading account contract ID.
account (str | None) – Alternative account identifier.
direction (str) – Sort direction (
"desc"or"asc").count (int) – Maximum number of orders (default 20).
is_open (bool | None) – Filter by open status (
True/False/None).start_timestamp (int | None) – Pagination cursor.
start_order_id (str | None) – Pagination cursor.
- Return type:
Session endpoints¶
- async O2Api.create_session(owner_id, session_request)[source]¶
PUT /v1/session— Create a new trading session.Sends the
O2-Owner-Idheader with the owner address.- Parameters:
- Return type:
- async O2Api.submit_actions(owner_id, actions_request)[source]¶
POST /v1/session/actions— Submit signed session actions.Sends the
O2-Owner-Idheader. Raisesraise_for_error()on failure.- Parameters:
- Return type:
Account operation endpoints¶
Analytics endpoints¶
- async O2Api.whitelist_account(trade_account_id)[source]¶
POST /analytics/v1/whitelist— Whitelist a trading account.- Parameters:
trade_account_id (str) – The trading account contract ID.
- Return type:
Aggregated endpoints¶
- async O2Api.get_aggregated_assets()[source]¶
GET /v1/aggregated/assets— Get all assets.- Return type:
list[
AggregatedAsset]
- async O2Api.get_aggregated_orderbook(market_pair, depth=500, level=2)[source]¶
GET /v1/aggregated/orderbook— Get aggregated order book.
Faucet endpoints¶
Available on testnet and devnet only.
- async O2Api.mint_to_address(address)[source]¶
Mint test tokens to an address (wallet).