示例#1
0
        // K线历史数据
        // symbol: 交易对, 形如 tchbtc, ethbtc,btcbitcny,eosbtc...
        // period: K线类型, 形如 1min,5min,15min,30min,60min,1day,1week,1month
        // size  : 获取数量, 取值范围[1,2000]
        public static MarketKLine GetMarketKLine(string symbol, string period, int size)
        {
            string strResponse = Http.Get(V1.URL + "/market/history/kline", string.Format("symbol={0}&period={1}&size={2}", symbol, period, size));

            if (string.IsNullOrEmpty(strResponse))
            {
                return(null);
            }

            Response response = Response.FromString(strResponse);

            if (response == null || response.code != "0" || response.msg != "suc" || string.IsNullOrEmpty(response.data))
            {
                return(null);
            }

            MarketKLine marketKLine = MarketKLine.FromString(response.data);

            if (marketKLine == null || string.IsNullOrEmpty(marketKLine.symbol))
            {
                return(null);
            }

            return(marketKLine);
        }
示例#2
0
        public static MarketKLine FromString(string strResponseData)
        {
            Json.Dictionary dict = Json.ToDictionary(strResponseData);
            if (dict == null)
            {
                return(null);
            }

            MarketKLine marketKLine = new MarketKLine();

            marketKLine.symbol = dict["symbol"];
            if (string.IsNullOrEmpty(marketKLine.symbol))
            {
                return(null);
            }

            Json.Array kline_data = Json.ToArray(Json.GetAt(dict, "kline_data"));
            foreach (string dataItem in kline_data)
            {
                Json.Dictionary dataItemDist = Json.ToDictionary(dataItem);
                Item            item         = new Item();
                item.id     = Int64.Parse(dataItemDist["id"]);
                item.amount = double.Parse(dataItemDist["amount"]);
                item.vol    = double.Parse(dataItemDist["vol"]);
                item.high   = double.Parse(dataItemDist["high"]);
                item.low    = double.Parse(dataItemDist["low"]);
                item.close  = double.Parse(dataItemDist["close"]);
                item.open   = double.Parse(dataItemDist["open"]);

                if (marketKLine.kline_data == null)
                {
                    marketKLine.kline_data = new System.Collections.Generic.List <Item>();
                }

                marketKLine.kline_data.Add(item);
            }

            return(marketKLine);
        }