Esempio n. 1
0
        /// <summary>
        /// Download data about fear and greed on crypto market and save it to Influx
        /// </summary>
        internal async Task DownloadFearAndGreed()
        {
            InfluxConfig config  = configManager.GetSecretToken();
            FearAndGreed fearApi = new FearAndGreed(new HttpClient());
            IEnumerable <FearAndGreedData> data = (await fearApi.GetFearAndGreedFrom(new System.DateTime(2018, 3, 1))).Data.Select(g => new FearAndGreedData
            {
                Value = double.Parse(g.Value),
                Time  = g.Timestamp.ParseToUtcDateTime()
            });
            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, bucketFearAndGreed);

            InfluxDbData.Repository <FearAndGreedData> repo = new InfluxDbData.Repository <FearAndGreedData>(new InfluxContext(config.Url, config.Token));
            FearAndGreedData lastRecord = (await repo.GetLastWrittenRecordsTime(dataSourceIdentification)).SingleOrDefault();

            foreach (FearAndGreedData model in data.Where(f => f.Time > (lastRecord?.Time ?? DateTime.MinValue)))
            {
                await repo.Write(model, dataSourceIdentification).ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        internal async Task DownloadHashRate()
        {
            InfluxConfig configSecrets = configManager.GetSecretToken();
            HashRateApi  hashRateApi   = new HashRateApi(new HttpClient(), configManager.GetQuandlSetting().ApiKey);

            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, bucketHashRate);

            InfluxDbData.Repository <HashRate> repo = new InfluxDbData.Repository <HashRate>(new InfluxContext(configSecrets.Url, configSecrets.Token));
            HashRate lastRecord = (await repo.GetLastWrittenRecordsTime(dataSourceIdentification).ConfigureAwait(false)).SingleOrDefault();

            IEnumerable <HashRate> data = (await hashRateApi.GetData(lastRecord?.Time ?? DateTime.MinValue)).Select(g => new HashRate
            {
                Value = g.Value,
                Time  = g.Time.ToUniversalTime()
            });

            foreach (HashRate model in data)
            {
                await repo.Write(model, dataSourceIdentification).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Download data and save them to Influx
        /// </summary>
        internal async Task SaveGoldDataToDb()
        {
            InfluxConfig             config  = configManager.GetSecretToken();
            GoldApi                  goldApi = new GoldApi(new HttpClient(), configManager.GetQuandlSetting().ApiKey);
            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, buckerComodity);

            InfluxDbData.Repository <ComodityData> repo = new InfluxDbData.Repository <ComodityData>(new InfluxContext(config.Url, config.Token));
            ComodityData lastRecord = (await repo.GetLastWrittenRecordsTime(dataSourceIdentification))
                                      .SingleOrDefault(t => string.Compare(t.Ticker, gold, true) == 0);

            IEnumerable <ComodityData> data = (await goldApi.GetData(lastRecord?.Time ?? DateTime.MinValue).ConfigureAwait(false)).Select(g => new ComodityData
            {
                Price  = g.Price,
                Ticker = gold,
                Time   = g.Time.ToUniversalTime()
            });

            foreach (ComodityData model in data)
            {
                await repo.Write(model, dataSourceIdentification).ConfigureAwait(false);
            }
        }