Beispiel #1
0
        private TradeHistory parsePublicTradeHistory(string s, bool isSingle)
        {
            List<Order> OList = new List<Order>();
            TradeHistory t = new TradeHistory();

            JContainer r;

            if (s.ToUpper().Contains("INVALID TICKER"))
            {
                throw (new BTCTException("Invalid ticker."));
            }

            if (isSingle)
            {
                try
                {
                    r = JArray.Parse(s);
                }
                catch (Newtonsoft.Json.JsonReaderException ex)
                {
                    throw (new BTCTException("Invalid response format."));
                }
            }
            else
            {
                try
                {
                    r = JObject.Parse(s);
                }
                catch (Newtonsoft.Json.JsonReaderException ex)
                {
                    throw (new BTCTException("Invalid response format."));
                }
            }

            if (!isSingle)
            {
                foreach (JProperty ch in r.Children())
                {
                    Order o = new Order();
                    Security sec = new Security();

                    JToken c = ch.First;
                    if (c.HasValues)
                    {
                        o.active = false;
                        o.id = Convert.ToInt32((string)c["trade_id"]);
                        o.amount = Convert.ToInt32((string)c["quantity"]);
                        o.dateTime = BTCTUtils.UnixTimeStampToDateTime(Convert.ToInt32((string)c["timestamp"]));
                        o.price = BTCTUtils.StringToSatoshi((string)c["amount"]);
                        o.orderType = BTCTUtils.StringToOrderType((string)c["type"]);
                        sec.name = (string)c["ticker"];
                        o.security = sec;
                        OList.Add(o);
                    }
                }
                t.lastUpdate = BTCTUtils.UnixTimeStampToDateTime(Convert.ToInt32((string)r.Last.First));
            }
            else
            {
                for (int i = 0; i < r.Count; i++)
                {
                    Order o = new Order();
                    Security sec = new Security();

                    o.active = false;
                    o.id = Convert.ToInt32((string)r[i]["trade_id"]);
                    o.amount = Convert.ToInt32((string)r[i]["quantity"]);
                    o.dateTime = BTCTUtils.UnixTimeStampToDateTime(Convert.ToInt32((string)r[i]["timestamp"]));
                    o.price = BTCTUtils.StringToSatoshi((string)r[i]["amount"]);
                    o.orderType = BTCTUtils.StringToOrderType((string)r[i]["type"]);
                    sec.name = (string)r[i]["ticker"];
                    o.security = sec;
                    OList.Add(o);
                }
            }
            t.orders = OList;

            return t;
        }
Beispiel #2
0
        private TradeHistory parseTradeHistory(string s)
        {
            List<Order> OList = new List<Order>();
            TradeHistory t = new TradeHistory();

            string[] lines = s.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            // First line contains column headers, which we can ignore
            for (int i = 1; i < lines.Length; i++)
            {
                Order o = new Order();
                Security se = new Security();

                string[] fields = lines[i].Split(new Char[] { ',' });

                o.id = Convert.ToInt32(fields[0]);
                se.name = fields[1];
                o.orderType = BTCTUtils.StringToOrderType(fields[2]);
                if (o.orderType == OrderType.OT_TIN || o.orderType == OrderType.OT_TOUT)
                {
                    int start = fields[2].IndexOf('(');
                    int stop = fields[2].IndexOf(')');
                    o.transferUser = fields[2].Substring(start + 1, stop - start - 1);
                }
                o.amount = Convert.ToInt32(fields[3]);
                o.price = BTCTUtils.StringToSatoshi(fields[4]);
                // date/time string comes in quotes from BTCT for some reason.
                o.dateTime = DateTime.Parse(fields[5].Substring(1, fields[5].Length - 2));
                o.security = se;

                OList.Add(o);
            }
            t.orders = OList;
            t.lastUpdate = DateTime.Now;

            return t;
        }