コード例 #1
0
        public static bool ParseTimeSeriesEntry(ref CryptoDataItem dataItem, JObject jobject,
                                                string openKey, string highKey, string lowKey, string closeKey)
        {
            dataItem._open  = JsonHelper.GetDecimalValue(jobject, openKey);
            dataItem._high  = JsonHelper.GetDecimalValue(jobject, highKey);
            dataItem._low   = JsonHelper.GetDecimalValue(jobject, lowKey);
            dataItem._close = JsonHelper.GetDecimalValue(jobject, closeKey);

            dataItem._openUSD  = JsonHelper.GetDecimalValue(jobject, OPEN_USD_KEY);
            dataItem._highUSD  = JsonHelper.GetDecimalValue(jobject, HIGH_USD_KEY);
            dataItem._lowUSD   = JsonHelper.GetDecimalValue(jobject, LOW_USD_KEY);
            dataItem._closeUSD = JsonHelper.GetDecimalValue(jobject, CLOSE_USD_KEY);

            dataItem._volume       = JsonHelper.GetDecimalValue(jobject, VOLUME_KEY);
            dataItem._marketCapUSD = JsonHelper.GetDecimalValue(jobject, MARKET_CAP_KEY);

            return(true);
        }
コード例 #2
0
        public override void Init(JObject json)
        {
            string timeSeriesKey  = GetTypeJsonKey(DataType);
            bool   containAllKeys = json.ContainsKey(META_DATA) && json.ContainsKey(timeSeriesKey);

            if (!containAllKeys)
            {
                throw new FormatException("JSON result cannot be parsed (missing main properties");
            }

            var metaData   = (JObject)json.GetValue(META_DATA);
            var timeSeries = json.GetValue(timeSeriesKey);

            // TODO
            Currency = JsonHelper.GetValue(metaData, DIGITAL_CURRENCY_CODE_KEY);
            Market   = JsonHelper.GetValue(metaData, MARKET_CODE_KEY);
            Data     = new SortedDictionary <DateTime, CryptoDataItem>();

            string openKey  = OPEN_USD_KEY.Replace("b.", "a.").Replace("USD", Market);
            string highKey  = HIGH_USD_KEY.Replace("b.", "a.").Replace("USD", Market);
            string lowKey   = LOW_USD_KEY.Replace("b.", "a.").Replace("USD", Market);
            string closeKey = CLOSE_USD_KEY.Replace("b.", "a.").Replace("USD", Market);

            foreach (var entry in timeSeries.Children <JProperty>())
            {
                Console.WriteLine(entry.Name);
                DateTime dateTime = DateTime.ParseExact(entry.Name, AV_DATE_FORMAT, CultureInfo.InvariantCulture);

                JObject        entryData = entry.Value as JObject;
                CryptoDataItem dataItem  = default(CryptoDataItem);
                dataItem._date = dateTime;
                if (ParseTimeSeriesEntry(ref dataItem, entryData, openKey, highKey, lowKey, closeKey))
                {
                    Data[dataItem._date] = dataItem;
                }
            }
        }