예제 #1
0
        public decimal?GetLastPrice(Instrument inst, out decimal fxRate, string currency = "USD")
        {
            _logger.Log(LogLevel.Info, string.Format("Last price request for {0} and currency {1}", inst, currency));
            DateTime lastLocalDate;
            decimal? lastLocalPrice = GetLocalLastPrice(inst, out fxRate, out lastLocalDate);

            if (!_useExternalDataSource || !ExternalDataSource.Connected)
            {
                return(lastLocalPrice);
            }
            else
            {
                DateTime lastExternalDate;
                decimal? lastExternalPrice = ExternalDataSource.GetLastPrice(inst, out lastExternalDate);

                if (lastExternalPrice.HasValue && lastExternalDate >= lastLocalDate)
                {
                    fxRate = GetLastFXRate(currency);
                    return(lastExternalPrice.Value);
                }
                else
                {
                    return(lastLocalPrice);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (ExternalDataSource != null)
     {
         ExternalDataSource.Dispose();
         ExternalDataSource = null;
     }
 }
예제 #3
0
        /// <summary>
        /// Used for benchmarking.
        /// </summary>
        public List <OHLCBar> GetExternalData(int externalInstrumentID, DateTime startTime, DateTime endTime)
        {
            if (!_useExternalDataSource)
            {
                _logger.Log(LogLevel.Info, string.Format("Request for external data on instrument with external ID {0} not fulfilled, external data not allowed.", externalInstrumentID));
                return(new List <OHLCBar>());
            }

            return(ExternalDataSource.GetData(externalInstrumentID, startTime, endTime));
        }
예제 #4
0
        /// <summary>
        /// Used for the instrument chart.
        /// </summary>
        public List <OHLCBar> GetAllExternalData(Instrument inst)
        {
            if (!_useExternalDataSource)
            {
                _logger.Log(LogLevel.Info, string.Format("Request for all external data on instrument {0} not fulfilled, external data not allowed.", inst));
                return(new List <OHLCBar>());
            }

            _logger.Log(LogLevel.Info, string.Format("Request for all external data on instrument {0}", inst));
            return(ExternalDataSource.GetAllData(inst));
        }
예제 #5
0
        public List <OHLCBar> GetData(Instrument inst, DateTime startTime, DateTime endTime, BarSize frequency = BarSize.OneDay)
        {
            _logger.Log(LogLevel.Info, string.Format("Data request for {0} from {1} to {2} @ {3}", inst, startTime, endTime, frequency));

            //Check the cache
            lock (_dataCacheLock)
            {
                if (_dataCache.ContainsKey(inst.ID) &&
                    _dataCache[inst.ID].First().DT <= startTime &&
                    _dataCache[inst.ID].Last().DT >= endTime)
                {
                    _logger.Log(LogLevel.Info, "Found data in cache");
                    return(_dataCache[inst.ID].Where(x => x.DT >= startTime && x.DT <= endTime).ToList());
                }
            }

            //if external data is not allowed, just grab the prior positions data
            if (!_useExternalDataSource)
            {
                return(GetLocalData(inst, startTime, endTime));
            }

            //If the cache is not enough, go to the external datasource
            var data = ExternalDataSource.GetData(inst, startTime, endTime);

            //External datasource didn't have anything, get data from prior positions
            if (data == null || data.Count == 0)
            {
                _logger.Log(LogLevel.Info, "Data was not available externally, getting it form prior positions");
                return(GetLocalData(inst, startTime, endTime));
            }

            //QDMS data does NOT cover the entire period requested.
            //Try to supplement the data with the prices from prior positions
            if (frequency == BarSize.OneDay && (data.First().DT.Date > startTime.Date || data.Last().DT.Date < endTime))
            {
                SupplementWithLocalData(inst, startTime, endTime, ref data);
            }

            AddToCache(data, inst.ID);

            return(data);
        }