binance_lite

Crates.iobinance_lite
lib.rsbinance_lite
version1.0.1
created_at2025-11-26 23:30:41.437963+00
updated_at2025-11-26 23:38:30.392004+00
descriptionA lightweight Binance API wrapper
homepage
repositoryhttps://github.com/blackh-t/binance_lite
max_upload_size
id1952677
size42,922
N-Choo (blackh-t)

documentation

README

binance_lite

A lightweight Rust library for fetching market candlestick data from the Binance public API. Designed to be minimal, fast, and easy to integrate into trading bots or analytics tools.


โœจ Features

  • Fetch candlestick market data (open, high, low, close, timestamp, etc.)
  • Extract price history as Vec<f64>
  • Minimal dependencies
  • Asynchronous (uses reqwest + tokio)
  • JSON serialization support

๐Ÿ“ฆ Installation

Add to your Cargo.toml:

[dependencies]
binance_lite = "0.1.0"

(Replace with your crate version.)


๐Ÿš€ Quick Example

use binance_lite::MarketData;

#[tokio::main]
async fn main() {
    // Fetch BTC weekly data (2 candlesticks)
    let data = MarketData::get_data_for("BTC", "1w", 2).await;

    // Extract prices
    let prices = data.price();
    println!("Prices: {:?}", prices);

    // Serialize to JSON
    let json = data.serialize().unwrap();
    println!("As JSON:\n{}", json);
}

๐Ÿ“˜ API Overview

MarketData::get_data_for(symbol, interval, limit) -> MarketData

Fetches candlestick data for:

  • symbol: market pair base (ex: "BTC")
  • interval: Binance interval string ("1m", "5m", "1h", "1w", etc.)
  • limit: number of candlesticks to fetch

MarketData::price() -> Vec<f64>

Extracts the price values (from newest โ†’ oldest).


MarketData::serialize() -> Result<String>

Serializes the entire dataset into pretty JSON.


๐Ÿงช Testing

A built-in test validates that at least one candlestick is returned:

#[tokio::test]
async fn test_market_data() {
    let res = MarketData::get_data_for("BTC", "1w", 2).await;
    assert!(!res.record.is_empty());
}

Commit count: 0

cargo fmt