O2Api

Struct O2Api 

Source
pub struct O2Api {
    client: Client,
    config: NetworkConfig,
}
Expand description

Low-level REST API client for the O2 Exchange.

Fields§

§client: Client§config: NetworkConfig

Implementations§

Source§

impl O2Api

Source

const VALID_RESOLUTIONS: &'static [&'static str]

Valid bar resolutions accepted by the API.

Source

pub fn new(config: NetworkConfig) -> Self

Create a new API client with the given network configuration.

Source

async fn parse_response<T: DeserializeOwned>( &self, response: Response, ) -> Result<T, O2Error>

Parse an API response, detecting error codes and returning typed errors.

Source

pub async fn get_markets(&self) -> Result<MarketsResponse, O2Error>

GET /v1/markets - List all markets.

Source

pub async fn get_market_summary( &self, market_id: &str, ) -> Result<Vec<MarketSummary>, O2Error>

GET /v1/markets/summary - 24-hour market statistics.

Source

pub async fn get_market_ticker( &self, market_id: &str, ) -> Result<Vec<MarketTicker>, O2Error>

GET /v1/markets/ticker - Real-time ticker data.

Source

pub async fn get_depth( &self, market_id: &str, precision: u64, limit: Option<usize>, ) -> Result<DepthSnapshot, O2Error>

GET /v1/depth - Order book depth.

Source

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.

Source

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.

Source

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.

Source

pub async fn create_account( &self, owner_address: &str, ) -> Result<CreateAccountResponse, O2Error>

POST /v1/accounts - Create a trading account.

Source

pub async fn get_account_by_owner( &self, owner: &str, ) -> Result<AccountResponse, O2Error>

GET /v1/accounts - Get account info by owner address.

Source

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.

Source

pub async fn get_balance( &self, asset_id: &str, contract: Option<&str>, address: Option<&str>, ) -> Result<BalanceResponse, O2Error>

GET /v1/balance - Get asset balance.

Source

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.

Source

pub async fn get_order( &self, market_id: &str, order_id: &str, ) -> Result<Order, O2Error>

GET /v1/order - Get a single order.

Source

pub async fn create_session( &self, owner_id: &str, request: &SessionRequest, ) -> Result<SessionResponse, O2Error>

PUT /v1/session - Create or update a trading session.

Source

pub(crate) async fn submit_actions( &self, owner_id: &str, request: &SessionActionsRequest, ) -> Result<SessionActionsResponse, O2Error>

POST /v1/session/actions - Execute trading actions.

Source

pub async fn withdraw( &self, owner_id: &str, request: &WithdrawRequest, ) -> Result<WithdrawResponse, O2Error>

POST /v1/accounts/withdraw - Withdraw assets.

Source

pub async fn whitelist_account( &self, trade_account_id: &str, ) -> Result<WhitelistResponse, O2Error>

POST /analytics/v1/whitelist - Whitelist a trading account.

Source

pub async fn get_referral_info( &self, code: &str, ) -> Result<ReferralInfo, O2Error>

GET /analytics/v1/referral/code-info - Look up referral code.

Source

pub async fn get_aggregated_assets(&self) -> Result<AggregatedAssets, O2Error>

GET /v1/aggregated/assets - List all trading assets.

Source

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.

Source

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.

Source

pub async fn get_aggregated_summary(&self) -> Result<Vec<PairSummary>, O2Error>

GET /v1/aggregated/summary - 24-hour stats for all pairs.

Source

pub async fn get_aggregated_ticker(&self) -> Result<AggregatedTicker, O2Error>

GET /v1/aggregated/ticker - Real-time ticker for all pairs.

Source

pub async fn get_aggregated_coingecko_tickers( &self, ) -> Result<Vec<PairTicker>, O2Error>

GET /v1/aggregated/coingecko/tickers - CoinGecko ticker format.

Source

pub async fn get_aggregated_trades( &self, market_pair: &str, ) -> Result<Vec<AggregatedTrade>, O2Error>

GET /v1/aggregated/trades - Recent trades for a pair.

Source

pub async fn mint_to_address( &self, address: &str, ) -> Result<FaucetResponse, O2Error>

Mint tokens to a wallet address via the faucet (testnet/devnet only).

Source

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).

Trait Implementations§

Source§

impl Clone for O2Api

Source§

fn clone(&self) -> O2Api

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for O2Api

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for O2Api

§

impl !RefUnwindSafe for O2Api

§

impl Send for O2Api

§

impl Sync for O2Api

§

impl Unpin for O2Api

§

impl !UnwindSafe for O2Api

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more