コード例 #1
0
ファイル: DataUpdateJob.cs プロジェクト: herbota/QDMS
        private void _broker_HistoricalDataArrived(object sender, HistoricalDataEventArgs e)
        {
            if (e.Request.RequesterIdentity != _requesterID)
            {
                return;
            }

            //If no data was received, we add that to the errors
            if (e.Data.Count == 0 && _settings.NoDataReceived)
            {
                _errors.Add(string.Format("Data update for instrument {0} downloaded 0 bars.", e.Request.Instrument));
            }

            //Check the data for abnormalities
            CheckDataForOutliers(e.Request);

            //Remove the request from pending ones
            lock (_reqIDLock)
            {
                var req = _pendingRequests.FirstOrDefault(x => x.RequestID == e.Request.RequestID);
                if (req != null)
                {
                    _pendingRequests.Remove(req);
                }
            }
        }
コード例 #2
0
        private void Client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
        {
            StatusLabelText = $"Loaded {e.Data.Count} Bars";

            //find largest significant decimal by sampling the prices at the start and end of the series
            var decPlaces = new List <int>();

            for (var i = 0; i < Math.Min(20, e.Data.Count); i++)
            {
                decPlaces.Add(e.Data[i].Open.CountDecimalPlaces());
                decPlaces.Add(e.Data[e.Data.Count - 1 - i].Close.CountDecimalPlaces());
            }

            //set the column format to use that number so we don't get any useless trailing 0s
            var decimalPlaces = 5;

            if (decPlaces.Count > 0)
            {
                decimalPlaces = decPlaces.Max();
            }

            foreach (var bar in e.Data)
            {
                var newBar = DataUtils.BarWithRoundedPrices(bar, decimalPlaces);

                uiContext.Send(x => Data.Add(newBar), null);
            }
        }
コード例 #3
0
        void _client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                StatusLabel.Content = string.Format("Loaded {0} Bars", e.Data.Count);

                //find largest significant decimal by sampling the prices at the start and end of the series
                var decPlaces = new List <int>();
                for (int i = 0; i < Math.Min(20, e.Data.Count); i++)
                {
                    decPlaces.Add(e.Data[i].Open.CountDecimalPlaces());
                    decPlaces.Add(e.Data[e.Data.Count - 1 - i].Close.CountDecimalPlaces());
                }

                //set the column format to use that number so we don't get any useless trailing 0s
                if (decPlaces.Count > 0)
                {
                    SetPriceColumnFormat(decPlaces.Max());
                }


                foreach (OHLCBar bar in e.Data)
                {
                    Data.Add(bar);
                }
            });
        }
コード例 #4
0
        /// <inheritdoc/>
        public void historicalDataUpdate(int reqId, Bar bar)
        {
            // Raise an event which can be listened throughout the application
            var eventArgs = new HistoricalDataEventArgs(reqId, bar.Time, bar.Open, bar.High, bar.Low, bar.Close, (int)bar.Volume, bar.Count, bar.WAP, false);

            this.HistoricalDataUpdateEvent?.Invoke(this, eventArgs);
        }
コード例 #5
0
        /// <summary>
        /// A callback for historical data, fixing a breaking change by the IB API to keep this signature
        /// </summary>
        /// <param name="reqId">The req id</param>
        /// <param name="date">The date</param>
        /// <param name="open">The open</param>
        /// <param name="high">The high</param>
        /// <param name="low">The low</param>
        /// <param name="close">The close</param>
        /// <param name="volume">The volume</param>
        /// <param name="count">The count</param>
        /// <param name="WAP">The WAP</param>
        /// <param name="hasGaps">Whether the data has gaps</param>
        public void historicalData(int reqId, string date, double open, double high, double low, double close, int volume, int count, double WAP, bool hasGaps)
        {
            // Raise an event which can be listened throughout the application
            var eventArgs = new HistoricalDataEventArgs(reqId, date, open, high, low, close, volume, count, WAP, hasGaps);

            this.HistoricalDataEvent.Invoke(this, eventArgs);
        }
コード例 #6
0
 private void OnHistoricalDataRequestCancelled(object sender, HistoricalDataEventArgs e)
 {
     if (e.RequestId == this.request.RequestId)
     {
         this.mres.Set();
     }
 }
コード例 #7
0
 private void _broker_HistoricalDataArrived(object sender, HistoricalDataEventArgs e)
 {
     lock (_socketLock)
     {
         SendFilledHistoricalRequest(e.Request, e.Data);
     }
 }
