Exemple #1
0
        /// <summary>
        /// Get the candles in monthly packages
        /// </summary>
        /// <returns>Candles in a month</returns>
        private async Task <ICollection <Contracts.Candle> > GetCandlesBetween(Contracts.InstrumentName instrument, Contracts.Granularity granularity, DateTime utcFrom, DateTime utcTo)
        {
            // Authenticate to OANDA with the master account
            var oandaConnection = _oandaApiConnectionFactory.CreateConnection(OandaConnectionType.FxPractice, _configuration["Oanda-MasterToken"]);

            // Get candles
            var oandaInstrument  = _mapper.Map <InstrumentName>(instrument);
            var oandaGranularity = _mapper.Map <CandlestickGranularity>(granularity);
            var candles          = await oandaConnection.GetInstrument(oandaInstrument).GetCandlesByTimeAsync(oandaGranularity, utcFrom, utcTo);

            return(_mapper.Map <ICollection <Contracts.Candle> >(candles));
        }
Exemple #2
0
 private async Task PostCandlesToTheEngine(Contracts.InstrumentName instrument, Contracts.Granularity granularity, IEnumerable <Contracts.Candle> candles)
 {
     var client = _httpClientFactory.CreateClient(_configuration["forex-miner-thor:Name"]);
     await _retryPolicy.ExecuteAsync(async() =>
     {
         await client.PostAsync($"instruments/{instrument}/granularities/{granularity}", CreateHttpContent(candles));
     });
 }
Exemple #3
0
 /// <summary>
 /// Get granularity from DB
 /// </summary>
 /// <param name="instrumentName">Name of the instrument</param>
 /// <param name="granularityName">Granularity</param>
 /// <returns>Granularity</returns>
 private Database.InstrumentGranularity GetGranularityFromDbByName(Contracts.InstrumentName instrumentName, Contracts.Granularity granularityName)
 {
     return(_dbContext.Instruments.Include(instrument => instrument.Granularities)
            .SingleOrDefault(instrument => instrument.Name == instrumentName)?.Granularities
            .SingleOrDefault(granularity => granularity.Granularity == granularityName));
 }