JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.05k stars 429 forks source link

GetKlines Price Problem #597

Closed allcasper99 closed 3 years ago

allcasper99 commented 3 years ago

hello, when I use the klines method, there is a problem with the incoming prices. The prices of the Tradingview website and the binance exchange are the same, but the price from the method is different. You can see in the attachment. Example icxusdt

Binance image

Tradingview image

Binance.Net GetKlines image

Can you fix this problem?

Hulkstance commented 3 years ago

The following code (same as yours) is retrieving the last candle which is unfinished. That's why the data is different. It changes over the time until the time interval is complete.

await client.Spot.Market.GetKlinesAsync("ICXUSDT", KlineInterval.FourHour, limit: 1).ConfigureAwait(false);

If you want to pull the latest finished candle you should do:

await client.Spot.Market.GetKlinesAsync("ICXUSDT", KlineInterval.FourHour, limit: 2).ConfigureAwait(false).SkipLast(1).ToList();

Or you could just remove the last candle, instead of SkipLast.

SARPSARP090 commented 3 years ago

Hi.

await client.Spot.Market.GetKlinesAsync("ICXUSDT", KlineInterval.FourHour, limit: 2).ConfigureAwait(false).SkipLast(1).ToList();

Is SkipLast here obsolete anymore?