pub struct O2Api {
client: Client,
config: NetworkConfig,
}Expand description
Low-level REST API client for the O2 Exchange.
Fields§
§client: Client§config: NetworkConfigImplementations§
Source§impl O2Api
impl O2Api
Sourceconst VALID_RESOLUTIONS: &'static [&'static str]
const VALID_RESOLUTIONS: &'static [&'static str]
Valid bar resolutions accepted by the API.
Sourcepub fn new(config: NetworkConfig) -> Self
pub fn new(config: NetworkConfig) -> Self
Create a new API client with the given network configuration.
Sourceasync fn parse_response<T: DeserializeOwned>(
&self,
response: Response,
) -> Result<T, O2Error>
async fn parse_response<T: DeserializeOwned>( &self, response: Response, ) -> Result<T, O2Error>
Parse an API response, detecting error codes and returning typed errors.
Sourcepub async fn get_markets(&self) -> Result<MarketsResponse, O2Error>
pub async fn get_markets(&self) -> Result<MarketsResponse, O2Error>
GET /v1/markets - List all markets.
Sourcepub async fn get_market_summary(
&self,
market_id: &str,
) -> Result<Vec<MarketSummary>, O2Error>
pub async fn get_market_summary( &self, market_id: &str, ) -> Result<Vec<MarketSummary>, O2Error>
GET /v1/markets/summary - 24-hour market statistics.
Sourcepub async fn get_market_ticker(
&self,
market_id: &str,
) -> Result<Vec<MarketTicker>, O2Error>
pub async fn get_market_ticker( &self, market_id: &str, ) -> Result<Vec<MarketTicker>, O2Error>
GET /v1/markets/ticker - Real-time ticker data.
Sourcepub async fn get_depth(
&self,
market_id: &str,
precision: u64,
limit: Option<usize>,
) -> Result<DepthSnapshot, O2Error>
pub async fn get_depth( &self, market_id: &str, precision: u64, limit: Option<usize>, ) -> Result<DepthSnapshot, O2Error>
GET /v1/depth - Order book depth.
Sourcepub async fn get_trades(
&self,
market_id: &str,
direction: &str,
count: u32,
start_timestamp: Option<u64>,
start_trade_id: Option<&str>,
contract: Option<&str>,
) -> Result<TradesResponse, O2Error>
pub async fn get_trades( &self, market_id: &str, direction: &str, count: u32, start_timestamp: Option<u64>, start_trade_id: Option<&str>, contract: Option<&str>, ) -> Result<TradesResponse, O2Error>
GET /v1/trades - Recent trade history.
Sourcepub async fn get_trades_by_account(
&self,
market_id: &str,
contract: &str,
direction: &str,
count: u32,
start_timestamp: Option<u64>,
start_trade_id: Option<&str>,
) -> Result<TradesResponse, O2Error>
pub async fn get_trades_by_account( &self, market_id: &str, contract: &str, direction: &str, count: u32, start_timestamp: Option<u64>, start_trade_id: Option<&str>, ) -> Result<TradesResponse, O2Error>
GET /v1/trades_by_account - Trades by account.
Sourcepub async fn get_bars(
&self,
market_id: &str,
from_ts: u64,
to_ts: u64,
resolution: &str,
) -> Result<Vec<Bar>, O2Error>
pub async fn get_bars( &self, market_id: &str, from_ts: u64, to_ts: u64, resolution: &str, ) -> Result<Vec<Bar>, O2Error>
GET /v1/bars - OHLCV candlestick data.
from_ts and to_ts are in milliseconds (not seconds).
resolution must be one of: 1s, 1m, 2m, 3m, 5m, 15m, 30m,
1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M, 3M.
Sourcepub async fn create_account(
&self,
owner_address: &str,
) -> Result<CreateAccountResponse, O2Error>
pub async fn create_account( &self, owner_address: &str, ) -> Result<CreateAccountResponse, O2Error>
POST /v1/accounts - Create a trading account.
Sourcepub async fn get_account_by_owner(
&self,
owner: &str,
) -> Result<AccountResponse, O2Error>
pub async fn get_account_by_owner( &self, owner: &str, ) -> Result<AccountResponse, O2Error>
GET /v1/accounts - Get account info by owner address.
Sourcepub async fn get_account_by_id(
&self,
trade_account_id: &str,
) -> Result<AccountResponse, O2Error>
pub async fn get_account_by_id( &self, trade_account_id: &str, ) -> Result<AccountResponse, O2Error>
GET /v1/accounts - Get account info by trade_account_id.
Sourcepub async fn get_balance(
&self,
asset_id: &str,
contract: Option<&str>,
address: Option<&str>,
) -> Result<BalanceResponse, O2Error>
pub async fn get_balance( &self, asset_id: &str, contract: Option<&str>, address: Option<&str>, ) -> Result<BalanceResponse, O2Error>
GET /v1/balance - Get asset balance.
Sourcepub async fn get_orders(
&self,
market_id: &str,
contract: &str,
direction: &str,
count: u32,
is_open: Option<bool>,
start_timestamp: Option<u64>,
start_order_id: Option<&str>,
) -> Result<OrdersResponse, O2Error>
pub async fn get_orders( &self, market_id: &str, contract: &str, direction: &str, count: u32, is_open: Option<bool>, start_timestamp: Option<u64>, start_order_id: Option<&str>, ) -> Result<OrdersResponse, O2Error>
GET /v1/orders - Get order history.
Sourcepub async fn get_order(
&self,
market_id: &str,
order_id: &str,
) -> Result<Order, O2Error>
pub async fn get_order( &self, market_id: &str, order_id: &str, ) -> Result<Order, O2Error>
GET /v1/order - Get a single order.
Sourcepub async fn create_session(
&self,
owner_id: &str,
request: &SessionRequest,
) -> Result<SessionResponse, O2Error>
pub async fn create_session( &self, owner_id: &str, request: &SessionRequest, ) -> Result<SessionResponse, O2Error>
PUT /v1/session - Create or update a trading session.
Sourcepub(crate) async fn submit_actions(
&self,
owner_id: &str,
request: &SessionActionsRequest,
) -> Result<SessionActionsResponse, O2Error>
pub(crate) async fn submit_actions( &self, owner_id: &str, request: &SessionActionsRequest, ) -> Result<SessionActionsResponse, O2Error>
POST /v1/session/actions - Execute trading actions.
Sourcepub async fn withdraw(
&self,
owner_id: &str,
request: &WithdrawRequest,
) -> Result<WithdrawResponse, O2Error>
pub async fn withdraw( &self, owner_id: &str, request: &WithdrawRequest, ) -> Result<WithdrawResponse, O2Error>
POST /v1/accounts/withdraw - Withdraw assets.
Sourcepub async fn whitelist_account(
&self,
trade_account_id: &str,
) -> Result<WhitelistResponse, O2Error>
pub async fn whitelist_account( &self, trade_account_id: &str, ) -> Result<WhitelistResponse, O2Error>
POST /analytics/v1/whitelist - Whitelist a trading account.
Sourcepub async fn get_referral_info(
&self,
code: &str,
) -> Result<ReferralInfo, O2Error>
pub async fn get_referral_info( &self, code: &str, ) -> Result<ReferralInfo, O2Error>
GET /analytics/v1/referral/code-info - Look up referral code.
Sourcepub async fn get_aggregated_assets(&self) -> Result<AggregatedAssets, O2Error>
pub async fn get_aggregated_assets(&self) -> Result<AggregatedAssets, O2Error>
GET /v1/aggregated/assets - List all trading assets.
Sourcepub async fn get_aggregated_orderbook(
&self,
market_pair: &str,
depth: u32,
level: u32,
) -> Result<AggregatedOrderbook, O2Error>
pub async fn get_aggregated_orderbook( &self, market_pair: &str, depth: u32, level: u32, ) -> Result<AggregatedOrderbook, O2Error>
GET /v1/aggregated/orderbook - Order book depth by pair name.
Sourcepub async fn get_aggregated_coingecko_orderbook(
&self,
ticker_id: &str,
depth: u32,
) -> Result<CoingeckoAggregatedOrderbook, O2Error>
pub async fn get_aggregated_coingecko_orderbook( &self, ticker_id: &str, depth: u32, ) -> Result<CoingeckoAggregatedOrderbook, O2Error>
GET /v1/aggregated/coingecko/orderbook - CoinGecko orderbook depth by ticker ID.
Sourcepub async fn get_aggregated_summary(&self) -> Result<Vec<PairSummary>, O2Error>
pub async fn get_aggregated_summary(&self) -> Result<Vec<PairSummary>, O2Error>
GET /v1/aggregated/summary - 24-hour stats for all pairs.
Sourcepub async fn get_aggregated_ticker(&self) -> Result<AggregatedTicker, O2Error>
pub async fn get_aggregated_ticker(&self) -> Result<AggregatedTicker, O2Error>
GET /v1/aggregated/ticker - Real-time ticker for all pairs.
Sourcepub async fn get_aggregated_coingecko_tickers(
&self,
) -> Result<Vec<PairTicker>, O2Error>
pub async fn get_aggregated_coingecko_tickers( &self, ) -> Result<Vec<PairTicker>, O2Error>
GET /v1/aggregated/coingecko/tickers - CoinGecko ticker format.
Sourcepub async fn get_aggregated_trades(
&self,
market_pair: &str,
) -> Result<Vec<AggregatedTrade>, O2Error>
pub async fn get_aggregated_trades( &self, market_pair: &str, ) -> Result<Vec<AggregatedTrade>, O2Error>
GET /v1/aggregated/trades - Recent trades for a pair.
Sourcepub async fn mint_to_address(
&self,
address: &str,
) -> Result<FaucetResponse, O2Error>
pub async fn mint_to_address( &self, address: &str, ) -> Result<FaucetResponse, O2Error>
Mint tokens to a wallet address via the faucet (testnet/devnet only).
Sourcepub async fn mint_to_contract(
&self,
contract_id: &str,
) -> Result<FaucetResponse, O2Error>
pub async fn mint_to_contract( &self, contract_id: &str, ) -> Result<FaucetResponse, O2Error>
Mint tokens directly to a trading account contract via the faucet (testnet/devnet only).