The active trading session, or null if no session has been created.
Enables await using client = new O2Client(...).
Submit a batch of type-safe actions grouped by market.
This is the primary batch interface. Actions use the Action union with dual-mode Numeric values — string decimals are auto-scaled, bigint values pass through directly.
Market resolution, price/quantity scaling, FractionalPrice adjustment, min_order validation, and accounts registry lookup are all handled internally.
Groups of actions per market.
Whether to return order details in response (default: false).
Cancel all open orders for a market. Returns one result per chunk, or null if no orders.
Cancel an order. The session nonce is updated in-place.
Close all connections and release resources.
Create an order with automatic encoding, signing, and nonce management.
Price and quantity accept dual-mode Numeric values:
string — human-readable decimal (e.g., "0.02", "100") — auto-scaledbigint — raw chain integer (e.g., 20000000n) — pass-throughMarket pair string or Market object.
Order side ("buy" or "sell").
Order price as decimal string or raw bigint.
Order quantity as decimal string or raw bigint.
Optionaloptions: CreateOrderOptionsOptional order parameters.
Create a trading session.
The trade account ID is resolved automatically from the wallet address.
Disconnect WebSocket if connected.
Get balances for a trade account, keyed by symbol.
Fetch the order book depth snapshot.
Market pair string or Market object.
Price grouping level, from 1 (most precise) to 18
(most grouped). Default 1. At level 1, prices are at or near their
exact values. Higher levels round prices into larger buckets — useful
for a visual depth chart but too coarse for trading. Same scale as
streamDepth.
Optionallimit: numberMaximum number of price levels per side (bids/asks).
undefined (default) returns the full order book.
Fetch all available markets. Results are cached with stale-while-revalidate.
Fetch the current on-chain nonce for a trading account.
The trade account contract ID.
Fetch orders for an account on a market.
Market pair string or Market object.
The trade account contract ID.
OptionalisOpen: booleanFilter by open/closed status.
Number of orders (default: 20, max 200).
Optionalcursor: { startOrderId: string; startTimestamp: number }Optional pagination cursor. Pass the timestamp and order_id
from the last order of the previous page.
Fetch real-time ticker data for a market.
Fetch recent trades for a market.
Market pair string or Market object.
Number of trades to return (default: 50, max 50).
Optionalaccount: string | TradeAccountIdOptional trade account ID to filter trades for a specific account.
Optionalcursor: { startTimestamp: number; startTradeId: string }Optional pagination cursor. Pass the timestamp and trade_id
from the last trade of the previous page.
Restore a pre-existing session (e.g., from serialized state).
Settle balance for a market. The session nonce is updated in-place.
Idempotent account setup. Safe to call on every bot startup.
Stream real-time balance updates for a trading account.
The trade account contract ID.
An async generator yielding BalanceUpdate messages.
Stream real-time order book depth updates.
An async generator yielding DepthUpdate messages.
Stream WebSocket connection lifecycle events.
Yields ConnectionEvent objects whenever the connection state changes (connected, disconnected, reconnecting, reconnected, closed).
Use this to detect reconnects and re-sync critical state from the REST API — messages during the disconnect window are lost.
Stream real-time nonce updates for a trading account.
The trade account contract ID.
An async generator yielding NonceUpdate messages.
Stream real-time order updates for a trading account.
The trade account contract ID.
An async generator yielding OrderUpdate messages.
Stream real-time trades for a market.
An async generator yielding TradeUpdate messages.
Mint test assets from faucet directly to the owner's trading account contract.
This is useful for explicit testnet/devnet top-ups after account setup.
The owner wallet.
Faucet mint response.
O2Error if no trade account exists or faucet is unavailable.
StaticgenerateGenerate a new EVM-compatible secp256k1 wallet.
A new wallet state with EVM address and zero-padded b256 address.
StaticgenerateGenerate a new Fuel-native secp256k1 wallet.
A new wallet state with a random private key.
StaticloadLoad an EVM-compatible wallet from a private key hex string.
The private key as a 0x-prefixed hex string.
The loaded wallet state with EVM address.
StaticloadLoad a Fuel-native wallet from a private key hex string.
The private key as a 0x-prefixed hex string.
The loaded wallet state.
The underlying low-level REST API client.