示例#1
0
        /// <summary>
        /// Get candlestick data for a market
        /// </summary>
        /// <param name="symbol">The symbol to get the data for</param>
        /// <param name="period">The period of a single candlestick</param>
        /// <param name="size">The amount of candlesticks</param>
        /// <returns></returns>
        public async Task <WebCallResult <List <HuobiMarketKline> > > GetMarketKlinesAsync(string symbol, HuobiPeriod period, int size)
        {
            if (size <= 0 || size > 2000)
            {
                return(WebCallResult <List <HuobiMarketKline> > .CreateErrorResult(new ArgumentError("Size should be between 1 and 2000")));
            }

            var parameters = new Dictionary <string, object>
            {
                { "symbol", symbol },
                { "period", JsonConvert.SerializeObject(period, new PeriodConverter(false)) },
                { "size", size }
            };

            var result = await ExecuteRequest <HuobiChannelResponse <List <HuobiMarketKline> > >(GetUrl(MarketKlineEndpoint), parameters : parameters).ConfigureAwait(false);

            if (!result.Success)
            {
                return(WebCallResult <List <HuobiMarketKline> > .CreateErrorResult(result.ResponseStatusCode, result.ResponseHeaders, result.Error));
            }

            return(new WebCallResult <List <HuobiMarketKline> >(result.ResponseStatusCode, result.ResponseHeaders, result.Data.Data, null));
        }
示例#2
0
 /// <summary>
 /// Subscribes to candlestick updates for a symbol
 /// </summary>
 /// <param name="symbol">The symbol to subscribe to</param>
 /// <param name="period">The period of a single candlestick</param>
 /// <param name="onData">The handler for updates</param>
 /// <returns></returns>
 public CallResult <UpdateSubscription> SubscribeToKlineUpdates(string symbol, HuobiPeriod period, Action <HuobiKline> onData) => SubscribeToKlineUpdatesAsync(symbol, period, onData).Result;
示例#3
0
 /// <summary>
 /// Get candlestick data for a market
 /// </summary>
 /// <param name="symbol">The symbol to get the data for</param>
 /// <param name="period">The period of a single candlestick</param>
 /// <param name="size">The amount of candlesticks</param>
 /// <returns></returns>
 public WebCallResult <List <HuobiMarketKline> > GetMarketKlines(string symbol, HuobiPeriod period, int size) => GetMarketKlinesAsync(symbol, period, size).Result;
示例#4
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 CallResult <IEnumerable <HuobiKline> > GetKlines(string symbol, HuobiPeriod period) => GetKlinesAsync(symbol, period).Result;
示例#5
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));
        }
示例#6
0
        /// <summary>
        /// Subscribes to candlestick updates for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to subscribe to</param>
        /// <param name="period">The period of a single candlestick</param>
        /// <param name="onData">The handler for updates</param>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToKlineUpdatesAsync(string symbol, HuobiPeriod period, Action <HuobiKline> onData)
        {
            symbol = symbol.ValidateHuobiSymbol();
            var request         = new HuobiSubscribeRequest(NextId().ToString(), $"market.{symbol}.kline.{JsonConvert.SerializeObject(period, new PeriodConverter(false))}");
            var internalHandler = new Action <HuobiSocketUpdate <HuobiKline> >(data => onData(data.Data));

            return(await Subscribe(request, null, false, internalHandler).ConfigureAwait(false));
        }
示例#7
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 <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));
        }
示例#8
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 CallResult <List <HuobiMarketKline> > QueryMarketKlines(string symbol, HuobiPeriod period) => QueryMarketKlinesAsync(symbol, period).Result;
示例#9
0
        /// <summary>
        /// Get 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>
        /// <param name="size">The amount of candlesticks</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns></returns>
        public async Task <WebCallResult <IEnumerable <HuobiKline> > > GetKlinesAsync(string symbol, HuobiPeriod period, int size, CancellationToken ct = default)
        {
            symbol = symbol.ValidateHuobiSymbol();
            size.ValidateIntBetween(nameof(size), 0, 2000);

            var parameters = new Dictionary <string, object>
            {
                { "symbol", symbol },
                { "period", JsonConvert.SerializeObject(period, new PeriodConverter(false)) },
                { "size", size }
            };

            return(await SendHuobiRequest <IEnumerable <HuobiKline> >(GetUrl(MarketKlineEndpoint), HttpMethod.Get, ct, parameters).ConfigureAwait(false));
        }
示例#10
0
 /// <summary>
 /// Get 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>
 /// <param name="size">The amount of candlesticks</param>
 /// <param name="ct">Cancellation token</param>
 /// <returns></returns>
 public WebCallResult <IEnumerable <HuobiKline> > GetKlines(string symbol, HuobiPeriod period, int size, CancellationToken ct = default) => GetKlinesAsync(symbol, period, size, ct).Result;