wisespace-io / binance-rs

Rust Library for the Binance API
Other
640 stars 290 forks source link

KlineSummary Serialization #102

Closed partisan-bobryk closed 3 years ago

partisan-bobryk commented 3 years ago

Hi I don't know if this was asked before, but i noticed that KlineSummary struct doesn't implement Serialize/Deserialize macro. Was that intentional by design?

The use case for me would be getting historical data and saving it locally to test against.

Would this be something that I can make a PR for?

wisespace-io commented 3 years ago

@VeprUA Yes, you can create a PR for it. We just missed it.

ghost commented 3 years ago

can someone help me please, i have tried to do the implementation to it but i cant.

impl<'de> Deserialize<'de> for KlineSummaries {

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where D: Deserializer<'de>
{

    return KlineSummaries::deserialize(deserializer)

}

}

wisespace-io commented 3 years ago

@VeprUA I added the macros in the release 0.13.3, let me know if it is working in your side.

wisespace-io commented 3 years ago

@VeprUA See how you get the Kline values below

// last 10 5min klines (candlesticks) for a symbol:
match market.get_klines("BNBETH", "5m", 10, None, None) {
    Ok(klines) => {   
        match klines {
            binance::model::KlineSummaries::AllKlineSummaries(klines) => {
                let kline: KlineSummary = klines[0].clone(); // You need to iterate over the klines
                println!(
                    "Open: {}, High: {}, Low: {}",
                    kline.open, kline.high, kline.low
                )
            }
        }
    },
    Err(e) => println!("Error: {}", e),
}
partisan-bobryk commented 3 years ago

Sorry, I got sidetracked, thank you for taking care of this. 🙌🎉