1 个不稳定版本
0.1.0 | 2023 年 3 月 8 日 |
---|
#22 在 #binance
26KB
677 行
币安历史数据
从币安交易所下载和解析历史数据
安装
将以下行添加到您的 Cargo.toml
文件中
binance-history = "0.1.0"
或对于最新 GitHub 版本
binance-history = { git = "https://github.com/K0nstantini/binance-history" }
用法
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());
}
使用自定义结构体
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());
}
依赖关系
~13–29MB
~406K SLoC