示例#1
0
        public async Task <double> GetCurrentExchangeRate(string fromSymbol, string toSymbol)
        {
            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, bucketForex);
            List <CryptoData>        data = await this.cryptoRepository.GetLastWrittenRecordsTime(dataSourceIdentification).ConfigureAwait(false);

            return(data.SingleOrDefault(a => string.Equals(a.Ticker, $"{fromSymbol}{toSymbol}", System.StringComparison.OrdinalIgnoreCase))?.ClosePrice ?? 0);
        }
示例#2
0
        public async Task <double> GetCurrentGoldPriceForOunce()
        {
            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, bucketComodity);
            List <ComodityData>      data = await this.comodityRepository.GetLastWrittenRecordsTime(dataSourceIdentification).ConfigureAwait(false);

            return(data.SingleOrDefault(a => string.Equals(a.Ticker, Gold))?.Price ?? 0);
        }
示例#3
0
        public async Task <double> GetCurrentExchangeRate(string fromSymbol, string toSymbol)
        {
            DataSourceIdentification dataSourceIdentification = new DataSourceIdentification(organizationId, bucketForex);
            List <ForexData>         data = await this.forexRepository.GetLastWrittenRecordsTime(dataSourceIdentification);

            return(data.SingleOrDefault(a => string.Equals(a.BaseCurrency, fromSymbol, System.StringComparison.OrdinalIgnoreCase) &&
                                        string.Equals(a.Currency, toSymbol, System.StringComparison.OrdinalIgnoreCase))?.Price ?? 0);
        }
示例#4
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);
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }
 public CryptoDataDownloader(IRepository <CryptoData> influxRepository, DataSourceIdentification dataSourceIdentification)
 {
     this.influxRepo = influxRepository;
     this.dataSourceIdentification = dataSourceIdentification;
 }
 public ForexDataDownloader(IRepository <ForexData> influxRepository, DataSourceIdentification dataSourceIdentification, string twelveDataapiKey)
 {
     this.influxRepo = influxRepository;
     this.dataSourceIdentification = dataSourceIdentification;
     this.twelveDataapiKey         = twelveDataapiKey;
 }