Skip to main content

Account

Struct Account 

Source
pub struct Account<'a, T> { /* private fields */ }
Expand description

Accessor for the authenticated account endpoints.

Obtain one via OkxClient::account. All methods require credentials; calling them without credentials returns Error::Configuration.

Implementations§

Source§

impl<'a, T: Transport> Account<'a, T>

Source

pub async fn get_balance( &self, ccy: Option<&str>, ) -> Result<Vec<AccountBalance>, Error>

Retrieve the trading-account balance.

GET /api/v5/account/balance. Authenticated. Pass ccy to filter to one or more comma-separated currencies (e.g. Some("BTC,USDT")). The result is a single AccountBalance.

§Errors

Returns Error::Configuration if no credentials are set, Error::Api on a non-zero OKX code, or transport/decode errors.

Source

pub async fn get_positions( &self, inst_type: Option<InstType>, inst_id: Option<&str>, ) -> Result<Vec<Position>, Error>

Retrieve open positions.

GET /api/v5/account/positions. Authenticated. Both filters are optional; omit them to return all positions.

§Errors

See get_balance.

Source

pub async fn get_position_risk( &self, inst_type: Option<InstType>, ) -> Result<Vec<PositionRisk>, Error>

Retrieve account position risk.

GET /api/v5/account/account-position-risk. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_account_config(&self) -> Result<Vec<AccountConfig>, Error>

Retrieve account configuration.

GET /api/v5/account/config. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_account_bills( &self, request: &BillsRequest, ) -> Result<Vec<AccountBill>, Error>

Retrieve recent account bills.

GET /api/v5/account/bills. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_account_bills_archive( &self, request: &BillsArchiveRequest, ) -> Result<Vec<AccountBill>, Error>

Retrieve archived account bills.

GET /api/v5/account/bills-archive. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_position_mode( &self, pos_mode: &str, ) -> Result<Vec<SetPositionModeResult>, Error>

Set the account position mode.

POST /api/v5/account/set-position-mode. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_leverage( &self, request: &SetLeverageRequest, ) -> Result<Vec<LeverageInfo>, Error>

Set leverage for an instrument or currency.

POST /api/v5/account/set-leverage. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_leverage( &self, request: &LeverageRequest, ) -> Result<Vec<LeverageInfo>, Error>

Retrieve leverage settings.

GET /api/v5/account/leverage-info. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_max_order_size( &self, request: &MaxOrderSizeRequest, ) -> Result<Vec<MaxOrderSize>, Error>

Retrieve maximum tradable size for an instrument.

GET /api/v5/account/max-size. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_max_avail_size( &self, request: &MaxAvailableSizeRequest, ) -> Result<Vec<MaxAvailableSize>, Error>

Retrieve maximum available size for an instrument.

GET /api/v5/account/max-avail-size. Authenticated.

§Errors

See get_balance.

Source

pub async fn adjust_margin( &self, request: &AdjustMarginRequest, ) -> Result<Vec<AdjustMarginResult>, Error>

Increase or decrease margin for a position.

POST /api/v5/account/position/margin-balance. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_fee_rates( &self, request: &FeeRatesRequest, ) -> Result<Vec<FeeRate>, Error>

Retrieve trade fee rates.

GET /api/v5/account/trade-fee. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_account_instruments( &self, request: &AccountInstrumentsRequest, ) -> Result<Vec<AccountInstrument>, Error>

Retrieve account-available instruments.

GET /api/v5/account/instruments. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_max_loan( &self, request: &MaxLoanRequest, ) -> Result<Vec<MaxLoan>, Error>

Retrieve the maximum loan amount.

GET /api/v5/account/max-loan. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_interest_accrued( &self, request: &InterestAccruedRequest, ) -> Result<Vec<InterestAccrued>, Error>

Retrieve interest-accrued records.

GET /api/v5/account/interest-accrued. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_interest_rate( &self, ccy: Option<&str>, ) -> Result<Vec<InterestRate>, Error>

Retrieve interest rates.

