Esempio n. 1
1
 /// <summary>
 /// Parses the JSON data returned by the 0/data/getTrades.php method
 /// </summary>        
 public static List<MtGoxTrade> getObjects(string jsonDataStr)
 {
     List<MtGoxTrade> tradeList = new List<MtGoxTrade>();
     string json = jsonDataStr;
     var serializer = new JavaScriptSerializer();
     serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
     dynamic obj = serializer.Deserialize(json, typeof(object));
     for (int i = 0; i < obj.Length; i++)
     {
         MtGoxTrade trade = new MtGoxTrade();
         trade.date = obj[i].date;
         trade.price = Double.Parse(obj[i].price);
         trade.amount = Double.Parse(obj[i].amount);
         trade.price_int = Int64.Parse(obj[i].price_int);
         trade.amount_int = Int64.Parse(obj[i].amount_int);
         trade.tid = obj[i].tid;
         if (Enum.IsDefined(typeof(MtGoxCurrencySymbol), obj[i].price_currency))
             trade.price_currency = (MtGoxCurrencySymbol)Enum.Parse(typeof(MtGoxCurrencySymbol), obj[i].price_currency, true);
         trade.item = obj[i].item;
         if (Enum.IsDefined(typeof(MtGoxTradeType), obj[i].trade_type))
             trade.trade_type = (MtGoxTradeType)Enum.Parse(typeof(MtGoxTradeType), obj[i].trade_type, true);
         trade.primary = obj[i].primary;
         tradeList.Add(trade);
         if (i > 100)
             break;
     }
     return tradeList;
 }
Esempio n. 2
0
        public void Initialize()
        {
            depth = new MtGoxDepthInfo();
            tradeListInFiveMin = new List<MtGoxTrade>();
            tradeListInOneMin = new List<MtGoxTrade>();
            ticker = new MtGoxTickerItem();

            for (int i = 0; i < 100; i++)
            {
                MtGoxAsk a = new MtGoxAsk();
                a.amount = i + 1;
                a.price = i + 1;
                depth.asks.Add(a);
                MtGoxBid b = new MtGoxBid();
                b.amount = i + 1;
                b.price = i + 1;
                depth.bids.Add(b);
                MtGoxTrade t = new MtGoxTrade();
                t.amount = i + 1;
                t.price = i + 1;
                tradeListInFiveMin.Add(t);
                tradeListInOneMin.Add(t);
            }
            ticker.last = 5;
        }
        /// <summary>
        /// Parses the JSON data returned by the 0/data/getTrades.php method
        /// </summary>
        public static List <MtGoxTrade> getObjects(string jsonDataStr)
        {
            List <MtGoxTrade> tradeList = new List <MtGoxTrade>();
            string            json      = jsonDataStr;
            var serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic obj = serializer.Deserialize(json, typeof(object));

            for (int i = 0; i < obj.Length; i++)
            {
                MtGoxTrade trade = new MtGoxTrade();
                trade.date       = obj[i].date;
                trade.price      = Double.Parse(obj[i].price);
                trade.amount     = Double.Parse(obj[i].amount);
                trade.price_int  = Int64.Parse(obj[i].price_int);
                trade.amount_int = Int64.Parse(obj[i].amount_int);
                trade.tid        = obj[i].tid;
                if (Enum.IsDefined(typeof(MtGoxCurrencySymbol), obj[i].price_currency))
                {
                    trade.price_currency = (MtGoxCurrencySymbol)Enum.Parse(typeof(MtGoxCurrencySymbol), obj[i].price_currency, true);
                }
                trade.item = obj[i].item;
                if (Enum.IsDefined(typeof(MtGoxTradeType), obj[i].trade_type))
                {
                    trade.trade_type = (MtGoxTradeType)Enum.Parse(typeof(MtGoxTradeType), obj[i].trade_type, true);
                }
                trade.primary = obj[i].primary;
                tradeList.Add(trade);
                if (i > 100)
                {
                    break;
                }
            }
            return(tradeList);
        }