pub struct BaseExchange {
pub config: ExchangeConfig,
pub http_client: HttpClient,
pub market_cache: Arc<RwLock<MarketCache>>,
pub market_loading_lock: Arc<Mutex<()>>,
pub capabilities: ExchangeCapabilities,
pub urls: HashMap<String, String>,
pub timeframes: HashMap<String, String>,
pub precision_mode: PrecisionMode,
}Expand description
Base exchange implementation
Fields§
§config: ExchangeConfigExchange configuration
http_client: HttpClientHTTP client for API requests
market_cache: Arc<RwLock<MarketCache>>Thread-safe market data cache
market_loading_lock: Arc<Mutex<()>>Mutex to serialize market loading operations
capabilities: ExchangeCapabilitiesExchange capability flags
urls: HashMap<String, String>API endpoint URLs
timeframes: HashMap<String, String>Timeframe mappings
precision_mode: PrecisionModePrecision mode for price/amount formatting
Implementations§
Source§impl BaseExchange
impl BaseExchange
Sourcepub fn new(config: ExchangeConfig) -> Result<BaseExchange, Error>
pub fn new(config: ExchangeConfig) -> Result<BaseExchange, Error>
Creates a new exchange instance
Sourcepub async fn load_markets(
&self,
reload: bool,
) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
pub async fn load_markets( &self, reload: bool, ) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
Loads market data from the exchange
Sourcepub async fn load_markets_with_loader<F, Fut>(
&self,
reload: bool,
loader: F,
) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
pub async fn load_markets_with_loader<F, Fut>( &self, reload: bool, loader: F, ) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
Loads market data with a custom loader function
Sourcepub async fn set_markets(
&self,
markets: Vec<Market>,
currencies: Option<Vec<Currency>>,
) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
pub async fn set_markets( &self, markets: Vec<Market>, currencies: Option<Vec<Currency>>, ) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
Sets market and currency data in the cache
Sourcepub async fn market(&self, symbol: &str) -> Result<Arc<Market>, Error>
pub async fn market(&self, symbol: &str) -> Result<Arc<Market>, Error>
Gets market information by trading symbol
Sourcepub async fn market_by_id(&self, id: &str) -> Result<Arc<Market>, Error>
pub async fn market_by_id(&self, id: &str) -> Result<Arc<Market>, Error>
Gets market information by exchange-specific market ID
Sourcepub async fn currency(&self, code: &str) -> Result<Arc<Currency>, Error>
pub async fn currency(&self, code: &str) -> Result<Arc<Currency>, Error>
Gets currency information by currency code
Sourcepub fn throttle(&self) -> Result<(), Error>
👎Deprecated since 0.2.0: Rate limiting is now handled internally by HttpClient. This method is a no-op.
pub fn throttle(&self) -> Result<(), Error>
Applies rate limiting if enabled (deprecated, now handled by HttpClient)
Sourcepub fn check_required_credentials(&self) -> Result<(), Error>
pub fn check_required_credentials(&self) -> Result<(), Error>
Checks that required API credentials are configured
Sourcepub fn build_query_string(&self, params: &HashMap<String, Value>) -> String
pub fn build_query_string(&self, params: &HashMap<String, Value>) -> String
Builds a URL query string from parameters
Sourcepub fn handle_http_error(&self, status_code: u16, response: &str) -> Error
pub fn handle_http_error(&self, status_code: u16, response: &str) -> Error
Handles HTTP error responses
Sourcepub fn safe_string(&self, dict: &Value, key: &str) -> Option<String>
pub fn safe_string(&self, dict: &Value, key: &str) -> Option<String>
Safely extracts a string value from a JSON object
Sourcepub fn safe_integer(&self, dict: &Value, key: &str) -> Option<i64>
pub fn safe_integer(&self, dict: &Value, key: &str) -> Option<i64>
Safely extracts an integer value from a JSON object
Sourcepub fn safe_float(&self, dict: &Value, key: &str) -> Option<f64>
pub fn safe_float(&self, dict: &Value, key: &str) -> Option<f64>
Safely extracts a float value from a JSON object
Sourcepub fn safe_bool(&self, dict: &Value, key: &str) -> Option<bool>
pub fn safe_bool(&self, dict: &Value, key: &str) -> Option<bool>
Safely extracts a boolean value from a JSON object
Sourcepub fn parse_ticker(
&self,
ticker_data: &Value,
market: Option<&Market>,
) -> Result<Ticker, Error>
pub fn parse_ticker( &self, ticker_data: &Value, market: Option<&Market>, ) -> Result<Ticker, Error>
Parses raw ticker data from exchange API response
Sourcepub fn parse_trade(
&self,
trade_data: &Value,
market: Option<&Market>,
) -> Result<Trade, Error>
pub fn parse_trade( &self, trade_data: &Value, market: Option<&Market>, ) -> Result<Trade, Error>
Parses raw trade data from exchange API response
Sourcepub fn parse_order(
&self,
order_data: &Value,
market: Option<&Market>,
) -> Result<Order, Error>
pub fn parse_order( &self, order_data: &Value, market: Option<&Market>, ) -> Result<Order, Error>
Parses raw order data from exchange API response
Sourcepub fn parse_balance(&self, balance_data: &Value) -> Result<Balance, Error>
pub fn parse_balance(&self, balance_data: &Value) -> Result<Balance, Error>
Parses raw balance data from exchange API response
Sourcepub fn parse_order_book(
&self,
orderbook_data: &Value,
timestamp: Option<i64>,
) -> Result<OrderBook, Error>
pub fn parse_order_book( &self, orderbook_data: &Value, timestamp: Option<i64>, ) -> Result<OrderBook, Error>
Parses raw order book data from exchange API response
Sourcepub async fn calculate_fee(
&self,
symbol: &str,
_order_type: OrderType,
_side: OrderSide,
amount: Decimal,
price: Decimal,
taker_or_maker: Option<&str>,
) -> Result<Fee, Error>
pub async fn calculate_fee( &self, symbol: &str, _order_type: OrderType, _side: OrderSide, amount: Decimal, price: Decimal, taker_or_maker: Option<&str>, ) -> Result<Fee, Error>
Calculates trading fee for a given order
Sourcepub async fn amount_to_precision(
&self,
symbol: &str,
amount: Decimal,
) -> Result<Decimal, Error>
pub async fn amount_to_precision( &self, symbol: &str, amount: Decimal, ) -> Result<Decimal, Error>
Converts an amount to the precision required by the market
Sourcepub async fn price_to_precision(
&self,
symbol: &str,
price: Decimal,
) -> Result<Decimal, Error>
pub async fn price_to_precision( &self, symbol: &str, price: Decimal, ) -> Result<Decimal, Error>
Converts a price to the precision required by the market
Trait Implementations§
Source§impl Clone for BaseExchange
impl Clone for BaseExchange
Source§fn clone(&self) -> BaseExchange
fn clone(&self) -> BaseExchange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more