Exemple #1
0
        public static MakeDetail FromString(string strResponseData)
        {
            Json.Array array = Json.ToArray(strResponseData);
            if (array == null)
            {
                return(null);
            }

            MakeDetail makeDetail = new MakeDetail();

            makeDetail.items = new System.Collections.Generic.List <Item>();
            foreach (string dataItem in array)
            {
                Json.Dictionary dataItemDict = Json.ToDictionary(dataItem);

                Item item = new Item();
                item.id      = long.Parse(dataItemDict["id"]);
                item.volume  = double.Parse(dataItemDict["volume"]);
                item.price   = double.Parse(dataItemDict["price"]);
                item.symbol  = dataItemDict["symbol"];
                item.type    = dataItemDict["type"];
                item.source  = dataItemDict["source"];
                item.orderId = long.Parse(dataItemDict["orderId"]);
                long.TryParse(Json.GetAt(dataItemDict, "bid_user_id"), out item.bid_user_id);
                long.TryParse(Json.GetAt(dataItemDict, "ask_user_id"), out item.ask_user_id);
                double.TryParse(Json.GetAt(dataItemDict, "buy_fee"), out item.buy_fee);
                double.TryParse(Json.GetAt(dataItemDict, "sell_fee"), out item.sell_fee);
                item.created = Int64.Parse(dataItemDict["created"]);

                makeDetail.items.Add(item);
            }

            return(makeDetail);
        }
        public static MatchResults FromString(string strResponseData)
        {
            Json.Array array = Json.ToArray(strResponseData);
            if (array == null)
            {
                return(null);
            }

            MatchResults matchResults = new MatchResults();

            matchResults.items = new System.Collections.Generic.List <Item>();
            foreach (string dataItem in array)
            {
                Json.Dictionary dataItemDict = Json.ToDictionary(dataItem);

                Item item = new Item();
                item.id      = long.Parse(Json.GetAt(dataItemDict, "id"));
                item.price   = double.Parse(Json.GetAt(dataItemDict, "price"));
                item.volume  = double.Parse(Json.GetAt(dataItemDict, "volume"));
                item.fee     = double.Parse(Json.GetAt(dataItemDict, "fee"));
                item.orderId = long.Parse(Json.GetAt(dataItemDict, "orderId"));
                item.symbol  = Json.GetAt(dataItemDict, "symbol");
                item.type    = Json.GetAt(dataItemDict, "type");
                item.status  = int.Parse(Json.GetAt(dataItemDict, "status"));
                item.mtime   = Int64.Parse(Json.GetAt(dataItemDict, "mtime"));
                item.source  = Json.GetAt(dataItemDict, "source");

                matchResults.items.Add(item);
            }

            return(matchResults);
        }
Exemple #3
0
        public static Balance FromString(string strResponseData)
        {
            Json.Array array = Json.ToArray(strResponseData);
            if (array == null)
            {
                return(null);
            }

            Balance balance = new Balance();

            if (array.Count > 0)
            {
                balance.items = new System.Collections.Generic.List <Item>();
                for (int i = 0; i < array.Count; i++)
                {
                    Item            item    = new Item();
                    string          strItem = Json.GetAt(array, i);
                    Json.Dictionary dict    = Json.ToDictionary(strItem);
                    item.coin   = Json.GetAt(dict, "coin");
                    item.normal = Convert.ToDouble(Json.GetAt(dict, "normal"));
                    item.locK   = Convert.ToDouble(Json.GetAt(dict, "lock"));
                    balance.items.Add(item);
                }
            }

            return(balance);
        }
Exemple #4
0
        public Int64 ts = 0;                                       // 消息生成时间,单位:毫秒

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

            MarketDepth marketDepth = new MarketDepth();

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

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

            Json.Dictionary tick = Json.ToDictionary(depth_data["tick"]);
            Json.Array      buys = Json.ToArray(tick["buys"]);
            Json.Array      asks = Json.ToArray(tick["asks"]);
            foreach (string buyItem in buys)
            {
                Json.Array buyItemArray = Json.ToArray(buyItem);
                Item       item         = new Item();
                item.price  = double.Parse(buyItemArray[0]);
                item.amount = double.Parse(buyItemArray[1]);

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

                marketDepth.buys.Add(item);
            }
            foreach (string askItem in asks)
            {
                Json.Array askItemArray = Json.ToArray(askItem);
                Item       item         = new Item();
                item.price  = double.Parse(askItemArray[0]);
                item.amount = double.Parse(askItemArray[1]);

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

                marketDepth.asks.Add(item);
            }

            return(marketDepth);
        }
