Get the price of a symbol at a specific date
Evanok opened this issue · comments
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.
Yes it is.
market.get_klines(symbol, "5m", number, start_time, end_time)
where
- start_time is the starting time in milliseconds, can also be
None
- end_time is the ending time in milliseconds, can also be
None
- number is the number of intervals you want, in your case its probably 1.
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
Thanks for your answer !