[−][src]Crate cbpro
Coinbase pro async client.
cbpro
This crate provides an easy to use Coinbase Pro binding interface.
For private endpoints use AuthenticatedClient. For public endpoints use PublicClient or AuthenticatedClient::public.
All methods beloging to the public or private client will return QueryBuilder
Get basic feed connection at WebSocketFeed::connect or the authenticated connection at WebSocketFeed::connect_auth. For more details on Coinbase Pro go to: https://docs.pro.coinbase.com.
Examples
Async Client
use cbpro::client::{PublicClient, SANDBOX_URL}; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let client = PublicClient::new(SANDBOX_URL); let products = client.get_products().json().await?; println!("{}", serde_json::to_string_pretty(&products).unwrap()); Ok(()) }
Async Pagination
use cbpro::client::{PublicClient, SANDBOX_URL}; use futures::TryStreamExt; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let client = PublicClient::new(SANDBOX_URL); let mut pages = client.get_trades("BTC-USD").paginate()?; while let Some(json) = pages.try_next().await? { println!("{}", serde_json::to_string_pretty(&json).unwrap()); tokio::time::delay_for(core::time::Duration::new(1, 0)).await; } Ok(()) }
Async Websocket
use cbpro::websocket::{Channels, WebSocketFeed, SANDBOX_FEED_URL}; use futures::TryStreamExt; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let mut feed = WebSocketFeed::connect(SANDBOX_FEED_URL).await?; feed.subscribe(&["BTC-USD"], &[Channels::LEVEL2]).await?; while let Some(value) = feed.try_next().await? { println!("{}", serde_json::to_string_pretty(&value).unwrap()); } Ok(()) }
Re-exports
pub use self::client::AuthenticatedClient; |
pub use self::client::PublicClient; |
pub use self::websocket::WebSocketFeed; |
Modules
builder | Builder and types representing optional methods |
client | Public and private clients |
error | cbpro errors |
websocket | Public and private websocket feed |
Type Definitions
Pages | Alias representing a stream of json pages |