wisespace-io / binance-rs

Rust Library for the Binance API
Other
688 stars 305 forks source link

Get the price of a symbol at a specific date #127

Closed Evanok closed 3 years ago

Evanok commented 3 years ago

Hello,

Nice job on this code ! You have really cool feature on your api Did I miss something about the api to get price symbol ?

I would like to be able to get the prince of a specific symbol at a specific date ? Is it possible with this api ?

Thanks, Eva.

KivalM commented 3 years ago

Yes it is.

market.get_klines(symbol, "5m", number,  start_time, end_time)

where

for example, the price on january 1st 2021

fn main() {
    let market: Market = Binance::new(None, None);
    match market.get_klines("ETHUSDT", "5m", 1, 1609452000000, None) {
        Ok(klines) => match klines {

            binance::model::KlineSummaries::AllKlineSummaries(klines) => {
               // will only run once since limit is 1
                for z in klines {
                    println!("{}", z.open);
                    println!("{}", z.close);
                    println!("{}", z.high);
                    println!("{}", z.low);
                }
            }
        },
        Err(e) => println!("Error: {}", e),
    }
}

You could change the "5m" to something else, like "1m" for a smaller interval, but you get the idea

Evanok commented 3 years ago

Thanks for your answer !