[][src]Crate cbpro

Coinbase pro async client.

cbpro

This crate provides an easy to use Coinbase Pro API wrapper. For private endpoints use AuthenticatedClient. For public endpoints use PublicClient or AuthenticatedClient::public. All methods belonging to the public or private client will return QueryBuilder which has split implementations per T.

The websocket can be found here: WebSocketFeed. 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::<serde_json::Value>().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::<serde_json::Value>()?;

    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};

#[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.json::<serde_json::Value>().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

Errors of this crate

websocket

Public and private websocket feed

Type Definitions

Pages

Alias representing a stream of json pages