Exemple #5
0
        public static Currencys FromString(string strResponseData)
        {
            Json.Dictionary dict = Json.ToDictionary(strResponseData);
            if (dict == null)
            {
                return(null);
            }

            Currencys currencys = new Currencys();

            foreach (var part in dict)
            {
                Partition partition = new Partition();
                partition.name = part.Key;
                Json.Array array = Json.ToArray(part.Value);
                if (array != null)
                {
                    partition.items = new System.Collections.Generic.List <Currency>();
                    foreach (var it in array)
                    {
                        Json.Dictionary dictItem = Json.ToDictionary(it);
                        Currency        item     = new Currency();
                        item.baseCurrency    = Json.GetAt(dictItem, "baseCurrency");
                        item.quoteCurrency   = Json.GetAt(dictItem, "quoteCurrency");
                        item.pricePrecision  = Convert.ToInt32(Json.GetAt(dictItem, "pricePrecision"));
                        item.amountPrecision = Convert.ToInt32(Json.GetAt(dictItem, "amountPrecision"));
                        item.withdrawFeeMin  = Convert.ToDouble(Json.GetAt(dictItem, "withdrawFeeMin"));
                        item.withdrawFeeMax  = Convert.ToDouble(Json.GetAt(dictItem, "withdrawFeeMax"));
                        item.withdrawOneMin  = Convert.ToDouble(Json.GetAt(dictItem, "withdrawOneMin"));
                        item.withdrawOneMax  = Convert.ToDouble(Json.GetAt(dictItem, "withdrawOneMax"));
                        Json.Dictionary dictDS = Json.ToDictionary(Json.GetAt(dictItem, "depthSelect"));
                        item.depthSelect       = new Currency.DepthSelect();
                        item.depthSelect.step0 = Convert.ToDouble(Json.GetAt(dictDS, "step0"));
                        item.depthSelect.step1 = Convert.ToDouble(Json.GetAt(dictDS, "step1"));
                        item.depthSelect.step2 = Convert.ToDouble(Json.GetAt(dictDS, "step2"));
                        partition.items.Add(item);
                    }
                }

                if (currencys.partitions == null)
                {
                    currencys.partitions = new System.Collections.Generic.List <Partition>();
                }

                currencys.partitions.Add(partition);
            }

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

            MarketTrade marketTrade = new MarketTrade();

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

            int size = int.Parse(dict["size"]);

            Json.Array trade_data = Json.ToArray(Json.GetAt(dict, "trade_data"));
            foreach (string dataItem in trade_data)
            {
                Json.Dictionary dataItemDist = Json.ToDictionary(dataItem);
                Item            item         = new Item();
                item.id     = int.Parse(dataItemDist["id"]);
                item.side   = dataItemDist["side"];
                item.price  = double.Parse(dataItemDist["price"]);
                item.vol    = double.Parse(dataItemDist["vol"]);
                item.amount = double.Parse(dataItemDist["amount"]);
                item.ts     = Int64.Parse(dataItemDist["ts"]);
                item.ds     = dataItemDist["ds"];

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

                marketTrade.trade_data.Add(item);
            }
            if (marketTrade.trade_data.Count != size)
            {
                return(null);
            }

            return(marketTrade);
        }
Exemple #7
0
        public async Task<bool> Read() {
            if (flag % 10 == 0) {
                string url = CreateAPIUrl();
                string Data = await GetHTML(url);//等候
                Json.Object temp = new Json.Object(Data);
                if ((bool)temp["ok"]) {
                    count = int.Parse(temp["rsp", "total"].ToString());
                    Now = (Json.Array)temp["rsp", "vlogs"];
                } else {
                    return false;
                }
            }
            if (flag == count || count == 0) return false;
            this.Item = new ItemData();
            this.Item.FromJson((Json.Object)Now[flag % 10], true);

            this.Item.thumb = Regex.Unescape(this.Item.thumb);
            this.Item.title = Regex.Unescape(this.Item.title);
            flag++;
            return true;
        }
Exemple #8
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);
        }
Exemple #9
0
        public static OrdersDetail FromString(string strResponseData)
        {
            Json.Array array = Json.ToArray(strResponseData);
            if (array == null)
            {
                return(null);
            }

            OrdersDetail ordersDetail = new OrdersDetail();

            ordersDetail.items = new System.Collections.Generic.List <OrderDetail>();
            foreach (string dataItem in array)
            {
                Json.Dictionary dataItemDict = Json.ToDictionary(dataItem);

                OrderDetail item = new OrderDetail();
                item.user_id = long.Parse(Json.GetAt(dataItemDict, "user_id"));
                item.symbol  = Json.GetAt(dataItemDict, "symbol");
                item.id      = long.Parse(Json.GetAt(dataItemDict, "id"));
                item.type    = Json.GetAt(dataItemDict, "type");
                item.volume  = double.Parse(Json.GetAt(dataItemDict, "volume"));
                item.price   = double.Parse(Json.GetAt(dataItemDict, "price"));
                double.TryParse(Json.GetAt(dataItemDict, "avg_price"), out item.avg_price);
                int.TryParse(Json.GetAt(dataItemDict, "status"), out item.status);
                double.TryParse(Json.GetAt(dataItemDict, "deal_volume"), out item.deal_volume);
                item.deal_money = double.Parse(Json.GetAt(dataItemDict, "deal_money"));
                item.fee        = double.Parse(Json.GetAt(dataItemDict, "fee"));
                item.source     = int.Parse(Json.GetAt(dataItemDict, "source"));
                item.ctime      = Int64.Parse(Json.GetAt(dataItemDict, "ctime"));
                item.mtime      = Int64.Parse(Json.GetAt(dataItemDict, "mtime"));

                ordersDetail.items.Add(item);
            }

            return(ordersDetail);
        }