Coder Social home page Coder Social logo

coinbase-rs's Introduction

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.

coinbase-rs's People

Contributors

j16r avatar mvines avatar agentydragon avatar tarcieri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.