/// <summary> /// Get data regarding the last 24 hours change /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="ct">Cancellation token</param> /// <returns>Data over the last 24 hours</returns> public async Task <WebCallResult <IEnumerable <IBinance24HPrice> > > Get24HPricesAsync(string?symbol = null, CancellationToken ct = default) { var parameters = new Dictionary <string, object>(); parameters.AddOptionalParameter("symbol", symbol); if (symbol != null) { var result = await BaseClient .SendRequestInternal <Binance24HPrice>(FuturesClient.GetUrl(price24HEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(new WebCallResult <IEnumerable <IBinance24HPrice> >(result.ResponseStatusCode, result.ResponseHeaders, result.Success ? new[] { result.Data } : null, result.Error)); } else { var result = await BaseClient .SendRequestInternal <IEnumerable <Binance24HPrice> >(FuturesClient.GetUrl(price24HEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(new WebCallResult <IEnumerable <IBinance24HPrice> >(result.ResponseStatusCode, result.ResponseHeaders, result.Success ? result.Data: null, result.Error)); } }
/// <summary> /// Gets the price of a symbol /// </summary> /// <param name="symbol">The symbol to get the price for</param> /// <param name="ct">Cancellation token</param> /// <returns>Price of symbol</returns> public async Task <WebCallResult <BinancePrice> > GetPriceAsync(string symbol, CancellationToken ct = default) { var parameters = new Dictionary <string, object> { { "symbol", symbol } }; return(await BaseClient.SendRequestInternal <BinancePrice>(FuturesClient.GetUrl(allPricesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Get data regarding the last 24 hours change /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="pair">Filter by pair</param> /// <param name="ct">Cancellation token</param> /// <returns>Data over the last 24 hours</returns> public async Task <WebCallResult <IEnumerable <BinanceFuturesCoin24HPrice> > > Get24HPricesAsync(string?symbol = null, string?pair = null, CancellationToken ct = default) { var parameters = new Dictionary <string, object>(); parameters.AddOptionalParameter("symbol", symbol); parameters.AddOptionalParameter("pair", pair); return(await BaseClient .SendRequestInternal <IEnumerable <BinanceFuturesCoin24HPrice> >(FuturesClient.GetUrl(price24HEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Gets account information, including balances /// </summary> /// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param> /// <param name="ct">Cancellation token</param> /// <returns>The account information</returns> public async Task <WebCallResult <BinanceFuturesAccountInfo> > GetAccountInfoAsync(long?receiveWindow = null, CancellationToken ct = default) { var timestampResult = await BaseClient.CheckAutoTimestamp(ct).ConfigureAwait(false); if (!timestampResult) { return(new WebCallResult <BinanceFuturesAccountInfo>(timestampResult.ResponseStatusCode, timestampResult.ResponseHeaders, null, timestampResult.Error)); } var parameters = new Dictionary <string, object> { { "timestamp", BaseClient.GetTimestamp() } }; parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? BaseClient.DefaultReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); return(await BaseClient.SendRequestInternal <BinanceFuturesAccountInfo>(FuturesClient.GetUrl(accountInfoEndpoint, Api, SignedV2), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false)); }
/// <summary> /// Gets the best price/quantity on the order book for a symbol. /// </summary> /// <param name="symbol">Symbol to get book price for</param> /// <param name="ct">Cancellation token</param> /// <returns>List of book prices</returns> public async Task <WebCallResult <IEnumerable <BinanceBookPrice> > > GetBookPricesAsync(string?symbol = null, CancellationToken ct = default) { var parameters = new Dictionary <string, object>(); parameters.AddOptionalParameter("symbol", symbol); if (symbol == null) { return(await BaseClient .SendRequestInternal <IEnumerable <BinanceBookPrice> >( FuturesClient.GetUrl(bookPricesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters) .ConfigureAwait(false)); } else { var result = await BaseClient.SendRequestInternal <BinanceBookPrice>(FuturesClient.GetUrl(bookPricesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(result.As <IEnumerable <BinanceBookPrice> >(result.Success ? new[] { result.Data } : null)); } }
/// <summary> /// Gets the recent trades for a symbol /// </summary> /// <param name="symbol">The symbol to get recent trades for</param> /// <param name="limit">Result limit</param> /// <param name="ct">Cancellation token</param> /// <returns>List of recent trades</returns> public override async Task <WebCallResult <IEnumerable <IBinanceRecentTrade> > > GetSymbolTradesAsync(string symbol, int?limit = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 1000); var parameters = new Dictionary <string, object> { { "symbol", symbol } }; parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); var result = await BaseClient.SendRequestInternal <IEnumerable <BinanceRecentTradeQuote> >(FuturesClient.GetUrl(recentTradesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(new WebCallResult <IEnumerable <IBinanceRecentTrade> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data, result.Error)); }
/// <summary> /// Get a list of the prices of all symbols /// </summary> /// <param name="ct">Cancellation token</param> /// <returns>List of prices</returns> public async Task <WebCallResult <IEnumerable <BinancePrice> > > GetPricesAsync(CancellationToken ct = default) { return(await BaseClient.SendRequestInternal <IEnumerable <BinancePrice> >(FuturesClient.GetUrl(allPricesEndpoint, Api, publicVersion), HttpMethod.Get, ct).ConfigureAwait(false)); }
/// <summary> /// Gets composite index info /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="ct">Cancellation token</param> /// <returns></returns> public async Task <WebCallResult <IEnumerable <BinanceFuturesCompositeIndexInfo> > > GetCompositeIndexInfoAsync(string?symbol = null, CancellationToken ct = default) { var parameters = new Dictionary <string, object>(); parameters.AddOptionalParameter("symbol", symbol); return(await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesCompositeIndexInfo> >(FuturesClient.GetUrl(compositeIndexApi, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Gets Taker Buy/Sell Volume Ratio /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="period">The period timespan</param> /// <param name="limit">Max number of results</param> /// <param name="startTime">Start time to get taker buy/sell volume ratio</param> /// <param name="endTime">End time to get taker buy/sell volume ratio</param> /// <param name="ct">Cancellation token</param> /// <returns>Taker Buy/Sell Volume Ratio info</returns> public async Task <WebCallResult <IEnumerable <BinanceFuturesBuySellVolumeRatio> > > GetTakerBuySellVolumeRatioAsync(string symbol, PeriodInterval period, int?limit = null, DateTime?startTime = null, DateTime?endTime = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 500); var parameters = new Dictionary <string, object> { { "symbol", symbol }, { "period", JsonConvert.SerializeObject(period, new PeriodIntervalConverter(false)) } }; parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null); return(await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesBuySellVolumeRatio> >(FuturesClient.GetUrl(takerBuySellVolumeRatioEndpoint, tradingDataApi), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Get all Liquidation Orders /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="startTime">Start time to get liquidation orders history</param> /// <param name="endTime">End time to get liquidation orders history</param> /// <param name="limit">Max number of results. Default:100 Max:1000</param> /// <param name="ct">Cancellation token</param> /// <returns>The all liquidation orders</returns> public async Task <WebCallResult <IEnumerable <BinanceFuturesLiquidation> > > GetLiquidationOrdersAsync(string?symbol = null, DateTime?startTime = null, DateTime?endTime = null, int?limit = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 0, 1000); var parameters = new Dictionary <string, object>(); parameters.AddOptionalParameter("symbol", symbol); parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); return(await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesLiquidation> >(FuturesClient.GetUrl(allForcedOrdersEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Get candlestick data for the provided symbol /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="interval">The candlestick timespan</param> /// <param name="startTime">Start time to get candlestick data</param> /// <param name="endTime">End time to get candlestick data</param> /// <param name="limit">Max number of results</param> /// <param name="ct">Cancellation token</param> /// <returns>The candlestick data for the provided symbol</returns> public override async Task <WebCallResult <IEnumerable <IBinanceKline> > > GetKlinesAsync(string symbol, KlineInterval interval, DateTime?startTime = null, DateTime?endTime = null, int?limit = null, CancellationToken ct = default) { symbol.ValidateBinanceSymbol(); limit?.ValidateIntBetween(nameof(limit), 1, 1500); var parameters = new Dictionary <string, object> { { "symbol", symbol }, { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) } }; parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); var result = await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesUsdtKline> >(FuturesClient.GetUrl(klinesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(new WebCallResult <IEnumerable <IBinanceKline> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data, result.Error)); }
/// <summary> /// Get candlestick data for the provided pair /// </summary> /// <param name="pair">The symbol to get the data for</param> /// <param name="contractType">The contract type</param> /// <param name="interval">The candlestick timespan</param> /// <param name="startTime">Start time to get candlestick data</param> /// <param name="endTime">End time to get candlestick data</param> /// <param name="limit">Max number of results</param> /// <param name="ct">Cancellation token</param> /// <returns>The candlestick data for the provided symbol</returns> public async Task <WebCallResult <IEnumerable <IBinanceKline> > > GetContinuousContractKlinesAsync(string pair, ContractType contractType, KlineInterval interval, DateTime?startTime = null, DateTime?endTime = null, int?limit = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 1000); var parameters = new Dictionary <string, object> { { "pair", pair }, { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, { "contractType", JsonConvert.SerializeObject(contractType, new ContractTypeConverter(false)) } }; parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); var result = await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesUsdtKline> >(FuturesClient.GetUrl(continuousContractKlineEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(result.As <IEnumerable <IBinanceKline> >(result.Data)); }
/// <summary> /// Gets the historical trades for a symbol /// </summary> /// <param name="symbol">The symbol to get recent trades for</param> /// <param name="limit">Result limit</param> /// <param name="fromId">From which trade id on results should be retrieved</param> /// <param name="ct">Cancellation token</param> /// <returns>List of recent trades</returns> public override async Task <WebCallResult <IEnumerable <IBinanceRecentTrade> > > GetTradeHistoryAsync(string symbol, int?limit = null, long?fromId = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 1000); var parameters = new Dictionary <string, object> { { "symbol", symbol } }; parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("fromId", fromId?.ToString(CultureInfo.InvariantCulture)); var result = await BaseClient.SendRequestInternal <IEnumerable <BinanceRecentTradeBase> >(FuturesClient.GetUrl(historicalTradesEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false); return(result.As <IEnumerable <IBinanceRecentTrade> >(result.Data)); }
/// <summary> /// Get candlestick data for the provided pair /// </summary> /// <param name="symbol">The symbol to get the data for</param> /// <param name="interval">The candlestick timespan</param> /// <param name="startTime">Start time to get candlestick data</param> /// <param name="endTime">End time to get candlestick data</param> /// <param name="limit">Max number of results</param> /// <param name="ct">Cancellation token</param> /// <returns>The candlestick data for the provided symbol</returns> public async Task <WebCallResult <IEnumerable <BinanceMarkIndexKline> > > GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime?startTime = null, DateTime?endTime = null, int?limit = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 1000); var parameters = new Dictionary <string, object> { { "symbol", symbol }, { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) } }; parameters.AddOptionalParameter("startTime", startTime != null ? BinanceClient.ToUnixTimestamp(startTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("endTime", endTime != null ? BinanceClient.ToUnixTimestamp(endTime.Value).ToString(CultureInfo.InvariantCulture) : null); parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); return(await BaseClient.SendRequestInternal <IEnumerable <BinanceMarkIndexKline> >(FuturesClient.GetUrl(markPriceKlineEndpoint, Api, publicVersion), HttpMethod.Get, ct, parameters).ConfigureAwait(false)); }
/// <summary> /// Gets all user trades for provided symbol /// </summary> /// <param name="symbol">Symbol to get trades for</param> /// <param name="pair">Symbol to get trades for</param> /// <param name="limit">The max number of results</param> /// <param name="fromId">TradeId to fetch from. Default gets most recent trades</param> /// <param name="startTime">Orders newer than this date will be retrieved</param> /// <param name="endTime">Orders older than this date will be retrieved</param> /// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param> /// <param name="ct">Cancellation token</param> /// <returns>List of trades</returns> public async Task <WebCallResult <IEnumerable <BinanceFuturesCoinTrade> > > GetMyTradesAsync(string?symbol = null, string?pair = null, DateTime?startTime = null, DateTime?endTime = null, int?limit = null, long?fromId = null, long?receiveWindow = null, CancellationToken ct = default) { limit?.ValidateIntBetween(nameof(limit), 1, 1000); var timestampResult = await BaseClient.CheckAutoTimestamp(ct).ConfigureAwait(false); if (!timestampResult) { return(new WebCallResult <IEnumerable <BinanceFuturesCoinTrade> >(timestampResult.ResponseStatusCode, timestampResult.ResponseHeaders, null, timestampResult.Error)); } var parameters = new Dictionary <string, object> { { "timestamp", BaseClient.GetTimestamp() } }; parameters.AddOptionalParameter("symbol", symbol); parameters.AddOptionalParameter("pair", pair); parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("fromId", fromId?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("startTime", startTime.HasValue ? JsonConvert.SerializeObject(startTime.Value, new TimestampConverter()) : null); parameters.AddOptionalParameter("endTime", endTime.HasValue ? JsonConvert.SerializeObject(endTime.Value, new TimestampConverter()) : null); parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? BaseClient.DefaultReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); return(await BaseClient.SendRequestInternal <IEnumerable <BinanceFuturesCoinTrade> >(FuturesClient.GetUrl(myFuturesTradesEndpoint, Api, SignedVersion), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false)); }