From eed5ea1aa416822840dee7d6753de047705c7f4e Mon Sep 17 00:00:00 2001 From: Vlad Dumitru Date: Mon, 30 Sep 2024 17:05:44 +0300 Subject: [PATCH] Bybit - GetTickersAsync implementation (#845) --- .../Exchanges/Bybit/ExchangeBybitV5Base.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs index 7e36c8b1..6b1103da 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs @@ -37,6 +37,8 @@ public ExchangeBybitV5Base() WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas; RateLimit = new RateGate(10, TimeSpan.FromSeconds(1)); RequestWindow = TimeSpan.FromSeconds(15); + MarketSymbolSeparator = string.Empty; + MarketSymbolIsUppercase = true; } protected override async Task OnGetNonceOffset() @@ -270,6 +272,69 @@ protected override async Task OnGetOrderBookAsync( return book; } + protected override async Task>> OnGetTickersAsync() + { + //{ + // "retCode": 0, + // "retMsg": "OK", + // "result": { + // "category": "spot", + // "list": [ + // { + // "symbol": "MOJOUSDT", + // "bid1Price": "0.01755", + // "bid1Size": "128.66", + // "ask1Price": "0.01763", + // "ask1Size": "311.27", + // "lastPrice": "0.01759", + // "prevPrice24h": "0.01848", + // "price24hPcnt": "-0.0482", + // "highPrice24h": "0.01851", + // "lowPrice24h": "0.01726", + // "turnover24h": "67118.0455931", + // "volume24h": "3769556.35" + // }, + // ... + // ] + // } + //} + + var tickers = new List>(); + + var marketSymbolsMetadata = await GetMarketSymbolsMetadataAsync(); + + var url = $"/v5/market/tickers?category={MarketCategory.ToStringLowerInvariant()}"; + var token = await MakeJsonRequestAsync(url); + var tickerList = token["list"]; + foreach (var ticker in tickerList) + { + var marketSymbol = ticker["symbol"].ToStringInvariant(); + if (!marketSymbolsMetadata.Any(x => x.MarketSymbol == marketSymbol)) + { + // "Please always use the Trading symbols found in the instrument-info api, then query tickers by those symbols." - Bybit API support + continue; + } + + var exchangeTicker = await this.ParseTickerAsync( + ticker, + marketSymbol, + "ask1Price", + "bid1Price", + "lastPrice", + // https://bybit-exchange.github.io/docs/faq#what-is-the-difference-between-turnover-and-volume + "volume24h", // Volume: is in the same currency as the quantity's currency + "turnover24h" // Turnover: is in the opposite currency to the quantity's currency + ); + + tickers.Add(new KeyValuePair( + marketSymbol, + exchangeTicker + )); + } + + return tickers; + } + #endregion Public #region Private