Skip to main content

ExchangeClient

Struct ExchangeClient 

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

A client that fetches market data from a specific exchange.

All methods return Option and never panic; network or parse errors are silently mapped to None so callers can retry or fall back.

Implementations§

Source§

impl ExchangeClient

Source

pub fn new(exchange: Exchange) -> Self

Create a client for the given exchange.

Source

pub fn binance() -> Self

Convenience constructor for Binance.

Source

pub fn coingecko() -> Self

Convenience constructor for CoinGecko.

Source

pub fn fetch_candles( &self, symbol: &str, interval: &str, limit: usize, ) -> Option<Vec<Candle>>

Fetch OHLCV kline candles.

  • Binancesymbol is a trading pair like "BTCUSDT", interval is a Binance interval string ("1m", "5m", "1h", "1d", …), and limit is the number of candles (max 1000).

  • CoinGeckosymbol is the coin id (e.g. "bitcoin"), interval is interpreted as the number of days of history ("1", "7", "30", "365"), and limit is currently unused (the API decides granularity from days).

Source

pub fn fetch_prices( &self, symbol: &str, interval: &str, limit: usize, ) -> Option<Vec<Point>>

Fetch close prices as Points suitable for line charts.

Each point has x = timestamp (seconds) and y = close price.

  • Binance – uses klines; x is the candle open time.
  • CoinGecko – uses the market_chart endpoint which returns price samples at varying resolution depending on days.
Source

pub fn fetch_spot_price(&self, symbol: &str) -> Option<f64>

Fetch the current spot (last traded) price.

  • Binance – uses /api/v3/ticker/price.
  • CoinGecko – uses /api/v3/simple/price.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V