コード例 #8
0
 public void EmitHistoricalDataCancelled(global::OpenQuant.API.HistoricalDataRequest request)
 {
     if (this.HistoricalDataRequestCancelled != null)
     {
         HistoricalDataEventArgs args = new HistoricalDataEventArgs(request.request.RequestId, request.request.Instrument, this, 0);
         this.HistoricalDataRequestCancelled(this, args);
     }
 }
コード例 #9
0
        /// <summary>
        ///     This method handles data arrivals from the local database
        /// </summary>
        private void LocalStorageHistoricalDataArrived(object sender, HistoricalDataEventArgs e)
        {
            Log(LogLevel.Info,
                $"Pulled {e.Data.Count} data points from local storage on instrument {e.Request.Instrument.Symbol}.");

            //pass up the data to the server so it can be sent out
            ReturnData(e);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: KBurov/qdms
 private static void client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
 {
     Console.WriteLine("Historical data received:");
     foreach (var bar in e.Data)
     {
         Console.WriteLine($"{bar.DT} - O: {bar.Open}  H: {bar.High}  L: {bar.Low}  C: {bar.Close}");
     }
 }
コード例 #11
0
        private void J9LThvcYS([In] HistoricalDataRequest obj0, [In] int obj1)
        {
            HistoricalDataEventArgs args = new HistoricalDataEventArgs(obj0.RequestId, obj0.Instrument, (IHistoricalDataProvider)this, obj1);

            if (this.MYMwJXMLq == null)
            {
                return;
            }
            this.MYMwJXMLq((object)this, args);
        }
コード例 #12
0
        private void xmlocsjtF([In] HistoricalDataRequest obj0, [In] int obj1)
        {
            HistoricalDataEventArgs args = new HistoricalDataEventArgs(obj0.RequestId, obj0.Instrument, (IHistoricalDataProvider)this, obj1);

            if (this.uGp8FpvD3 == null)
            {
                return;
            }
            this.uGp8FpvD3((object)this, args);
        }
コード例 #13
0
ファイル: GoogleFinance.cs プロジェクト: zhuzhenping/FreeOQ
        private void FAwwpUwD2([In] HistoricalDataRequest obj0, [In] int obj1)
        {
            HistoricalDataEventArgs args = new HistoricalDataEventArgs(obj0.RequestId, obj0.Instrument, (IHistoricalDataProvider)this, obj1);

            if (this.NI1e0JhDM == null)
            {
                return;
            }
            this.NI1e0JhDM((object)this, args);
        }
コード例 #14
0
ファイル: GoogleFinance.cs プロジェクト: zhuzhenping/FreeOQ
        private void iAYkpjLCs([In] HistoricalDataRequest obj0, [In] int obj1)
        {
            HistoricalDataEventArgs args = new HistoricalDataEventArgs(obj0.RequestId, obj0.Instrument, (IHistoricalDataProvider)this, obj1);

            if (this.utrQoQnL1 == null)
            {
                return;
            }
            this.utrQoQnL1((object)this, args);
        }
コード例 #15
0
        void tws_HistoricalData(object sender, HistoricalDataEventArgs e)
        {
            // get history object
            if (!hist_list.ContainsKey(e.RequestId))
            {
                return;
            }
            HistData h = hist_list[e.RequestId];

            h.history.Add(e);
        }
コード例 #16
0
ファイル: DownloadForm.cs プロジェクト: zhuzhenping/FreeOQ
        private void aNXk7gk8ZR([In] object obj0, [In] HistoricalDataEventArgs obj1)
        {
            uRIUcg8mp5qy3pl442 riUcg8mp5qy3pl442 = (uRIUcg8mp5qy3pl442)null;

            if (!this.V43ldlVmhs.TryGetValue(obj1.RequestId, out riUcg8mp5qy3pl442))
            {
                return;
            }
            this.zYhk9pJVyB(riUcg8mp5qy3pl442, nB29ckVlruqARiYysQ.Cancelled);
            this.hRhl1skFVG.Remove(obj1.RequestId);
        }
コード例 #17
0
ファイル: DownloadForm.cs プロジェクト: zhuzhenping/FreeOQ
        private void provider_HistoricalDataRequestCancelled(object sender, HistoricalDataEventArgs args)
        {
            DownloadViewItem downloadViewItem = (DownloadViewItem)null;

            if (!this.items.TryGetValue(args.RequestId, out downloadViewItem))
            {
                return;
            }
            this.SetItemStatus(downloadViewItem, DownloadItemStatus.Cancelled);
            this.activeRequests.Remove(args.RequestId);
        }
コード例 #18
0
ファイル: DownloadForm.cs プロジェクト: zhuzhenping/FreeOQ
        private void NhvknhbWi9([In] object obj0, [In] HistoricalDataEventArgs obj1)
        {
            uRIUcg8mp5qy3pl442 riUcg8mp5qy3pl442 = (uRIUcg8mp5qy3pl442)null;

            if (!this.V43ldlVmhs.TryGetValue(obj1.RequestId, out riUcg8mp5qy3pl442))
            {
                return;
            }
            this.zYhk9pJVyB(riUcg8mp5qy3pl442, nB29ckVlruqARiYysQ.Done);
            this.puvkWE62bU();
            this.hRhl1skFVG.Remove(obj1.RequestId);
        }
コード例 #19
0
 static void client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
 {
     Console.WriteLine("Historical data received:");
     foreach (OHLCBar bar in e.Data)
     {
         Console.WriteLine("{0} - O: {1}  H: {2}  L: {3}  C: {4}",
                           bar.DT,
                           bar.Open,
                           bar.High,
                           bar.Low,
                           bar.Close);
     }
 }
コード例 #20
0
 private void OnHistoricalData(object sender, HistoricalDataEventArgs e)
 {
     // ignore 'end' notification
     if ((e.Bar != null) || (e.ErrorMessage != null))
     {
         lock (m_quoteMapLock)
         {
             TWSQuoteObject quoteObject;
             if (m_quoteMap.TryGetValue(e.RequestId, out quoteObject))
             {
                 quoteObject.Quote = e;
                 quoteObject.WaitHandle.Set();
                 m_quoteMap.Remove(e.RequestId);
             }
         }
     }
 }
コード例 #21
0
ファイル: QDMS.cs プロジェクト: zino974/QPAS
        private void dataClient_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
        {
            if (!_requestIDs.ContainsKey(e.Request.RequestID))
            {
                return;
            }
            if (e.Request.Instrument.ID == null)
            {
                throw new Exception("Null instrument ID return wtf");
            }

            lock (_arrivedDataLock)
            {
                int id = e.Request.Instrument.ID.Value;
                _arrivedData.Add(id, e.Data);
                _requestIDs[e.Request.RequestID] = true;
            }
        }
コード例 #22
0
ファイル: HistoricalDataBroker.cs プロジェクト: alacazar/qdms
        /// <summary>
        /// Raise the event that returns data to the server, after applying an RTH filter if needed.
        /// </summary>
        private void ReturnData(HistoricalDataEventArgs e)
        {
            //if needed, we filter out the data outside of regular trading hours
            if (e.Request.RTHOnly &&
                e.Request.Frequency < BarSize.OneDay &&
                e.Request.Instrument.Sessions != null)
            {
                RTHFilter.Filter(e.Data, e.Request.Instrument.Sessions.ToList());
            }

            //For daily+ data using RTH, we set the bar opening and closing times using
            if (e.Request.Frequency >= BarSize.OneDay)
            {
                MyUtils.SetSessionTimes(e.Data, e.Request.Instrument);
            }

            RaiseEvent(HistoricalDataArrived, this, new HistoricalDataEventArgs(e.Request, e.Data));
        }
コード例 #23
0
        private void Dispatcher_HistoricalData(object sender, HistoricalDataEventArgs args)
        {
            HistoricalData     data = args.Data;
            ImportTaskViewItem importTaskViewItem;

            if (!this.taskItems.TryGetValue(data.RequestId, out importTaskViewItem))
            {
                return;
            }
            foreach (SmartQuant.DataObject dataObject in data.Objects)
            {
                if (dataObject is Quote)
                {
                    Quote quote1 = (Quote)dataObject;
                    Quote quote2;
                    lock (this.lastQuotes)
                    {
                        if (!this.lastQuotes.TryGetValue(data.RequestId, out quote2))
                        {
                            quote2 = new Quote(new Bid(), new Ask());
                            this.lastQuotes.Add(data.RequestId, quote2);
                        }
                    }
                    if (quote1.Bid.Price != quote2.Bid.Price || quote1.Bid.Size != quote2.Bid.Size)
                    {
                        this.framework.DataManager.Save(importTaskViewItem.Task.Instrument, (SmartQuant.DataObject) new Bid(quote1.Bid), SaveMode.Add);
                    }
                    if (quote1.Ask.Price != quote2.Ask.Price || quote1.Ask.Size != quote2.Ask.Size)
                    {
                        this.framework.DataManager.Save(importTaskViewItem.Task.Instrument, (SmartQuant.DataObject) new Ask(quote1.Ask), SaveMode.Add);
                    }
                    quote2.Bid.Price = quote1.Bid.Price;
                    quote2.Bid.Size  = quote1.Bid.Size;
                    quote2.Ask.Price = quote1.Ask.Price;
                    quote2.Ask.Size  = quote1.Ask.Size;
                }
                else
                {
                    this.framework.DataManager.Save(importTaskViewItem.Task.Instrument, dataObject, SaveMode.Add);
                }
            }
            importTaskViewItem.Task.TotalNum = data.TotalNum;
            importTaskViewItem.Task.Count   += data.Objects.Length;
        }
コード例 #24
0
 private void Client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         ProgressBarValue++;
         if (ProgressBarValue >= ProgressBarMaximum)
         {
             ProgressBarValue   = 0;
             ProgressBarMaximum = 0;
             StatusBarLabel     = "Historical data update complete";
         }
         else
         {
             StatusBarLabel =
                 $"Rcvd {e.Data.Count} bars of {e.Request.Instrument.Symbol} @ {e.Request.Frequency}";
         }
     }
                                           );
 }
