예제 #1
0
파일: QDMS.cs 프로젝트: QANTau/QPAS
        /// <summary>
        /// Retrieve a list of sessions that describe the regular trading hours for this instrument.
        /// </summary>
        public List<InstrumentSession> GetSessions(EntityModel.Instrument instrument)
        {
            RefreshInstrumentsList();
            var qdmsInstrument = instrument.GetQDMSInstrument(_instrumentsList);

            if(qdmsInstrument == null || qdmsInstrument.Sessions == null) 
            {
                _logger.Log(LogLevel.Info, string.Format("QDMS instrument not found for local instrument: {0}", instrument));
                return new List<InstrumentSession>();
            }
            return qdmsInstrument.Sessions.ToList();
        }
예제 #2
0
파일: QDMS.cs 프로젝트: QANTau/QPAS
        public List<OHLCBar> GetAllData(EntityModel.Instrument instrument, BarSize frequency = BarSize.OneDay)
        {
            if (!_client.Connected) return new List<OHLCBar>();

            RefreshInstrumentsList();

            //find instrument
            var qdmsInst = instrument.GetQDMSInstrument(_instrumentsList);
            if (qdmsInst == null) //nothing like this in QDMS, just grab local data
            {
                return new List<OHLCBar>();
            }

            StoredDataInfo dataInfo = TryGetStorageInfo(qdmsInst);
            if (dataInfo == null)
            {
                return new List<OHLCBar>();
            }

            return GetData(
                instrument, 
                dataInfo.EarliestDate, 
                dataInfo.LatestDate,
                frequency);
        }
예제 #3
0
파일: QDMS.cs 프로젝트: QANTau/QPAS
        public decimal? GetLastPrice(EntityModel.Instrument instrument, out DateTime lastDate)
        {
            lastDate = new DateTime(1, 1, 1);

            var qdmsInst = instrument.GetQDMSInstrument(_instrumentsList);
            if (qdmsInst == null || !qdmsInst.ID.HasValue)
            {
                return null;
            }

            StoredDataInfo dataInfo = TryGetStorageInfo(qdmsInst);
            if (dataInfo == null)
            {
                return null;
            }

            var lastAvailableDate = dataInfo.LatestDate;

            //Send out the request for the data
            var req = new HistoricalDataRequest
            {
                Instrument = qdmsInst,
                StartingDate = lastAvailableDate.AddDays(-1),
                EndingDate = lastAvailableDate,
                Frequency = BarSize.OneDay,
                DataLocation = _allowFreshData ? DataLocation.Both : DataLocation.LocalOnly,
                RTHOnly = true,
                SaveDataToStorage = false
            };
            var id = _client.RequestHistoricalData(req);
            _requestIDs.Add(id, false);


            //Wait until the data arrives
            int i = 0;
            while (i < 100)
            {
                Thread.Sleep(20);
                lock (_arrivedDataLock)
                {
                    if (_requestIDs[id])
                    {
                        var data = _arrivedData[qdmsInst.ID.Value].Last();
                        _arrivedData.Remove(qdmsInst.ID.Value);
                        lastDate = data.DT;
                        return data.Close;
                    }
                }
                i++;
            }

            return null;
        }
예제 #4
0
파일: QDMS.cs 프로젝트: QANTau/QPAS
        public List<OHLCBar> GetData(EntityModel.Instrument instrument, DateTime from, DateTime to, BarSize frequency = BarSize.OneDay)
        {
            if (!_client.Connected) return null;

            RefreshInstrumentsList();

            var qdmsInst = instrument.GetQDMSInstrument(_instrumentsList);
            if (qdmsInst == null) //nothing like this in QDMS, just grab local data
            {
                return null;
            }
            StoredDataInfo dataInfo = TryGetStorageInfo(qdmsInst);

            //Here we check if there's is absolutely no 
            if ((dataInfo == null || dataInfo.LatestDate < from || dataInfo.EarliestDate > to) &&
                !_allowFreshData)
            {
                return null;
            }

            //grab the data
            return RequestData(qdmsInst, from, to, frequency);
        }