Beispiel #1
0
        /// <summary>
        /// Retrieves all klines in a specific range.
        /// Implements end point https://api.huobi.pro/market/history/kline
        /// </summary>
        /// <param name="symbol">The trading symbol to query</param>
        /// <param name="period">The period of each candle</param>
        /// <param name="size">The number of data returns. It should be in the range [1, 2000]</param>
        /// <returns>List of Ticker objects</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when size is not in range [1, 2000]</exception>
        /// <exception cref="System.ArgumentException">Thrown when symbol is empty or null</exception>
        public async Task <List <Ticker> > GetTickerHistory(string symbol, TickerPeriod period, int?size)
        {
            if (size != null && (size < 1 || size > 2000))
            {
                throw new ArgumentOutOfRangeException("size", "size parameter should be in [1, 2000] range");
            }

            if (string.IsNullOrEmpty(symbol))
            {
                throw new ArgumentException("symbol parameter is required", "symbol");
            }

            SortedDictionary <string, string> parameters = new SortedDictionary <string, string>()
            {
                { "symbol", symbol }, { "period", period.ToParamValue() }
            };

            if (size != null)
            {
                parameters.Add("size", size.ToString());
            }

            string json = await HttpGetRequest(FormatUri(url_market_data + "history/kline", HttpMethod.Get, parameters, read_access_key, read_secret_key));

            var res = JsonParse <List <Ticker> >(json);

            return(await res);
        }
Beispiel #2
0
        public void TestGetTickerHistory(string ccy, TickerPeriod period, int?size)
        {
            var ticker_history = RestApi.GetTickerHistory(ccy, period, size);

            if (!string.IsNullOrEmpty(ccy) && size <= 2000 && size > 0)
            {
                ticker_history.Wait();

                Assert.Equal(TaskStatus.RanToCompletion, ticker_history.Status);
                Assert.Equal(size, ticker_history.Result.Count);
            }

            // Test Exceptions
            else
            {
                if (size > 2000 || size < 1)
                {
                    var ex = Assert.Throws <ArgumentOutOfRangeException>(() => ThrowsInnerException(ticker_history));

                    Assert.Equal(TaskStatus.Faulted, ticker_history.Status);
                    Assert.Equal("size parameter should be in [1, 2000] range\r\nParameter name: size", ex.Message);
                }

                else if (string.IsNullOrEmpty(ccy))
                {
                    var ex = Assert.Throws <ArgumentException>(() => ThrowsInnerException(ticker_history));

                    Assert.Equal(TaskStatus.Faulted, ticker_history.Status);
                    Assert.Equal("symbol parameter is required\r\nParameter name: symbol", ex.Message);
                }
            }
        }
        /// <summary>
        /// Represent the equivalence of TickerPeriod enumeration used solely when communicating with exchange server.
        /// </summary>
        public static string ToParamValue(this TickerPeriod period)
        {
            switch (period)
            {
            case TickerPeriod.Min1:
                return("1min");

            case TickerPeriod.Min5:
                return("5min");

            case TickerPeriod.Min15:
                return("15min");

            case TickerPeriod.Min30:
                return("30min");

            case TickerPeriod.Min60:
                return("60min");

            case TickerPeriod.Hour4:
                return("4hour");

            case TickerPeriod.Day1:
                return("1day");

            case TickerPeriod.Mon1:
                return("1mon");

            case TickerPeriod.Week1:
                return("1week");

            case TickerPeriod.Year1:
                return("1year");

            default:
                return(period.ToString());
            }
        }
Beispiel #4
0
        public static string ToKey(this TickerPeriod period)
        {
            switch (period)
            {
            case TickerPeriod.Min1:
                return("1m");

            case TickerPeriod.Min5:
                return("5m");

            case TickerPeriod.Min15:
                return("15m");

            case TickerPeriod.Min30:
                return("30m");

            case TickerPeriod.Min60:
                return("1h");

            case TickerPeriod.Hour4:
                return("4h");

            case TickerPeriod.Day1:
                return("1d");

            case TickerPeriod.Mon1:
                return("1mon");

            case TickerPeriod.Week1:
                return("1w");

            case TickerPeriod.Year1:
                return("1y");

            default:
                return(period.ToString());
            }
        }
Beispiel #5
0
        public static Int64 ToSeconds(this TickerPeriod period)
        {
            switch (period)
            {
            case TickerPeriod.Min1:
                return(60);

            case TickerPeriod.Min5:
                return(5 * 60);

            case TickerPeriod.Min15:
                return(15 * 60);

            case TickerPeriod.Min30:
                return(30 * 60);

            case TickerPeriod.Min60:
                return(60 * 60);

            case TickerPeriod.Hour4:
                return(4 * 60 * 60);

            case TickerPeriod.Day1:
                return(24 * 60 * 60);

            case TickerPeriod.Mon1:
                return(30 * 24 * 60 * 60);

            case TickerPeriod.Week1:
                return(7 * 24 * 60 * 60);

            case TickerPeriod.Year1:
                return(365 * 24 * 60 * 60);

            default:
                return(0);
            }
        }
Beispiel #6
0
 public TickerHistoryParameters(string symbol, TickerPeriod period, int size)
 {
     this.symbol = symbol;
     this.period = period;
     this.size   = size;
 }