OstiumClient

Struct OstiumClient 

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

Main client for interacting with the Ostium platform

Implementations§

Source§

impl OstiumClient

Source

pub fn builder(network: Network) -> OstiumClientBuilder

Create a new client builder for the specified network

Source

pub fn builder_with_config(config: NetworkConfig) -> OstiumClientBuilder

Create a new client builder with custom configuration

Source

pub async fn new(network: Network) -> Result<Self>

Create a new client with default configuration (no signer)

Source

pub fn config(&self) -> &NetworkConfig

Get the network configuration

Source

pub fn signer_address(&self) -> Option<Address>

Get the signer address if available

Source

pub fn has_signer(&self) -> bool

Check if the client has a signer configured

Source

pub fn map_contract_error( &self, error: &str, ) -> (String, String, HashMap<String, String>)

Maps Ethereum contract error selectors to human-readable messages

This function takes a contract error and attempts to decode it into a more meaningful error message based on known Ostium contract error selectors.

§Arguments
  • error - The error object or string containing the contract error
§Returns

A tuple containing (error_message, error_type, error_data)

Source

pub fn extract_error_selector(&self, error: &str) -> Option<String>

Extracts error selector (0x + 8 hex chars) from error message

Source

pub fn get_error_description(&self, selector: &str) -> Option<&'static str>

Get human-readable error message for a specific error selector

Source

pub fn map_contract_error_with_suggestions( &self, error: &str, ) -> (String, String, HashMap<String, String>, Option<String>)

Enhanced error mapping that includes suggestions for common issues

Source

pub async fn get_minimum_position_size(&self, symbol: &str) -> Result<Decimal>

Get minimum position size for a given symbol Returns the minimum position size in the base asset units

Source

pub async fn validate_trading_constraints( &self, symbol: &str, side: PositionSide, size: Decimal, leverage: Decimal, ) -> Result<()>

Validate trading constraints before executing a trade Checks: 1) Trading hours, 2) Minimum position size, 3) Open interest caps

Source§

impl OstiumClient

Source

pub async fn open_position(&self, params: OpenPositionParams) -> Result<TxHash>

Open a new trading position

Source

pub async fn close_position( &self, params: ClosePositionParams, ) -> Result<TxHash>

Close an existing position

Source

pub async fn update_tp_sl(&self, params: UpdateTPSLParams) -> Result<TxHash>

Update take profit and stop loss for a position

Source

pub async fn open_position_unsigned( &self, params: OpenPositionParams, trader_address: Address, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for opening a position

Source

pub async fn close_position_unsigned( &self, params: ClosePositionParams, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for closing a position

Source

pub async fn update_tp_sl_unsigned( &self, params: UpdateTPSLParams, tx_params: UnsignedTransactionParams, ) -> Result<Vec<UnsignedTransaction>>

Build unsigned transactions for updating TP/SL

Source

pub async fn place_advanced_order_unsigned( &self, params: AdvancedOrderParams, trader_address: Address, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for placing an advanced order

Source

pub async fn cancel_order_unsigned( &self, params: CancelOrderParams, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for canceling an order

Source§

impl OstiumClient

Source

pub async fn place_advanced_order( &self, params: AdvancedOrderParams, ) -> Result<TxHash>

Place an advanced order (market, limit, or stop)

Source

pub async fn place_limit_order( &self, params: LimitOrderParams, ) -> Result<TxHash>

Place a limit order

Source

pub async fn place_stop_order(&self, params: StopOrderParams) -> Result<TxHash>

Place a stop order

Source

pub async fn cancel_order(&self, params: CancelOrderParams) -> Result<TxHash>

Cancel an open limit or stop order

Source

pub async fn update_limit_order( &self, params: UpdateLimitOrderParams, ) -> Result<TxHash>

Update an existing limit order

Source

pub async fn validate_order_price( &self, symbol: &str, order_type: OrderExecutionType, price: Decimal, ) -> Result<bool>

Get current market price for validation purposes

Source§

impl OstiumClient

Source

pub async fn get_pairs(&self) -> Result<Vec<TradingPair>>

Get all available trading pairs

Source

pub async fn get_price(&self, symbol: &str) -> Result<Price>

Get current price for a trading pair

Source

pub async fn get_trading_hours(&self, symbol: &str) -> Result<TradingHours>

Get trading hours for a symbol

Source§

impl OstiumClient

Source

pub async fn get_balance(&self, address: Option<Address>) -> Result<Balance>

Get account balance

Source

pub async fn get_positions( &self, address: Option<Address>, ) -> Result<Vec<Position>>

Get open positions for an account

Source

pub async fn get_orders(&self, address: Option<Address>) -> Result<Vec<Order>>

Get open orders for an account

Trait Implementations§

Source§

impl AccountApi for OstiumClient

Source§

async fn get_balance(&self, address: Option<Address>) -> Result<Balance>

Get account balance
Source§

async fn get_positions(&self, address: Option<Address>) -> Result<Vec<Position>>

Get open positions
Source§

async fn get_orders(&self, address: Option<Address>) -> Result<Vec<Order>>

Get open orders
Source§

impl AdvancedOrderApi for OstiumClient

Source§

async fn place_advanced_order( &self, params: AdvancedOrderParams, ) -> Result<TxHash>

Place an advanced order (market, limit, or stop)
Source§

async fn place_limit_order(&self, params: LimitOrderParams) -> Result<TxHash>

Place a limit order
Source§

async fn place_stop_order(&self, params: StopOrderParams) -> Result<TxHash>

Place a stop order
Source§

async fn cancel_order(&self, params: CancelOrderParams) -> Result<TxHash>

Cancel an open order
Source§

async fn update_limit_order( &self, params: UpdateLimitOrderParams, ) -> Result<TxHash>

Update an existing limit order
Source§

async fn validate_order_price( &self, symbol: &str, order_type: OrderExecutionType, price: Decimal, ) -> Result<bool>

Validate order price against current market
Source§

impl Clone for OstiumClient

Source§

fn clone(&self) -> OstiumClient

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 MarketDataApi for OstiumClient

Source§

async fn get_pairs(&self) -> Result<Vec<TradingPair>>

Get all trading pairs
Source§

async fn get_price(&self, symbol: &str) -> Result<Price>

Get price for a symbol
Source§

async fn get_trading_hours(&self, symbol: &str) -> Result<TradingHours>

Get trading hours for a symbol
Source§

impl TradingApi for OstiumClient

Source§

async fn open_position(&self, params: OpenPositionParams) -> Result<TxHash>

Open a new position
Source§

async fn close_position(&self, params: ClosePositionParams) -> Result<TxHash>

Close an existing position
Source§

async fn update_tp_sl(&self, params: UpdateTPSLParams) -> Result<TxHash>

Update take profit and stop loss
Source§

impl UnsignedTransactionApi for OstiumClient

Source§

async fn open_position_unsigned( &self, params: OpenPositionParams, trader_address: Address, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for opening a position
Source§

async fn close_position_unsigned( &self, params: ClosePositionParams, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for closing a position
Source§

async fn update_tp_sl_unsigned( &self, params: UpdateTPSLParams, tx_params: UnsignedTransactionParams, ) -> Result<Vec<UnsignedTransaction>>

Build unsigned transactions for updating TP/SL
Source§

async fn place_advanced_order_unsigned( &self, params: AdvancedOrderParams, trader_address: Address, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for placing an advanced order
Source§

async fn cancel_order_unsigned( &self, params: CancelOrderParams, tx_params: UnsignedTransactionParams, ) -> Result<UnsignedTransaction>

Build unsigned transaction for canceling an order

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

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> 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> 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
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> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,