GET /api/v5/account/interest-rate. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_greeks( &self, greeks_type: &str, ) -> Result<Vec<SetGreeksResult>, Error>

Set the greeks display type.

POST /api/v5/account/set-greeks. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_isolated_mode( &self, iso_mode: &str, mode_type: &str, ) -> Result<Vec<SetIsolatedModeResult>, Error>

Set isolated margin transfer mode.

POST /api/v5/account/set-isolated-mode. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_max_withdrawal( &self, ccy: Option<&str>, ) -> Result<Vec<MaxWithdrawal>, Error>

Retrieve maximum withdrawal amounts.

GET /api/v5/account/max-withdrawal. Authenticated.

§Errors

See get_balance.

Source

pub async fn borrow_repay( &self, request: &BorrowRepayRequest, ) -> Result<Vec<BorrowRepayResult>, Error>

Borrow or repay margin.

POST /api/v5/account/borrow-repay. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_borrow_repay_history( &self, request: &BorrowRepayHistoryRequest, ) -> Result<Vec<BorrowRepayHistory>, Error>

Retrieve borrow/repay history.

GET /api/v5/account/borrow-repay-history. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_interest_limits( &self, request: &InterestLimitsRequest, ) -> Result<Vec<InterestLimit>, Error>

Retrieve borrowing rate and limit information.

GET /api/v5/account/interest-limits. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_simulated_margin( &self, request: &SimulatedMarginRequest, ) -> Result<Vec<SimulatedMargin>, Error>

Calculate simulated margin information.

POST /api/v5/account/simulated_margin. Authenticated. This is separate from OkxClientBuilder::demo_trading, which only toggles the OKX simulated-trading header.

§Errors

See get_balance.

Source

pub async fn get_greeks(&self, ccy: Option<&str>) -> Result<Vec<Greek>, Error>

Retrieve greeks.

GET /api/v5/account/greeks. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_positions_history( &self, request: &PositionsHistoryRequest, ) -> Result<Vec<PositionHistory>, Error>

Retrieve position history.

GET /api/v5/account/positions-history. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_account_position_tiers( &self, request: &AccountPositionTiersRequest, ) -> Result<Vec<AccountPositionTier>, Error>

Retrieve account position tiers.

GET /api/v5/account/position-tiers. Authenticated.

§Errors

See get_balance.

Source

pub async fn get_risk_state(&self) -> Result<Vec<RiskState>, Error>

Retrieve the account risk state.

GET /api/v5/account/risk-state. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_risk_offset_type( &self, risk_offset_type: &str, ) -> Result<Vec<SetRiskOffsetTypeResult>, Error>

Set account risk offset type.

POST /api/v5/account/set-riskOffset-type. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_auto_loan( &self, auto_loan: bool, ) -> Result<Vec<SetAutoLoanResult>, Error>

Set account auto-loan mode.

POST /api/v5/account/set-auto-loan. Authenticated.

§Errors

See get_balance.

Source

pub async fn set_account_level( &self, acct_lv: &str, ) -> Result<Vec<SetAccountLevelResult>, Error>

Set the account level.

POST /api/v5/account/set-account-level. Authenticated.

§Errors

See get_balance.

Source

pub async fn activate_option(&self) -> Result<Vec<ActivateOptionResult>, Error>

Activate option trading.

POST /api/v5/account/activate-option. Authenticated.

§Errors

See get_balance.

Source

pub async fn position_builder( &self, request: &PositionBuilderRequest, ) -> Result<Vec<PositionBuilderResult>, Error>

Build simulated positions and equity.

POST /api/v5/account/position-builder. Authenticated.

§Errors

See get_balance.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Account<'a, T>

§

impl<'a, T> RefUnwindSafe for Account<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Account<'a, T>
where T: Sync,

§

impl<'a, T> Sync for Account<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Account<'a, T>

§

impl<'a, T> UnsafeUnpin for Account<'a, T>

§

impl<'a, T> UnwindSafe for Account<'a, T>
where T: RefUnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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, 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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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