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); } }); }
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); } }
void _broker_HistoricalDataArrived(object sender, HistoricalDataEventArgs e) { _dataQueue.Enqueue(new KeyValuePair<HistoricalDataRequest, List<OHLCBar>>(e.Request, e.Data)); }
private void BrokerHistoricalDataArrived(object sender, HistoricalDataEventArgs e) { SendFilledHistoricalRequest(e.Request, e.Data); }
void _client_HistoricalDataReceived(object sender, HistoricalDataEventArgs e) { Application.Current.Dispatcher.Invoke(() => { StatusLabel.Content = string.Format("Loaded {0} Bars", e.Data.Count); foreach (OHLCBar bar in e.Data) { Data.Add(bar); } }); }
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); } } }
/// <summary> /// This one handles data arrivals from historical data sources other than local storage ///</summary> private void LocalStorageHistoricalDataArrived(object sender, HistoricalDataEventArgs e) { Application.Current.Dispatcher.Invoke(() => Log(LogLevel.Info, string.Format("Pulled {0} data points from local storage on instrument {1}.", e.Data.Count, e.Request.Instrument.Symbol)) ); //then add the data to the queue to be sent out over the network _dataQueue.Enqueue(new KeyValuePair<int, List<OHLCBar>>(e.Request.AssignedID, e.Data)); }
/// <summary> /// This one handles data arrivals from historical data sources other than local storage /// </summary> private void ExternalHistoricalDataArrived(object sender, HistoricalDataEventArgs e) { //save the data to local storage, then (maybe) send the original request to be fulfilled by local storage, which now has all the data available HistoricalDataRequest originalRequest; bool gotOriginalRequest = _originalRequests.TryGetValue(e.Request.AssignedID, out originalRequest); if (!gotOriginalRequest) throw new Exception("Something went wrong: original request disappeared"); if (e.Request.SaveDataToStorage) { lock (_localStorageLock) { _dataStorage.AddData(e.Data, e.Request.Instrument, e.Request.Frequency, true); } //check if there is a list in the subrequests for this request... if (_subRequests.ContainsKey(e.Request.AssignedID)) { //remove this item...if the list is empty, remove it and send the original request to the //local storage, because all the requests to external data sources have now arrived _subRequests[e.Request.AssignedID].Remove(e.Request); if (_subRequests[e.Request.AssignedID].Count == 0) { List<HistoricalDataRequest> tmpList; _subRequests.TryRemove(e.Request.AssignedID, out tmpList); //remove the list for this ID _dataStorage.RequestHistoricalData(originalRequest); //and finally send the original request to the local db } } else //there is not -- this is a standalone request, so just grab the data from the db and return it { _dataStorage.RequestHistoricalData(originalRequest); } Application.Current.Dispatcher.Invoke(() => Log(LogLevel.Info, string.Format("Pulled {0} data points from source {1} on instrument {2}.", e.Data.Count, e.Request.Instrument.Datasource.Name, e.Request.Instrument.Symbol)) ); } else //the data does NOT go to local storage, so we have to load that stuff and combine it right here { lock (_localStorageLock) { //grab the rest of the data from historical storage var storageData = new List<OHLCBar>(); if (e.Data[0].Date.ToDateTime() > originalRequest.StartingDate) { //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); } //then add the data to the queue to be sent out over the network _dataQueue.Enqueue(new KeyValuePair<int, List<OHLCBar>>(e.Request.AssignedID, storageData.Concat(e.Data).ToList())); Application.Current.Dispatcher.Invoke(() => Log(LogLevel.Info, string.Format("Pulled {0} data points from source {1} on instrument {2} and {3} points from local storage.", e.Data.Count, e.Request.Instrument.Datasource.Name, e.Request.Instrument.Symbol, storageData.Count)) ); } } }
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); } } ); }
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; } }
private void _broker_HistoricalDataArrived(object sender, HistoricalDataEventArgs e) { lock (_socketLock) { SendFilledHistoricalRequest(e.Request, e.Data); } }