v_exchanges_api_generics 0.19.3

A client for HTTP/HTTPS/WebSocket APIs.
Documentation
#![warn(future_incompatible, let_underscore, nonstandard_style)] //, missing_docs)]
#![feature(slice_pattern)]
#![feature(default_field_values)]
#![feature(error_generic_member_access)]
#![feature(try_blocks)]
#![feature(duration_constructors)]
#![allow(clippy::result_large_err)]

//! # Generic-API-Client
//! This is a crate for interacting with HTTP/HTTPS/WebSocket APIs.
//! It is named "generic" because you can use the **same** client to interact with **multiple different**
//! APIs with, different authentication methods, data formats etc.
//!
//! This crate  provides
//! - [Client][http::Client] A HTTP/HTTPS client
//! - [WebSocketConnection][websocket::WebSocketConnection] A `struct` to manage WebSocket connections
//! - [RequestHandler][http::RequestHandler] A `trait` for implementing features like authentication on your requests
//! - [WebSocketHandler][websocket::WebSocketHandler] A `trait` that is used to handle messages etc.. for a WebSocket Connection.
//!
//! For a more detailed documentation, see the links above.

use std::backtrace::Backtrace;

pub mod http;
pub mod ratelimiter;
pub mod retry;
pub mod ws;

pub use ratelimiter::{RateLimiter, quota::Quota};

pub use retry::{ExponentialBackoff, RetryConfig, RetryManager};
pub extern crate reqwest;
pub extern crate tokio_tungstenite;

#[derive(Debug, miette::Diagnostic, thiserror::Error, derive_new::new)]
#[non_exhaustive]
pub enum ConstructAuthError {
	#[error("missing API public key")]
	#[diagnostic(code(v_exchanges::auth::missing_pubkey), help("Provide API public key in your credentials"))]
	MissingPubkey {
		#[new(value = "Backtrace::capture()")]
		backtrace: Backtrace,
	},
	#[error("missing API secret key")]
	#[diagnostic(code(v_exchanges::auth::missing_secret), help("Provide API secret key in your credentials"))]
	MissingSecret {
		#[new(value = "Backtrace::capture()")]
		backtrace: Backtrace,
	},
	#[error("invalid character in API key: {key}")]
	#[diagnostic(code(v_exchanges::auth::invalid_api_key))]
	InvalidCharacterInApiKey {
		key: String,
		#[new(value = "Backtrace::capture()")]
		backtrace: Backtrace,
	},
	#[error(transparent)]
	Other(eyre::Report),
}

#[derive(Debug, miette::Diagnostic, thiserror::Error)]
pub enum UrlError {
	#[error("Failed to parse URL: {0}")]
	#[diagnostic(code(v_exchanges::url::parse))]
	Parse(#[from] url::ParseError),
	#[error("Exchange does not provide testnet for requested endpoint: {0}")]
	#[diagnostic(
		code(v_exchanges::url::missing_testnet),
		help("Not all exchanges provide testnet endpoints. Check if this exchange supports testnet for this specific API.")
	)]
	MissingTestnet(url::Url),
}