Skip to content

Commit eed5ea1

Browse files
authored
Bybit - GetTickersAsync implementation (#845)
1 parent 3f24f4b commit eed5ea1

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public ExchangeBybitV5Base()
3737
WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas;
3838
RateLimit = new RateGate(10, TimeSpan.FromSeconds(1));
3939
RequestWindow = TimeSpan.FromSeconds(15);
40+
MarketSymbolSeparator = string.Empty;
41+
MarketSymbolIsUppercase = true;
4042
}
4143

4244
protected override async Task OnGetNonceOffset()
@@ -270,6 +272,69 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
270272
return book;
271273
}
272274

275+
protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>> OnGetTickersAsync()
276+
{
277+
//{
278+
// "retCode": 0,
279+
// "retMsg": "OK",
280+
// "result": {
281+
// "category": "spot",
282+
// "list": [
283+
// {
284+
// "symbol": "MOJOUSDT",
285+
// "bid1Price": "0.01755",
286+
// "bid1Size": "128.66",
287+
// "ask1Price": "0.01763",
288+
// "ask1Size": "311.27",
289+
// "lastPrice": "0.01759",
290+
// "prevPrice24h": "0.01848",
291+
// "price24hPcnt": "-0.0482",
292+
// "highPrice24h": "0.01851",
293+
// "lowPrice24h": "0.01726",
294+
// "turnover24h": "67118.0455931",
295+
// "volume24h": "3769556.35"
296+
// },
297+
// ...
298+
// ]
299+
// }
300+
//}
301+
302+
var tickers = new List<KeyValuePair<string, ExchangeTicker>>();
303+
304+
var marketSymbolsMetadata = await GetMarketSymbolsMetadataAsync();
305+
306+
var url = $"/v5/market/tickers?category={MarketCategory.ToStringLowerInvariant()}";
307+
var token = await MakeJsonRequestAsync<JToken>(url);
308+
var tickerList = token["list"];
309+
foreach (var ticker in tickerList)
310+
{
311+
var marketSymbol = ticker["symbol"].ToStringInvariant();
312+
if (!marketSymbolsMetadata.Any(x => x.MarketSymbol == marketSymbol))
313+
{
314+
// "Please always use the Trading symbols found in the instrument-info api, then query tickers by those symbols." - Bybit API support
315+
continue;
316+
}
317+
318+
var exchangeTicker = await this.ParseTickerAsync(
319+
ticker,
320+
marketSymbol,
321+
"ask1Price",
322+
"bid1Price",
323+
"lastPrice",
324+
// https://bybit-exchange.github.io/docs/faq#what-is-the-difference-between-turnover-and-volume
325+
"volume24h", // Volume: is in the same currency as the quantity's currency
326+
"turnover24h" // Turnover: is in the opposite currency to the quantity's currency
327+
);
328+
329+
tickers.Add(new KeyValuePair<string, ExchangeTicker>(
330+
marketSymbol,
331+
exchangeTicker
332+
));
333+
}
334+
335+
return tickers;
336+
}
337+
273338
#endregion Public
274339

275340
#region Private

0 commit comments

Comments
 (0)