/// <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); }
public async Task CryptoDownload(CryptoTicker tickerToDownload, DateTime?from = null) { List <CandleModel> data = await this.DownloadData(tickerToDownload, from ?? new DateTime(2019, 1, 1)).ConfigureAwait(false); foreach (CandleModel model in data) { await influxRepo.Write(new CryptoData { ClosePrice = model.Close, HighPrice = model.High, LowPrice = model.Low, OpenPrice = model.Open, Ticker = tickerToDownload.ToString(), Time = model.DateTime.ParseToUtcDateTime(), Volume = model.Volume }, this.dataSourceIdentification).ConfigureAwait(false); } }
private async Task <List <CandleModel> > DownloadData(CryptoTicker cryptoTicker, DateTime from) { CryptoWatch cryptoCandleDataApi = new CryptoWatch(new HttpClient()); return(await cryptoCandleDataApi.GetCandlesDataFrom(cryptoTicker.ToString(), from).ConfigureAwait(false)); }