31 releases

0.8.1 Sep 2, 2022
0.7.1 May 31, 2021
0.6.9 Jan 30, 2021
0.6.2 Nov 24, 2020
0.2.8 Nov 13, 2018

#2 in #coinbase

Download history 72/week @ 2024-05-22 132/week @ 2024-05-29 218/week @ 2024-06-05 196/week @ 2024-06-12 177/week @ 2024-06-19 274/week @ 2024-06-26 181/week @ 2024-07-03 266/week @ 2024-07-10 229/week @ 2024-07-17 305/week @ 2024-07-24 232/week @ 2024-07-31 216/week @ 2024-08-07 307/week @ 2024-08-14 236/week @ 2024-08-21 160/week @ 2024-08-28 164/week @ 2024-09-04

912 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

120KB
3K SLoC

Build Status Crates.io Docs.rs

Coinbase pro client for Rust

Supports SYNC/ASYNC/Websocket-feed data support

Features

  • private and public API
  • sync and async support
  • websocket-feed support

Examples

Cargo.toml:

[dependencies]
coinbase-pro-rs = "0.7.1"

Async

use hyper::rt::Future;
use coinbase_pro_rs::{Public, ASync, SANDBOX_URL};

fn main() {
    let client: Public<ASync> = Public::new_with_keep_alive(SANDBOX_URL, false);
    // if keep_alive is not disables - tokio::run will hold the connection without exiting the example
    let f = client.get_time()
        .map_err(|_| ())
        .and_then(|time| {
            println!("Coinbase.time: {}", time.iso);
            Ok(())
        });

    tokio::run(f); // waiting for tokio
}

Sync

use coinbase_pro_rs::{Public, Sync, SANDBOX_URL};

fn main() {
   let client: Public<Sync> = Public::new(SANDBOX_URL);
   let time = client.get_time().unwrap();
   println!("Coinbase.time: {}", time.iso);
}

Websocket

use futures::{Future, Stream};
use coinbase_pro_rs::{WSFeed, WS_SANDBOX_URL};
use coinbase_pro_rs::structs::wsfeed::*;

fn main() {
    let stream = WSFeed::connect(WS_SANDBOX_URL,
        &["BTC-USD"], &[ChannelType::Heartbeat])
        .await
        .unwrap();

    let f = stream
        .take(10)
        .for_each(|msg| {
        match msg {
            Message::Heartbeat {sequence, last_trade_id, time, ..} => println!("{}: seq:{} id{}",
                                                                               time, sequence, last_trade_id),
            Message::Error {message} => println!("Error: {}", message),
            Message::InternalError(_) => panic!("internal_error"),
            other => println!("{:?}", other)
        }
        Ok(())
    });

    tokio::run(f.map_err(|_| panic!("stream fail")));
}

Api supported:

  • SYNC
  • ASYNC
  • Websocket-Feed

API

  • Requests
  • Pagination
  • Types
  • Private
    • Authentication
    • Accounts
    • Orders
    • Fills
    • Deposits
      • List
    • Withdrawals
      • List
    • Payment Methods
    • Coinbase Accounts
    • Fees
    • Reports
    • User Account
  • Market Data
    • Products
    • Currencies
    • Time
  • Websocket Feed
    • heartbeat
    • ticker
    • level2
    • user
    • matches
    • full

FIX API

by request

OrderBook

https://github.com/inv2004/orderbook-rs

Tests

cargo test

Dependencies

~9–22MB
~340K SLoC