# 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`:
```toml
[dependencies]
binance_lite = "0.1.0"
```
(Replace with your crate version.)
---
## ๐ Quick Example
```rust
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:
```rust
#[tokio::test]
async fn test_market_data() {
let res = MarketData::get_data_for("BTC", "1w", 2).await;
assert!(!res.record.is_empty());
}
```
---