Beispiel #1
0
        private DividendHistory parsePublicDividendHistory(string s)
        {
            DividendHistory dh = new DividendHistory();
            List<Dividend> dl = new List<Dividend>();

            JContainer r;

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

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

            foreach (JProperty ch in r.Children())
            {
                Dividend d = new Dividend();
                Security sec = new Security();

                JToken c = ch.First;
                if (c.HasValues)
                {
                    d.shares = Convert.ToInt32((string)c["shares_paid"]);
                    d.shares = d.shares == 0 ? 1 : d.shares;
                    d.id = Convert.ToInt32((string)c["id"]);
                    d.dateTime = BTCTUtils.UnixTimeStampToDateTime(Convert.ToInt32((string)c["process_time"]));
                    d.dividend = BTCTUtils.StringToSatoshi((string)c["amount"]) / d.shares;
                    d.status = BTCTUtils.StringToDivStatus((string)c["status"]);
                    sec.name = (string)c["ticker"];
                    d.security = sec;
                    dl.Add(d);
                }
            }
            dh.lastUpdate = BTCTUtils.UnixTimeStampToDateTime(Convert.ToInt32((string)r.Last.First));
            dh.dividends = dl;

            return dh;
        }
Beispiel #2
0
        private DividendHistory parseDividendHistory(string s)
        {
            DividendHistory dh = new DividendHistory();
            List<Dividend> l = new List<Dividend>();

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

            for (int i = 1; i < lines.Length; i++)
            {
                Dividend d = new Dividend();
                Security se = new Security();

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

                se.name = fields[0];
                d.shares = Convert.ToInt32(fields[1]);
                d.dividend = BTCTUtils.StringToSatoshi(fields[2]);
                d.dateTime = DateTime.Parse(fields[4].Substring(1, fields[4].Length - 2));
                d.security = se;

                l.Add(d);
            }

            dh.dividends = l;
            dh.lastUpdate = DateTime.Now;

            return dh;
        }