/// <inheritdoc /> public async Task <WebCallResult <CoinExOrderBook> > GetOrderBookAsync(string symbol, int mergeDepth, int?limit = null, CancellationToken ct = default) { symbol.ValidateCoinExSymbol(); mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8); limit?.ValidateIntValues(nameof(limit), 5, 10, 20); var parameters = new Dictionary <string, object> { { "market", symbol }, { "merge", CoinExHelpers.MergeDepthIntToString(mergeDepth) } }; parameters.AddOptionalParameter("limit", limit); return(await _baseClient.Execute <CoinExOrderBook>(_baseClient.GetUrl(MarketDepthEndpoint), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <CallResult <CoinExSocketOrderBook> > GetOrderBookAsync(string symbol, int limit, int mergeDepth) { symbol.ValidateCoinExSymbol(); mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8); limit.ValidateIntValues(nameof(limit), 5, 10, 20); return(await _baseClient.QueryInternalAsync <CoinExSocketOrderBook>(this, new CoinExSocketRequest(_baseClient.NextIdInternal(), DepthSubject, QueryAction, symbol, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth)), false).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task <CallResult <UpdateSubscription> > SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action <DataEvent <CoinExSocketOrderBook> > onMessage, CancellationToken ct = default) { symbol.ValidateCoinExSymbol(); mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8); limit.ValidateIntValues(nameof(limit), 5, 10, 20); var internalHandler = new Action <DataEvent <JToken[]> >(data => { if (data.Data.Length != 3) { _log.Write(LogLevel.Warning, $"Received unexpected data format for depth update. Expected 3 objects, received {data.Data.Length}. Data: " + data); return; } var fullUpdate = (bool)data.Data[0]; var desResult = _baseClient.DeserializeInternal <CoinExSocketOrderBook>(data.Data[1]); if (!desResult) { _log.Write(LogLevel.Warning, "Received invalid depth update: " + desResult.Error); return; } desResult.Data.FullUpdate = fullUpdate; onMessage(data.As(desResult.Data, symbol)); }); return(await _baseClient.SubscribeInternalAsync(this, new CoinExSocketRequest(_baseClient.NextIdInternal(), DepthSubject, SubscribeAction, symbol, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth)), null, false, internalHandler, ct).ConfigureAwait(false)); }