/// <summary>
        /// Gets signals either from DB or by means of Task Analysis Library
        /// </summary>
        /// <returns>list of signals or list of signals and historical quotes depending on 'historical' parameter</returns>
        private async Task <List <Signal> > GetSignalsWrapper(string symbol, List <IIndicator> indicators, int?last, string timeframe)
        {
            List <Signal> signals;

            // If all indicators are saved in DB - there is no need to request historicalQuotes
            if (indicators.All(i => i.FromDatabase))
            {
                DateTime dateTime  = ApiTimeFrameHelper.ConvertTimeframeToDateTimeUsingConfig(timeframe);
                int      numOfDays = (int)dateTime.TotalBusinessDaysUntil(DateTime.UtcNow);
                signals = GetSignalsFromDb(symbol, indicators, numOfDays);

                return(signals);
            }

            List <HistoricalQuote> historicalQuotes = MarketDataService.GetHistoricalQuotes(symbol, timeframe);

            if (historicalQuotes.IsNullOrEmpty())
            {
                signals = new List <Signal>();
            }
            else
            {
                HistoricalData historicalData = new HistoricalData(historicalQuotes);
                signals = GetSignalsFromDbAndViaCalculation(historicalData, indicators, last);
            }

            return(signals);
        }
        public async Task <List <Signal> > GetSignalsAsync(string symbol, List <IIndicator> indicators, int?last, string timeframe)
        {
            ApiTimeFrameHelper.ValidateTimeFrame(timeframe);

            List <Signal> result = await GetSignalsWrapper(symbol, indicators, last, timeframe);

            return(result);
        }
Beispiel #3
0
        public EntityResponse <List <HistoricalQuote> > GetHistoricalQuotes(string securityCode, string timeframe = null)
        {
            DateTime fromDate = ApiTimeFrameHelper.ConvertTimeframeToDateTimeUsingConfig(timeframe);

            List <HistoricalQuote> historicalQuotes = _uow.HistoricalQuotes
                                                      .Get(securityCode, fromDate)
                                                      .OrderBy(item => item.TradeDate)
                                                      .ToList();

            return(historicalQuotes);
        }