コード例 #25
0
ファイル: MainWindow.xaml.cs プロジェクト: buybackoff/qdms
 private void _client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         _progressBar.Value++;
         if (_progressBar.Value >= _progressBar.Maximum)
         {
             _progressBar.Value     = 0;
             _progressBar.Maximum   = 0;
             StatusBarLabel.Content = "Historical data update complete";
         }
         else
         {
             StatusBarLabel.Content = string.Format("Rcvd {0} bars of {1} @ {2}",
                                                    e.Data.Count,
                                                    e.Request.Instrument.Symbol,
                                                    e.Request.Frequency);
         }
     }
                                           );
 }
コード例 #26
0
 private void OnHistoricalData(object sender, HistoricalDataEventArgs e)
 {
     // ignore 'end' notification
     if ((e.Bar != null) || (e.ErrorMessage != null))
     {
         lock (m_quoteMapLock)
         {
             TWSQuoteObject quoteObject;
             if (!m_quoteMap.TryGetValue(e.RequestId, out quoteObject))
             {
                 m_host.OnInfo(String.Format("Unable to find request id {0} in map", e.RequestId), true);
             }
             else
             {
                 quoteObject.Quote = e;
                 quoteObject.WaitHandle.Set();
                 m_quoteMap.Remove(e.RequestId);
             }
         }
     }
 }
