3 releases

0.1.9 May 9, 2022
0.1.8 Apr 27, 2022
0.1.0 Apr 26, 2022

#112 in #exchange

26 downloads per month
Used in 3 crates

BSD-2-Clause

44KB
1K SLoC

ecbt(Exchange Connect Base Tool)

CI status CI status License Crates.io Minimum rustc version Join at Slack

High performance cryptocurrency trading API with support for user defined networking.

  • Based on Rust, memory safe by default.
  • Support for websockets and user defined networking.
  • Easy to add support for additional exchanges.

License

BSD 2-Clause License

Usage

Add dependencies in Cargo.toml:

[dependencies]
ecbt = "0.1"
ecbt-exchange = "0.1"
ecbt-binance = "0.1"
tokio = { version = "1", features = ["full"] }

HTTP

use std::borrow::Borrow;

use ecbt::{
    prelude::{
        market_pair::{Currency, MarketPair},
        GetPriceTickerRequest,
    },
    Ecbt,
};
use ecbt_binance::{Binance, BinanceParameters};
use ecbt_exchange::ExchangeMarketData;

#[tokio::main]
async fn main() {
    let ecbt = Ecbt::http::<Binance>(BinanceParameters::sandbox())
        .await
        .unwrap();
    let request = GetPriceTickerRequest {
        market_pair: MarketPair(Currency::ETH, Currency::USDT),
    };
    let s = ecbt.get_price_ticker(request.borrow()).await.unwrap();
    println!("{:?}", s);
}

WebSocket

use ecbt::{
    prelude::{
        market_pair::{Currency, MarketPair},
        websocket::{EcbtWebSocketMessage, Subscription, WebSocketResponse},
        ExchangeStream,
    },
    Ecbt,
};
use ecbt_binance::{BinanceParameters, BinanceWebsocket};

#[tokio::main]
async fn main() {
    let ecbt = Ecbt::ws::<BinanceWebsocket>(BinanceParameters::sandbox())
        .await
        .unwrap();
    let market = MarketPair(Currency::ETH, Currency::BTC);

    ecbt.subscribe(Subscription::OrderBookUpdates(market), move |m| {
        let r = m.as_ref();

        if let Ok(WebSocketResponse::Generic(EcbtWebSocketMessage::OrderBook(order_book))) = r {
            println!("{:?}", order_book)
        } else if let Err(err) = r {
            println!("{:#?}", err);
        }
    })
    .await
    .expect("Failed to subscribe to orderbook on Binance");

    std::thread::sleep(std::time::Duration::from_millis(5000));
}

Development

Configure pre-commit hook

pre-commit can help you check the quality of your code before committing to a branch.

  1. Configure pre-commit with this tutorial: https://pre-commit.com
  2. Run pre-commit install.

Contributions

Because there are many exchanges, if ecbt has not been implemented, you may need to implement it yourself.

Contact Us

Contact or join us @oss-jtyd.

WIP

  • Project Skeleton
  • Binance support
  • Nash support
  • Huobi support
  • Coinbase support
  • Apifiny support
  • Okex support
  • FTX support

Dependencies

~9–26MB
~401K SLoC