예제 #1
0
        // 前24小时行情
        // symbol: 交易对, 形如 tchbtc, ethbtc,btcbitcny,eosbtc...
        public static MarketDetail GetMarketDetail(string symbol)
        {
            string strResponse = Http.Get(V1.URL + "/market/detail", string.Format("symbol={0}", symbol));

            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);
            }

            MarketDetail marketDetail = MarketDetail.FromString(response.data);

            if (marketDetail == null || marketDetail.ts <= 0)
            {
                return(null);
            }

            return(marketDetail);
        }
예제 #2
0
        public Int64 ts      = 0;       // 数据产生时间,单位:毫秒

        public static MarketDetail FromString(string strResponseData)
        {
            Json.Dictionary dict = Json.ToDictionary(strResponseData);
            if (dict == null)
            {
                return(null);
            }

            MarketDetail marketDetail = new MarketDetail();

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

            Json.Dictionary trade_ticker_data = Json.ToDictionary(Json.GetAt(dict, "trade_ticker_data"));
            marketDetail.ts = Int64.Parse(trade_ticker_data["ts"]);

            Json.Dictionary tick = Json.ToDictionary(trade_ticker_data["tick"]);
            marketDetail.amount = double.Parse(tick["amount"]);
            marketDetail.vol    = double.Parse(tick["vol"]);
            marketDetail.high   = double.Parse(tick["high"]);
            marketDetail.low    = double.Parse(tick["low"]);
            marketDetail.rose   = double.Parse(tick["rose"]);
            marketDetail.close  = double.Parse(tick["close"]);
            marketDetail.open   = double.Parse(tick["open"]);

            return(marketDetail);
        }