Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -270,6 +272,69 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
return book;
}

protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>> 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<KeyValuePair<string, ExchangeTicker>>();

var marketSymbolsMetadata = await GetMarketSymbolsMetadataAsync();

var url = $"/v5/market/tickers?category={MarketCategory.ToStringLowerInvariant()}";
var token = await MakeJsonRequestAsync<JToken>(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<string, ExchangeTicker>(
marketSymbol,
exchangeTicker
));
}

return tickers;
}

#endregion Public

#region Private
Expand Down