Bybit.Net
Bybit.Net copied to clipboard
Websocket Tickerdata price differs from the actual price
Hello, Im using websocket ticker data api to sace the best ask and bid prices and it sometimes significantly differs from what i see on tradingview.com's Chart+. Here's a photo
The code is very simple Tickerdata ipdate event is triggered and it saves the whole object into a public variable
subscribe =>
UpdateResults = await SocketClient.UsdPerpetualStreams.SubscribeToTickerUpdatesAsync(Symbol.Name, SocketHandler_TickerDataUpdate);
Event=>
private void SocketHandler_TickerDataUpdate(DataEvent<BybitTickerUpdate> obj) foreach (var stringPropertyNamesAndValues in obj.Data.GetType() .GetProperties().Where(x => x.GetType() != null) .Select(pi => new { pi.Name, Value = pi.GetGetMethod().Invoke(obj.Data, null) })) { if (stringPropertyNamesAndValues.Value != null) { PropertyInfo propertyInfo = TickerData.GetType().GetProperty(stringPropertyNamesAndValues.Name); if (propertyInfo.GetGetMethod().Invoke(obj.Data, null) != null) propertyInfo.SetValue(TickerData, stringPropertyNamesAndValues.Value, null); } }
and writing to the db file.
BTW i use lock to prevent Threads from Interfering
TV ticks will sometimes differ from market ticks on every market. This is due to tick caching intervals used by data providers, where a tick update may vary between 0.5s, 1s, etc. So when the tick is pushed to web socket clients, every data provider may display a different snapshot due to lag, update intervals,...