コード例 #27
0
        /// <summary>
        ///     This one handles data arrivals from historical data sources other than local storage
        /// </summary>
        private void ExternalHistoricalDataArrived(object sender, HistoricalDataEventArgs e)
        {
            var assignedID         = e.Request.IsSubrequestFor ?? e.Request.AssignedID;
            var gotOriginalRequest = originalRequests.TryGetValue(assignedID, out HistoricalDataRequest originalRequest);

            if (!gotOriginalRequest)
            {
                throw new Exception("Something went wrong: original request disappeared");
            }

            if (e.Request.SaveToLocalStorage)
            {
                SaveToLocaLStorage(e, originalRequest);
            }
            else
            {
                var storageData = new List <OHLCBar>();
                if (e.Data.Count > 0 &&
                    e.Data[0].Date().ToDateTime() > originalRequest.StartingDate &&
                    e.Request.DataLocation != DataLocation.ExternalOnly)
                {
                    lock (localStorageLock)
                    {
                        //we add half a bar to the request limit so that the data we get starts with the next one
                        DateTime correctedDateTime =
                            e.Data[0].Date().Date.ToDateTime()
                            .AddMilliseconds(originalRequest.Frequency.ToTimeSpan().TotalMilliseconds / 2);
                        storageData = dataStorage.GetData(originalRequest.Instrument, originalRequest.StartingDate,
                                                          correctedDateTime, originalRequest.Frequency);
                    }
                }

                ReturnData(new HistoricalDataEventArgs(e.Request, storageData.Concat(e.Data).ToList()));

                Log(LogLevel.Info,
                    $"Pulled {e.Data.Count} data points from source {e.Request.Instrument.Datasource.Name} on instrument {e.Request.Instrument.Symbol} and {storageData.Count} points from local storage.");
            }
        }
