pub struct CoinApiHttpClient { /* private fields */ }Expand description
Authenticated, data-only CoinAPI HTTP client.
REST requests return raw protocol models. The single-page historical methods fetch exactly one page; callers must not infer completeness from a full page. The range methods page through a whole window. Range requests run serially so each sizes its pages after earlier ranges settle their credits. Flat Files downloads stream raw bytes to disk without requiring instrument definitions.
Implementations§
Source§impl CoinApiHttpClient
impl CoinApiHttpClient
Sourcepub fn new(
api_key: SecretString,
config: CoinApiHttpConfig,
) -> Result<Self, Error>
pub fn new( api_key: SecretString, config: CoinApiHttpConfig, ) -> Result<Self, Error>
Creates a client using an explicit secret and endpoint configuration.
§Errors
Returns an error if the credentials, endpoint, limits, or transport configuration are invalid.
Sourcepub fn credits_remaining(&self) -> u64
pub fn credits_remaining(&self) -> u64
Returns the remaining conservative local credit allowance.
Sourcepub async fn download_flat_file(
&self,
bucket: &str,
object_key: &str,
filepath: &Path,
) -> Result<(), Error>
pub async fn download_flat_file( &self, bucket: &str, object_key: &str, filepath: &Path, ) -> Result<(), Error>
Downloads one Flat Files object, replacing the destination only after the stream succeeds.
Authentication is automatic. The destination’s parent directories are created as needed. Downloads share this client’s retry, cancellation, proxy, and concurrency controls, and reject redirects. Flat Files usage does not consume the local REST credit allowance.
§Errors
Returns an error if the bucket or object key contains empty or dot segments, the request fails, retry controls stop the download, or a file operation fails.
Sourcepub async fn get_exchanges(
&self,
query: &ExchangesQuery,
) -> Result<Vec<Exchange>, Error>
pub async fn get_exchanges( &self, query: &ExchangesQuery, ) -> Result<Vec<Exchange>, Error>
Retrieves exchange metadata with optional filtering.
§Errors
Returns an error if the request fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_symbols(
&self,
exchange_id: &str,
query: &SymbolsQuery,
) -> Result<Vec<Symbol>, Error>
pub async fn get_symbols( &self, exchange_id: &str, query: &SymbolsQuery, ) -> Result<Vec<Symbol>, Error>
Retrieves active symbols for one exchange.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn request_instruments(
&self,
exchange_id: &str,
query: &SymbolsQuery,
price_precisions: &HashMap<InstrumentId, u8>,
ts_init: UnixNanos,
) -> Result<Vec<CoinApiInstrument>, Error>
pub async fn request_instruments( &self, exchange_id: &str, query: &SymbolsQuery, price_precisions: &HashMap<InstrumentId, u8>, ts_init: UnixNanos, ) -> Result<Vec<CoinApiInstrument>, Error>
Loads native instruments from the active symbols of one exchange.
Only spot, perpetual, and futures symbols are parsed. Symbols of those types that cannot
be mapped to a native instrument are logged and skipped. An instrument listed in
price_precisions takes that price precision instead of the CoinAPI price resolution.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails. Validation rejects a price precision beyond the Nautilus maximum.
Sourcepub async fn get_book(
&self,
symbol_id: &str,
query: &BookQuery,
) -> Result<Book, Error>
pub async fn get_book( &self, symbol_id: &str, query: &BookQuery, ) -> Result<Book, Error>
Retrieves a current L2 market-by-price book for one symbol.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_book_l3(
&self,
symbol_id: &str,
query: &BookQuery,
) -> Result<Book, Error>
pub async fn get_book_l3( &self, symbol_id: &str, query: &BookQuery, ) -> Result<Book, Error>
Retrieves a current L3 market-by-order book for one symbol.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_quotes(
&self,
symbol_id: &str,
query: &HistoryQuery,
) -> Result<Vec<Quote>, Error>
pub async fn get_quotes( &self, symbol_id: &str, query: &HistoryQuery, ) -> Result<Vec<Quote>, Error>
Retrieves one historical quote page with an explicit window and limit.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_quotes_range(
&self,
symbol_id: &str,
range: &HistoryRange,
) -> Result<HistoryPages<Quote>, Error>
pub async fn get_quotes_range( &self, symbol_id: &str, range: &HistoryRange, ) -> Result<HistoryPages<Quote>, Error>
Retrieves historical quotes across a window, ordered and paged by time_exchange.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, decoding fails, or response ordering fails.
Sourcepub async fn get_trades(
&self,
symbol_id: &str,
query: &TradesQuery,
) -> Result<Vec<Trade>, Error>
pub async fn get_trades( &self, symbol_id: &str, query: &TradesQuery, ) -> Result<Vec<Trade>, Error>
Retrieves one historical trade page with an explicit window and limit.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_trades_range(
&self,
symbol_id: &str,
range: &HistoryRange,
) -> Result<HistoryPages<Trade>, Error>
pub async fn get_trades_range( &self, symbol_id: &str, range: &HistoryRange, ) -> Result<HistoryPages<Trade>, Error>
Retrieves historical trades across a window, ordered and paged by time_exchange.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, decoding fails, or response ordering fails.
Sourcepub async fn get_ohlcv(
&self,
symbol_id: &str,
query: &OhlcvQuery,
) -> Result<Vec<Ohlcv>, Error>
pub async fn get_ohlcv( &self, symbol_id: &str, query: &OhlcvQuery, ) -> Result<Vec<Ohlcv>, Error>
Retrieves one historical OHLCV page for the requested period.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, or decoding fails.
Sourcepub async fn get_ohlcv_range(
&self,
symbol_id: &str,
period_id: OhlcvPeriod,
range: &HistoryRange,
) -> Result<HistoryPages<Ohlcv>, Error>
pub async fn get_ohlcv_range( &self, symbol_id: &str, period_id: OhlcvPeriod, range: &HistoryRange, ) -> Result<HistoryPages<Ohlcv>, Error>
Retrieves OHLCV periods starting within a window, ordered and paged by
time_period_start.
§Errors
Returns an error if validation fails, the credit budget is exhausted, the transport or HTTP request fails, decoding fails, or response ordering fails.