internal async Task DownloadForexHistory(ForexTicker forexTicker) { InfluxConfig config = GetSecretToken(); InfluxDbData.Repository <ForexData> repo = new(new InfluxContext(config.Url, config.Token)); ForexDataDownloader forexDataDownloader = new ForexDataDownloader(repo, new DataSourceIdentification(organizationId, bucketForex), this.configManager.GetTwelveDataApiKey()); await forexDataDownloader.ForexDownload(forexTicker.Value).ConfigureAwait(false); }
public InfluxConfig GetSecretToken() { InfluxConfig influxConfig = new InfluxConfig(); IConfigurationRoot configuration = this.GetConfigurationRoot(); configuration.GetSection("Influxdb").Bind(influxConfig); return(influxConfig); }
/// <summary> /// Download history values of crypto (from last updated value) /// </summary> /// <param name="cryptoTicker">Crypto ticker</param> /// <returns>Task</returns> internal async Task DownloadCryptoHistory(CryptoTicker cryptoTicker) { InfluxConfig config = GetSecretToken(); InfluxDbData.Repository <CryptoData> repo = new(new InfluxContext(config.Url, config.Token)); List <CryptoData> lastRecords = await repo.GetLastWrittenRecordsTime(new DataSourceIdentification(organizationId, bucketCrypto)).ConfigureAwait(false); CryptoData lastTickerRecord = lastRecords.SingleOrDefault(r => r.Ticker == cryptoTicker.ToString()); CryptoDataDownloader dataDownloader = new CryptoDataDownloader(repo, new DataSourceIdentification(organizationId, bucketCrypto)); await dataDownloader.CryptoDownload(cryptoTicker, lastTickerRecord?.Time).ConfigureAwait(false); }
/// <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); } }
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); } }
/// <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); } }