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
impl RestApi
Sourcepub async fn get_tickers<T: AsRef<str>>(
&self,
tickers: &[T],
) -> Result<Vec<Ticker>, Error>
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
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,
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
type Error = ProviderError
Auto Trait Implementations§
impl Freeze for RestApi
impl !RefUnwindSafe for RestApi
impl Send for RestApi
impl Sync for RestApi
impl Unpin for RestApi
impl UnsafeUnpin for RestApi
impl !UnwindSafe for RestApi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request