Skip to main content

AxRawHttpClient

Struct AxRawHttpClient 

Source
pub struct AxRawHttpClient { /* private fields */ }
Expand description

Raw HTTP client for low-level AX Exchange API operations.

This client handles request/response operations with the AX Exchange API, returning venue-specific response types. It does not parse to Nautilus domain types.

Implementations§

Source§

impl AxRawHttpClient

Source

pub fn base_url(&self) -> &str

Returns the base URL for this client.

Source

pub fn api_key_masked(&self) -> String

Returns a masked version of the API key for logging purposes.

Source

pub fn cancel_all_requests(&self)

Cancel all pending HTTP requests.

Source

pub fn reset_cancellation_token(&self)

Replaces the cancelled token so new requests can proceed after reconnect.

Source

pub fn cancellation_token(&self) -> CancellationToken

Get a clone of the current cancellation token.

Source

pub fn new( base_url: Option<String>, orders_base_url: Option<String>, timeout_secs: u64, max_retries: u32, retry_delay_ms: u64, retry_delay_max_ms: u64, proxy_url: Option<String>, ) -> Result<Self, AxHttpError>

Creates a new AxRawHttpClient using the default Ax HTTP URL.

§Errors

Returns an error if the retry manager cannot be created.

Source

pub fn with_credentials( api_key: String, api_secret: String, base_url: Option<String>, orders_base_url: Option<String>, timeout_secs: u64, max_retries: u32, retry_delay_ms: u64, retry_delay_max_ms: u64, proxy_url: Option<String>, ) -> Result<Self, AxHttpError>

Creates a new AxRawHttpClient configured with credentials.

§Errors

Returns an error if the HTTP client cannot be created.

Source

pub fn set_session_token(&self, token: String)

Sets the session token for authenticated requests.

The session token is obtained through the login flow and used for bearer token authentication.

Source

pub async fn get_whoami(&self) -> Result<AxWhoAmI, AxHttpError>

Fetches the current authenticated user information.

§Endpoint

GET /whoami

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_instruments( &self, ) -> Result<AxInstrumentsResponse, AxHttpError>

Fetches all available instruments.

§Endpoint

GET /instruments

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_balances(&self) -> Result<AxBalancesResponse, AxHttpError>

Fetches all account balances for the authenticated user.

§Endpoint

GET /balances

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_positions(&self) -> Result<AxPositionsResponse, AxHttpError>

Fetches all open positions for the authenticated user.

§Endpoint

GET /positions

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_tickers(&self) -> Result<AxTickersResponse, AxHttpError>

Fetches all tickers.

§Endpoint

GET /tickers

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_tickers_with_params( &self, params: &GetTickersParams, ) -> Result<AxTickersResponse, AxHttpError>

Fetches tickers with optional pagination and sorting.

§Endpoint

GET /tickers

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_ticker(&self, symbol: Ustr) -> Result<AxTicker, AxHttpError>

Fetches a single ticker by symbol.

§Endpoint

GET /ticker?symbol=<symbol>

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_instrument( &self, symbol: Ustr, ) -> Result<AxInstrument, AxHttpError>

Fetches a single instrument by symbol.

§Endpoint

GET /instrument?symbol=<symbol>

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn authenticate( &self, api_key: &str, api_secret: &str, expiration_seconds: i32, ) -> Result<AxAuthenticateResponse, AxHttpError>

Authenticates using API key and secret to obtain a session token.

§Endpoint

POST /authenticate

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn authenticate_auto( &self, expiration_seconds: i32, ) -> Result<AxAuthenticateResponse, AxHttpError>

Authenticates using stored credentials or environment variables.

§Credential Resolution

Credentials are resolved in the following order:

  1. Stored credentials (from with_credentials constructor)
  2. Environment variables (AX_API_KEY and AX_API_SECRET)
§Errors

Returns an error if:

  • No credentials are available from either source
  • The HTTP request fails
  • The credentials are invalid
Source

pub async fn place_order( &self, request: &PlaceOrderRequest, ) -> Result<AxPlaceOrderResponse, AxHttpError>

Places a new order.

§Endpoint

