Skip to main content

RestApi

Struct RestApi 

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

A client for interacting with the Bitfinex REST API.

The RestApi provides methods to fetch ticker data from the Bitfinex API and implements the AssetInfoProvider trait for integration with asset workers.

§Examples

use bothan_bitfinex::api::rest::RestApi;
use reqwest::Client;
use url::Url;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url = Url::parse("https://api-pub.bitfinex.com/v2/").unwrap();
    let client = Client::new();
    let api = RestApi::new(url, client);

    // Fetch ticker data for specific symbols
    let tickers = vec!["tBTCUSD", "tETHUSD"];
    let result = api.get_tickers(&tickers).await?;
    Ok(())
}

Implementations§

Source§

impl RestApi

Source

pub fn new(url: Url, client: Client) -> Self

Creates a new RestApi instance with the specified URL and HTTP client.

§Parameters
  • url: The base URL for the Bitfinex API
  • client: The HTTP client for making requests
§Returns

A new RestApi instance configured with the provided URL and client.

Source

pub async fn get_tickers<T: AsRef<str>>( &self, tickers: &[T], ) -> Result<Vec<Ticker>, Error>

Fetches ticker data for the specified symbols from the Bitfinex API.

This method makes a REST API call to the Bitfinex tickers endpoint to retrieve current market data for the specified trading pairs. The response includes both spot and funding ticker information depending on the symbol type.

§Parameters
  • tickers: A slice of symbol identifiers to fetch ticker data for
§Returns

Returns a Result containing a vector of Ticker instances on success, or a reqwest::Error if the request fails.

§Examples
use bothan_bitfinex::api::rest::RestApi;
use reqwest::Client;
use url::Url;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url = Url::parse("https://api-pub.bitfinex.com/v2/").unwrap();
    let client = Client::new();
    let api = RestApi::new(url, client);

    let symbols = vec!["tBTCUSD", "fUSD"];
    let tickers = api.get_tickers(&symbols).await?;

    for ticker in tickers {
        println!("Symbol: {}, Price: {}", ticker.symbol(), ticker.price());
    }

    Ok(())
}
§Errors

Returns a reqwest::Error if:

  • The HTTP request fails due to network issues
  • The API returns an error response
  • The response cannot be parsed as JSON

Trait Implementations§

Source§

impl AssetInfoProvider for RestApi

Source§

fn get_asset_info<'life0, 'life1, 'async_trait>( &'life0 self, ids: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<Vec<AssetInfo>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetches asset information for the specified asset IDs.

This method retrieves ticker data from the Bitfinex API for the given asset IDs and transforms the data into AssetInfo instances for use in asset workers. The method handles both spot and funding ticker types automatically.

§Parameters
  • ids: A slice of asset identifiers to fetch information for
§Returns

Returns a Result containing a vector of AssetInfo instances on success, or a ProviderError if the request fails or contains invalid data.

§Errors

Returns a ProviderError if:

  • The API request fails (RequestError)
  • The ticker data contains invalid values such as NaN (InvalidValue)
Source§

type Error = ProviderError

The type returned in the event of an operation failure. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, 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> ErasedDestructor for T
where T: 'static,