binance-history

Crates.iobinance-history
lib.rsbinance-history
version0.1.0
sourcesrc
created_at2023-03-08 21:32:13.656644
updated_at2023-03-08 21:32:13.656644
descriptionDownloading and parsing historical data from the Binance exchange
homepage
repositoryhttps://github.com/K0nstantini/binance-history
max_upload_size
id805102
size26,003
Konstantin (K0nstantini)

documentation

README

Binance history

Downloading and parsing historical data from the Binance exchange

Installation

Add the following line to your Cargo.toml file:

binance-history = "0.1.0"

Or for the latest github version:

binance-history = { git = "https://github.com/K0nstantini/binance-history" }

Usage

use binance_history::{COINMKlines, SpotTrades, USDMAggTrades};

#[tokio::main]
async fn main() {
    let symbol = "BTCUSDT";
    let path = "csv";
    let from = "2023-02-01 00:00:00";
    let to = "2023-02-02 23:59:59";

    let spot_trades: Vec<SpotTrades> = binance_history::get(symbol, None, from, to, path).await.unwrap();
    let usdm_agg_trades: Vec<USDMAggTrades> = binance_history::get(symbol, None, from, to, path).await.unwrap();
    let coinm_klines: Vec<COINMKlines> = binance_history::get("BTCUSD_PERP", Some("1h"), from, to, path).await.unwrap();

    assert!(!spot_trades.is_empty());
    assert!(!usdm_agg_trades.is_empty());
    assert!(!coinm_klines.is_empty());
}

Using custom struct

use binance_history::{BinanceData, DataType, MarketType};
use serde::Deserialize;

#[derive(Deserialize)]
struct Prices {
    time: i64,
    price: f64,
}

impl BinanceData for Prices {
    fn types() -> (MarketType, DataType) {
        (MarketType::USDM, DataType::Trades)
    }

    fn time(&self) -> i64 {
        self.time
    }
}

#[tokio::main]
async fn main() {
    let symbol = "ETHUSDT";
    let path = "csv";
    let from = "2023-02-01 00:00:00";
    let to = "2023-02-02 23:59:59";

    let prices: Vec<Prices> = binance_history::get(symbol, None, from, to, path).await.unwrap();
    assert!(!prices.is_empty());
}
Commit count: 14

cargo fmt