models — Data models¶
All API response types are implemented as Python dataclasses with
from_dict() class methods for JSON parsing.
Enums¶
- class o2_sdk.models.OrderType[source]¶
Type of an order (simple types without additional parameters).
For order types that require additional parameters, use the dedicated dataclasses instead:
LimitOrder(for limit orders with price + timestamp) orBoundedMarketOrder(for bounded market orders with max_price + min_price).- SPOT = "Spot"¶
- MARKET = "Market"¶
- FILL_OR_KILL = "FillOrKill"¶
- POST_ONLY = "PostOnly"¶
Order type parameter classes¶
- class o2_sdk.models.LimitOrder(price, timestamp=None)[source]¶
Limit order with expiry. In
create_order(), price is human-readable and auto-scaled. InCreateOrderAction, price should be the pre-scaled chain integer.
- class o2_sdk.models.BoundedMarketOrder(max_price, min_price)[source]¶
Bounded market order with price bounds. In
create_order(), prices are human-readable and auto-scaled. InCreateOrderAction, prices should be pre-scaled chain integers.
Scalar types¶
- class o2_sdk.models.Id(value)[source]¶
A hex identifier that always displays with a
0xprefix.The O2 API returns hex identifiers inconsistently — sometimes with the
0xprefix and sometimes without.Idnormalizes the value on construction so thatstr(id)always starts with0x, and compares case-insensitively.Idis astrsubclass, so it works transparently in f-strings, comparisons, dict keys, andis not Nonechecks.- Parameters:
value (str) – The hex string, with or without
0xprefix.
>>> from o2_sdk import Id >>> Id("97edbbf5") Id('0x97edbbf5') >>> Id("0x97EDBBF5") Id('0x97edbbf5')
Market models¶
- class o2_sdk.models.Market[source]¶
A trading market (order book) on the O2 Exchange.
- base: MarketAsset¶
The base asset definition.
- quote: MarketAsset¶
The quote asset definition.
- scale_price(human_value)[source]¶
Convert a human-readable price to an on-chain integer, truncated to the market’s
max_precision.
- format_price(chain_value)[source]¶
Convert an on-chain integer price back to a human-readable float.
- format_quantity(chain_value)[source]¶
Convert an on-chain integer quantity to a human-readable float.
- validate_order(price, quantity)[source]¶
Validate scaled price/quantity against on-chain constraints.
Checks:
PricePrecision: price must be a multiple of the truncation factor.
FractionalPrice:
(price * quantity) % 10^base_decimals == 0.min_order: forwarded quote amount must meet the minimum.
- Parameters:
- Raises:
ValueError – If any constraint is violated.
Account models¶
- class o2_sdk.models.Identity[source]¶
Base identity type — either an
Addressor aContractId. UseAddressIdentityorContractIdentityto construct instances directly, orfrom_dict()to parse from API responses.- classmethod from_dict(d)[source]¶
Factory method that returns the appropriate subclass.
- Parameters:
d (dict) – A dict like
{"Address": "0x..."}or{"ContractId": "0x..."}.- Returns:
An
AddressIdentityorContractIdentity.- Return type:
- Raises:
ValueError – If the dict format is not recognized.
- class o2_sdk.models.AddressIdentity(value)[source]¶
Identity for a Fuel Address. Subclass of
Identity.addr = AddressIdentity("0xabc...") addr.to_dict() # {"Address": "0xabc..."} addr.discriminant # 0
- class o2_sdk.models.ContractIdentity(value)[source]¶
Identity for a Fuel ContractId. Subclass of
Identity.contract = ContractIdentity("0xdef...") contract.to_dict() # {"ContractId": "0xdef..."} contract.discriminant # 1
Session models¶
Order models¶
Trade models¶
Balance models¶
Depth models¶
- class o2_sdk.models.DepthSnapshot[source]¶
A snapshot of order book depth.
- buys: list[DepthLevel]¶
Bid (buy) price levels, best first.
- sells: list[DepthLevel]¶
Ask (sell) price levels, best first.
- property best_bid: DepthLevel | None¶
The best (highest) bid price level, or
Noneif the book is empty.
- property best_ask: DepthLevel | None¶
The best (lowest) ask price level, or
Noneif the book is empty.
- class o2_sdk.models.DepthUpdate[source]¶
A real-time depth update from the WebSocket stream.
- changes: DepthSnapshot¶
The depth changes (or full snapshot for the initial message).
Bar models¶
Action response models¶
- class o2_sdk.models.ActionsResponse[source]¶
Response from
POST /v1/session/actions.This is the primary result type returned by trading methods such as
create_order(),cancel_order(), andbatch_actions().- code: int | None¶
Error code (see errors — Error types).
Action input models¶
These dataclasses are the typed inputs for
batch_actions(). Each has a to_dict()
method that serializes to the wire format expected by the API.
- class o2_sdk.models.CreateOrderAction(side, price, quantity, order_type=OrderType.SPOT)[source]¶
Create a new order. Prices and quantities must be pre-scaled on-chain integers passed as strings.
- order_type: OrderType | LimitOrder | BoundedMarketOrder¶
Defaults to
OrderType.SPOT.
- class o2_sdk.models.SettleBalanceAction(to)[source]¶
Settle balance to an identity. Accepts an
Identitysubclass (e.g.ContractIdentity) or anId, which is auto-wrapped asContractIdentityduring serialisation.# Pass session.trade_account_id directly (an Id): SettleBalanceAction(to=session.trade_account_id) # Or pass an explicit Identity: SettleBalanceAction(to=ContractIdentity("0xabc..."))
- class o2_sdk.models.RegisterRefererAction(to)[source]¶
Register a referer. Same auto-wrapping behaviour as
SettleBalanceAction.
- o2_sdk.models.Action¶
Type alias:
CreateOrderAction | CancelOrderAction | SettleBalanceAction | RegisterRefererAction
- class o2_sdk.models.MarketActions(market_id, actions)[source]¶
Groups a list of actions for a specific market. This is the input type for
batch_actions().from o2_sdk import ( CancelOrderAction, CreateOrderAction, SettleBalanceAction, MarketActions, OrderSide, OrderType, ) batch = MarketActions( market_id=market.market_id, actions=[ SettleBalanceAction(to=session.trade_account_id), CreateOrderAction( side=OrderSide.BUY, price=str(scaled_price), quantity=str(scaled_qty), ), ], ) result = await client.batch_actions([batch], collect_orders=True)