コード例 #28
0
        private void SaveToLocaLStorage(HistoricalDataEventArgs e, HistoricalDataRequest originalRequest)
        {
            HistoricalDataRequest historicalDataRequest = e.Request;

            AddData(new DataAdditionRequest(historicalDataRequest.Frequency, historicalDataRequest.Instrument, e.Data));

            if (historicalDataRequest.IsSubrequestFor.HasValue && subRequests.ContainsKey(historicalDataRequest.IsSubrequestFor.Value))
            {
                subRequests[historicalDataRequest.IsSubrequestFor.Value].Remove(historicalDataRequest);
                if (subRequests[historicalDataRequest.IsSubrequestFor.Value].Count == 0)
                {
                    subRequests.TryRemove(historicalDataRequest.IsSubrequestFor.Value, out List <HistoricalDataRequest> tmpList);

                    lock (localStorageLock)
                    {
                        dataStorage.RequestHistoricalData(originalRequest);
                    }
                }
            }
            else
            {
                if (historicalDataRequest.DataLocation == DataLocation.ExternalOnly)
                {
                    //if the request specifies only fresh data, we don't want to go through local storage
                    ReturnData(new HistoricalDataEventArgs(historicalDataRequest, e.Data));
                }
                else
                {
                    lock (localStorageLock)
                    {
                        dataStorage.RequestHistoricalData(originalRequest);
                    }
                }
            }

            Log(LogLevel.Info,
                $"Pulled {e.Data.Count} data points from source {historicalDataRequest.Instrument.Datasource.Name} on instrument {historicalDataRequest.Instrument.Symbol}.");
        }
コード例 #29
0
        private void OnHistoricalData(object sender, HistoricalDataEventArgs args)
        {
            var            f    = Framework.Current;
            HistoricalData data = args.Data;
//            ImportTaskViewItem importTaskViewItem;
//            if (!this.taskItems.TryGetValue(data.RequestId, out importTaskViewItem))
//                return;
//            foreach (DataObject dataObject in data.Objects)
//            {
//                if (dataObject is Quote)
//                {
//                    Quote quote1 = (Quote) dataObject;
//                    Quote quote2;
//                    lock (this.lastQuotes)
//                    {
//                        if (!this.lastQuotes.TryGetValue(data.RequestId, out quote2))
//                        {
//                            quote2 = new Quote(new Bid(), new Ask());
//                            this.lastQuotes.Add(data.RequestId, quote2);
//                        }
//                    }
//                    if (quote1.Bid.Price != quote2.Bid.Price || quote1.Bid.Size != quote2.Bid.Size)
//                        f.DataManager.Save(importTaskViewItem.Task.Instrument, (SmartQuant.DataObject) new Bid(quote1.Bid), SaveMode.Add);
//                    if (quote1.Ask.Price != quote2.Ask.Price || quote1.Ask.Size != quote2.Ask.Size)
//                        f.DataManager.Save(importTaskViewItem.Task.Instrument, (SmartQuant.DataObject) new Ask(quote1.Ask), SaveMode.Add);
//                    quote2.Bid.Price = quote1.Bid.Price;
//                    quote2.Bid.Size = quote1.Bid.Size;
//                    quote2.Ask.Price = quote1.Ask.Price;
//                    quote2.Ask.Size = quote1.Ask.Size;
//                }
//                else
//                    this.framework.DataManager.Save(importTaskViewItem.Task.Instrument, dataObject, SaveMode.Add);
//            }
//            importTaskViewItem.Task.TotalNum = data.TotalNum;
//            importTaskViewItem.Task.Count += data.Objects.Length;
        }
コード例 #30
0
 /// <summary>
 /// HistoricalData event invocator
 /// </summary>
 protected virtual void OnHistoricalData(HistoricalDataEventArgs e)
 {
     var handler = HistoricalData;
     if (handler != null) handler(this, e);
 }
コード例 #31
0
 private void BrokerHistoricalDataArrived(object sender, HistoricalDataEventArgs e)
 {
     SendFilledHistoricalRequest(e.Request, e.Data);
 }
コード例 #32
0
		public void EmitHistoricalDataCancelled(global::OpenQuant.API.HistoricalDataRequest request)
		{
			if (this.HistoricalDataRequestCancelled != null)
			{
				HistoricalDataEventArgs args = new HistoricalDataEventArgs(request.request.RequestId, request.request.Instrument, this, 0);
				this.HistoricalDataRequestCancelled(this, args);
			}
		}