coinbase-rs

Crates.iocoinbase-rs
lib.rscoinbase-rs
version0.4.0
sourcesrc
created_at2019-07-16 01:29:49.423852
updated_at2023-12-08 12:58:15.83928
descriptionCoinbase client for Rust
homepage
repositoryhttps://github.com/j16r/coinbase-rs
max_upload_size
id149305
size77,210
John Barker (j16r)

documentation

README

Coinbase Client for Rust

Actions Status

This is a Rust client for interacting with the Coinbase API. It works with version 2019-04-03 (v2) of the API. This is not compatible with the Coinbase Pro API.

Features

  • Private and Public API
  • Pagination through streams

Examples

Cargo.toml:

[dependencies]
coinbase-rs = "0.3.0"

Public API

use coinbase_rs::{Public, MAIN_URL};

#[tokio::main]
async fn main() {
    let client = Public::new(MAIN_URL);
    println!("Server time is {:?}", client.current_time().await.unwrap());
}

Private API

use coinbase_rs::{Private, MAIN_URL, Uuid};
use futures::pin_mut;
use futures::stream::StreamExt;
use std::str::FromStr;

pub const KEY: &str = "<put key here>";
pub const SECRET: &str = "<put secret here>";

#[tokio::main]
async fn main() {
    let client = Private::new(MAIN_URL, KEY, SECRET);

    let accounts = client.accounts();
    pin_mut!(accounts);

    while let Some(account_result) = accounts.next().await {
        for account in account_result.unwrap() {
            println!("Account {}", account.currency.code);
            if let Ok(id) = Uuid::from_str(&account.id) {
                let transactions = client.transactions(&id);
                pin_mut!(transactions);

                while let Some(transactions_result) = transactions.next().await {
                    for transaction in transactions_result.unwrap() {
                        println!(
                            "Transaction {} = {}",
                            transaction.id, transaction.amount.amount
                        );
                    }
                }
            }
        }
    }
}

Thanks

This project is inspired and borrows heavily from coinbase-pro-rs.

Commit count: 87

cargo fmt