/// <summary>
        /// Gets candlestick data for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="period">The period of a single candlestick</param>
        /// <returns></returns>
        public async Task <CallResult <List <HuobiMarketKline> > > QueryMarketKlinesAsync(string symbol, HuobiPeriod period)
        {
            var request = new HuobiSocketRequest($"market.{symbol}.kline.{JsonConvert.SerializeObject(period, new PeriodConverter(false))}");
            var result  = await Query <HuobiSocketResponse <List <HuobiMarketKline> > >(request).ConfigureAwait(false);

            return(new CallResult <List <HuobiMarketKline> >(result.Data?.Data, result.Error));
        }
        /// <summary>
        /// Gets a list of trades for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get trades for</param>
        /// <returns></returns>
        public async Task <CallResult <List <HuobiMarketTradeDetails> > > QueryMarketTradesAsync(string symbol)
        {
            var request = new HuobiSocketRequest($"market.{symbol}.trade.detail");
            var result  = await Query <HuobiSocketResponse <List <HuobiMarketTradeDetails> > >(request).ConfigureAwait(false);

            return(new CallResult <List <HuobiMarketTradeDetails> >(result.Data?.Data, result.Error));
        }
Beispiel #3
0
        /// <summary>
        /// Gets candlestick data for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="period">The period of a single candlestick</param>
        /// <returns></returns>
        public async Task <CallResult <IEnumerable <HuobiKline> > > GetKlinesAsync(string symbol, HuobiPeriod period)
        {
            symbol = symbol.ValidateHuobiSymbol();
            var request = new HuobiSocketRequest(NextId().ToString(), $"market.{symbol}.kline.{JsonConvert.SerializeObject(period, new PeriodConverter(false))}");
            var result  = await Query <HuobiSocketResponse <IEnumerable <HuobiKline> > >(request, false).ConfigureAwait(false);

            return(new CallResult <IEnumerable <HuobiKline> >(result.Data?.Data, result.Error));
        }
Beispiel #4
0
        /// <summary>
        /// Gets a list of trades for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get trades for</param>
        /// <returns></returns>
        public async Task <CallResult <IEnumerable <HuobiSymbolTradeDetails> > > GetTradesAsync(string symbol)
        {
            symbol = symbol.ValidateHuobiSymbol();
            var request = new HuobiSocketRequest(NextId().ToString(), $"market.{symbol}.trade.detail");
            var result  = await Query <HuobiSocketResponse <IEnumerable <HuobiSymbolTradeDetails> > >(request, false).ConfigureAwait(false);

            return(new CallResult <IEnumerable <HuobiSymbolTradeDetails> >(result.Data?.Data, result.Error));
        }
        /// <summary>
        /// Gets details for a market
        /// </summary>
        /// <param name="symbol">The symbol to get data for</param>
        /// <returns></returns>
        public async Task <CallResult <HuobiMarketDetails> > QueryMarketDetailsAsync(string symbol)
        {
            var request = new HuobiSocketRequest($"market.{symbol}.detail");
            var result  = await Query <HuobiSocketResponse <HuobiMarketDetails> >(request).ConfigureAwait(false);

            if (!result.Success)
            {
                return(new CallResult <HuobiMarketDetails>(null, result.Error));
            }

            result.Data.Data.Timestamp = result.Data.Timestamp;
            return(new CallResult <HuobiMarketDetails>(result.Data.Data, null));
        }
Beispiel #6
0
        /// <summary>
        /// Gets details for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get data for</param>
        /// <returns></returns>
        public async Task <CallResult <HuobiSymbolDetails> > GetSymbolDetailsAsync(string symbol)
        {
            symbol = symbol.ValidateHuobiSymbol();
            var request = new HuobiSocketRequest(NextId().ToString(), $"market.{symbol}.detail");
            var result  = await Query <HuobiSocketResponse <HuobiSymbolDetails> >(request, false).ConfigureAwait(false);

            if (!result)
            {
                return(new CallResult <HuobiSymbolDetails>(null, result.Error));
            }

            result.Data.Data.Timestamp = result.Data.Timestamp;
            return(new CallResult <HuobiSymbolDetails>(result.Data.Data, null));
        }
Beispiel #7
0
        /// <summary>
        /// Gets the current order book for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="mergeStep">The way the results will be merged together</param>
        /// <returns></returns>
        public async Task <CallResult <HuobiOrderBook> > GetOrderBookAsync(string symbol, int mergeStep)
        {
            symbol = symbol.ValidateHuobiSymbol();
            mergeStep.ValidateIntBetween(nameof(mergeStep), 0, 5);

            var request = new HuobiSocketRequest(NextId().ToString(), $"market.{symbol}.depth.step{mergeStep}");
            var result  = await Query <HuobiSocketResponse <HuobiOrderBook> >(request, false).ConfigureAwait(false);

            if (!result)
            {
                return(new CallResult <HuobiOrderBook>(null, result.Error));
            }

            result.Data.Data.Timestamp = result.Data.Timestamp;
            return(new CallResult <HuobiOrderBook>(result.Data.Data, null));
        }
        /// <summary>
        /// Gets the current order book for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="mergeStep">The way the results will be merged together</param>
        /// <returns></returns>
        public async Task <CallResult <HuobiMarketDepth> > QueryMarketDepthAsync(string symbol, int mergeStep)
        {
            if (mergeStep < 0 || mergeStep > 5)
            {
                return(new CallResult <HuobiMarketDepth>(null, new ArgumentError("Merge step should be between 0 and 5")));
            }

            var request = new HuobiSocketRequest($"market.{symbol}.depth.step{mergeStep}");
            var result  = await Query <HuobiSocketResponse <HuobiMarketDepth> >(request).ConfigureAwait(false);

            if (!result.Success)
            {
                return(new CallResult <HuobiMarketDepth>(null, result.Error));
            }

            result.Data.Data.Timestamp = result.Data.Timestamp;
            return(new CallResult <HuobiMarketDepth>(result.Data.Data, null));
        }
Beispiel #9
0
        /// <summary>
        /// Gets the current order book for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="levels">The amount of rows. 5, 20, 150 or 400. Level 5 and 20 are currently only supported for the following symbols: btcusdt, ethusdt, xrpusdt, eosusdt, ltcusdt, etcusdt, adausdt, dashusdt, bsvusdt.</param>
        /// <returns></returns>
        public async Task <CallResult <HuobiIncementalOrderBook> > GetOrderBookAsync(string symbol, int levels)
        {
            symbol = symbol.ValidateHuobiSymbol();
            levels.ValidateIntValues(nameof(levels), 5, 20, 150, 400);

            var request = new HuobiSocketRequest(NextId().ToString(CultureInfo.InvariantCulture), $"market.{symbol}.mbp.{levels}");
            var result  = await QueryAsync <HuobiSocketResponse <HuobiIncementalOrderBook> >(baseAddressMbp, request, false).ConfigureAwait(false);

            if (!result)
            {
                return(new CallResult <HuobiIncementalOrderBook>(null, result.Error));
            }

            if (result.Data.Data == null)
            {
                var info = $"No data received when requesting order book. " +
                           $"Levels 5/20 are only supported for a subset of symbols, see https://huobiapi.github.io/docs/spot/v1/en/#market-by-price-incremental-update. Use 150 level instead.";
                log.Write(LogLevel.Debug, info);
                return(new CallResult <HuobiIncementalOrderBook>(null, new ServerError(info)));
            }

            return(new CallResult <HuobiIncementalOrderBook>(result.Data.Data, null));
        }