POST /place-order (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn cancel_order( &self, order_id: &str, ) -> Result<AxCancelOrderResponse, AxHttpError>

Cancels an existing order.

§Endpoint

POST /cancel-order (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn replace_order( &self, request: &ReplaceOrderRequest, ) -> Result<AxReplaceOrderResponse, AxHttpError>

Replaces (amends) an existing order.

The exchange cancels the original order and creates a new one with the updated fields. Unspecified optional fields inherit from the original.

§Endpoint

POST /replace-order (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn cancel_all_orders( &self, request: &CancelAllOrdersRequest, ) -> Result<AxCancelAllOrdersResponse, AxHttpError>

Cancels all open orders, optionally filtered by account or symbol.

§Endpoint

POST /cancel-all-orders (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_open_orders(&self) -> Result<AxOpenOrdersResponse, AxHttpError>

Fetches all open orders.

§Endpoint

GET /open-orders (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_open_orders_page( &self, params: &GetOpenOrdersParams, ) -> Result<AxOpenOrdersResponse, AxHttpError>

Fetches one page of open orders.

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_fills( &self, start_timestamp_ns: i64, end_timestamp_ns: i64, ) -> Result<AxFillsResponse, AxHttpError>

Fetches the default page of fills/trades.

§Endpoint

GET /fills

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_fills_page( &self, params: &GetFillsParams, ) -> Result<AxFillsResponse, AxHttpError>

Fetches one page of fills/trades.

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_candles( &self, symbol: Ustr, start_timestamp_ns: i64, end_timestamp_ns: i64, candle_width: AxCandleWidth, ) -> Result<AxCandlesResponse, AxHttpError>

Fetches historical candles.

§Endpoint

GET /candles

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_current_candle( &self, symbol: Ustr, candle_width: AxCandleWidth, ) -> Result<AxCandle, AxHttpError>

Fetches the current (incomplete) candle.

§Endpoint

GET /candles/current

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_last_candle( &self, symbol: Ustr, candle_width: AxCandleWidth, ) -> Result<AxCandle, AxHttpError>

Fetches the last completed candle.

§Endpoint

GET /candles/last

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_funding_rates( &self, symbol: Ustr, start_timestamp_ns: i64, end_timestamp_ns: i64, ) -> Result<AxFundingRatesResponse, AxHttpError>

Fetches the default page of funding rates for a symbol.

§Endpoint

GET /funding-rates

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_funding_rates_page( &self, params: &GetFundingRatesParams, ) -> Result<AxFundingRatesResponse, AxHttpError>

Fetches one page of funding rates for a symbol.

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_funding_slots( &self, params: &GetFundingSlotsParams, ) -> Result<AxFundingSlotsResponse, AxHttpError>

Fetches the funding-slot schedule for a symbol on a trading day.

§Endpoint

GET /funding-slots

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_risk_snapshot( &self, ) -> Result<AxRiskSnapshotResponse, AxHttpError>

Fetches the current risk snapshot.

§Endpoint

GET /risk-snapshot

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn preview_aggressive_limit_order( &self, request: &PreviewAggressiveLimitOrderRequest, ) -> Result<AxPreviewAggressiveLimitOrderResponse, AxHttpError>

Previews an aggressive limit order to get the “take through” price.

This endpoint calculates the price needed to sweep the order book for a given quantity, which is used to simulate market orders on AX (which only supports limit orders natively).

§Endpoint

POST /preview-aggressive-limit-order

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_transactions( &self, transaction_types: Vec<String>, start_timestamp_ns: i64, end_timestamp_ns: i64, ) -> Result<AxTransactionsResponse, AxHttpError>

Fetches the default page of transactions filtered by type.

§Endpoint

GET /transactions

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_transactions_page( &self, params: &GetTransactionsParams, ) -> Result<AxTransactionsResponse, AxHttpError>

Fetches one page of transactions.

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_trades( &self, symbol: Ustr, limit: Option<i32>, ) -> Result<AxTradesResponse, AxHttpError>

Fetches recent trades for a symbol.

§Endpoint

GET /trades

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_book( &self, symbol: Ustr, level: Option<i32>, ) -> Result<AxBookResponse, AxHttpError>

Fetches an order book snapshot for a symbol.

§Endpoint

GET /book

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_order_status_by_id( &self, order_id: &str, ) -> Result<AxOrderStatusQueryResponse, AxHttpError>

Fetches the status of a single order by order ID.

§Endpoint

GET /order-status (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_order_status_by_cid( &self, client_order_id: u64, ) -> Result<AxOrderStatusQueryResponse, AxHttpError>

Fetches the status of a single order by client order ID.

§Endpoint

GET /order-status (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn get_orders( &self, params: &GetOrdersParams, ) -> Result<AxOrdersResponse, AxHttpError>

Fetches historical orders with optional filters.

§Endpoint

GET /orders (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Source

pub async fn check_initial_margin( &self, request: &PlaceOrderRequest, ) -> Result<AxInitialMarginRequirementResponse, AxHttpError>

Checks the initial margin requirement for a proposed order.

§Endpoint

POST /initial-margin-requirement (orders base URL)

§Errors

Returns an error if the request fails or the response cannot be parsed.

Trait Implementations§

Source§

impl Debug for AxRawHttpClient

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AxRawHttpClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

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
§

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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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<T> Ungil for T
where T: Send,

§

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