Skip to content

soerenmartius/coinapi-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coinapi-rs

Unofficial CoinAPI Rust SDK for the Coinapi.io

Build Status MIT licensed

Welcome to the unofficial CoinAPI Rust SDK. This repository contain SDK for our CoinAPI's documented at https://docs.coinapi.io/

To-Do

General

  • Error handling with Failure
  • Implement Log
  • Lazy load collections
  • Implement tests

API Implementation Status

  • REST API
    • General
      • Authorization
      • Output data format
    • Metadata
      • List all exchanges
      • List all assets
      • List all symbols
    • Exchanges rates
      • Get specific rate
      • Get all current rates
    • OHLCV
      • List all periods
      • Latest data
      • Historical Data
    • Trades
      • Current data
      • Latest data
      • Historical data
    • Quotes
      • Current data
      • Latest data
      • Historical data
    • Order book
      • Current data
      • Latest data
      • Historical data
    • Subscription
  • WebSocket API
    • General
      • Hello
    • Messages
      • Trades
      • Quotes
      • Book
      • Book5
      • Book20
      • Book50
      • Heartbeat
  • FIX API
    • Login (A)
    • Logout (5)
    • Trades (X)
    • Orderbooks (W)
    • Heartbeat (0)

Usage

Add this to your Cargo.toml

[dependencies]
coinapi = { git = "https://github.com/soerenmartius/coinapi-rs.git" }

Metadata

List all exchanges

use coinapi_rs::metadata::*;

fn main() {
    let metadata: MetaData = Coinapi::new(String::from("YOUR_API_KEY_HERE"));
    let data = metadata.get_all_exchanges();

    match data {
        Ok(r) => println!("{:#?}", r),
        Err(e) => println!("Error: {:?}", e)
    }
}

List all assets

use coinapi_rs::metadata::*;

fn main() {
    let metadata: MetaData = Coinapi::new(String::from("YOUR_API_KEY_HERE"));
    let assets = metadata.get_all_assets();

    match assets {
        Ok(r) => println!("{:#?}", r),
        Err(e) => println!("Error: {:?}", e)
    }
}

List all symbols

use coinapi_rs::metadata::*;

fn main() {
    let metadata: MetaData = Coinapi::new(String::from("YOUR_API_KEY_HERE"));
    let data = metadata.get_all_symbols(None);
    //let data = metadata.get_all_symbols(Some("BITSTAMP_SPOT_BTC_USD,HITBTC_SPOT_BTS_BTC")); // with filter

    match data {
        Ok(r) => println!("{:#?}", r),
        Err(e) => println!("Error: {:?}", e)
    }
}

Exchange rates

Get specific rate

use coinapi_rs::exchangerate::*;
use chrono::Utc;

fn main() {
    let exchangerate: ExchangeRate = Coinapi::new(String::from("YOUR_API_KEY_HERE"));
    let time = Utc.ymd(2018, 7, 8).and_hms(9, 10, 11);
    let data = exchangerate.get_specific_rate("BTC", "USDT", Some(time));

    match data {
        Ok(r) => println!("{:#?}", r),
        Err(e) => println!("Error: {:?}", e)
    }
}

Get all current rates

use coinapi_rs::exchangerate::*;

fn main() {
    let exchangerate: ExchangeRate = Coinapi::new(String::from("YOUR_API_KEY_HERE"));
    let data = exchangerate.get_all_rates("BTC");

        match data {
        Ok(r) => println!("{:#?}", r),
        Err(e) => println!("Error: {:?}", e)
    }
}

OHLCV

List all periods

use coinapi_rs::ohlcv::*;

fn main() {
    let ohlcv: OHLCV = Coinapi::new(String::from
    ("YOUR_API_KEY_HERE"));
    let data = ohlcv.list_all_periods();

    match data {
      Ok(r)  => println!("{:#?}", r),
      Err(e) => println!("Error: {:?}", e)
    }
}

Latest data

use coinapi_rs::ohlcv::*;
use chrono::Utc;

fn main() {
    let ohlcv: OHLCV = Coinapi::new(String::from
    ("YOUR_API_KEY_HERE"));
    let data = ohlcv.latest_data("BITSTAMP_SPOT_BTC_USD", "1MIN", Some(false), Some(100i32));

    match data {
      Ok(r)  => println!("{:#?}", r),
      Err(e) => println!("Error: {:?}", e)
    }
}

Historical data

use coinapi_rs::ohlcv::*;
use chrono::Utc;

fn main() {
    let ohlcv: OHLCV = Coinapi::new(String::from
    ("YOUR_API_KEY_HERE"));
    let start_time = Utc.ymd(2020, 8, 20).and_hms(5, 55, 55);
    let end_time = Utc.ymd(2020, 8, 27).and_hms(5, 55, 55);
    let data = ohlcv.historical_data("BITSTAMP_SPOT_BTC_USD", "1MIN", start_time, Some(time_end), None, Some(100i32));

    match data {
      Ok(r)  => println!("{:#?}", r),
      Err(e) => println!("Error: {:?}", e)
    }
}

## Contributors

- [Blake Willoughby](https://github.com/byblakeorriver)
- [Soren Martius](https://github.com/soerenmartius)