//the application is closing, shut down all the servers and stuff private void DXWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //save grid layout using (StreamWriter file = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "GridLayout.xml")) { InstrumentsGrid.SerializeLayout(file); } //shut down quartz _scheduler.Shutdown(true); //then take down the client, the servers, and the brokers _client.Disconnect(); _client.Dispose(); _realTimeServer.StopServer(); _realTimeServer.Dispose(); _historicalDataServer.StopServer(); _historicalDataServer.Dispose(); RealTimeBroker.Dispose(); HistoricalBroker.Dispose(); }
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { _client.HistoricalDataReceived -= _client_HistoricalDataReceived; _client.Error -= _client_Error; _client.Disconnect(); _client.Dispose(); }
//the application is closing, shut down all the servers and stuff private void DXWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //save grid layout using (StreamWriter file = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "GridLayout.xml")) { InstrumentsGrid.SerializeLayout(file); } //Dispose main viewmodel ViewModel.Dispose(); //then take down the client, the servers, and the brokers _client.Disconnect(); _client.Dispose(); }
static void Main() { //create the client, assuming the default port settings QDMSClient.QDMSClient client = new QDMSClient.QDMSClient( "SampleClient", "127.0.0.1", 5556, 5557, 5558, 5555); //hook up the events needed to receive data & error messages client.HistoricalDataReceived += client_HistoricalDataReceived; client.RealTimeDataReceived += client_RealTimeDataReceived; client.LocallyAvailableDataInfoReceived += client_LocallyAvailableDataInfoReceived; client.Error += client_Error; //connect to the server client.Connect(); //make sure the connection was succesful before we continue if (!client.Connected) { Console.WriteLine("Could not connect."); Console.WriteLine("Press enter to exit."); Console.ReadLine(); return; } //request the list of available instruments List <Instrument> instruments = client.FindInstruments(); foreach (Instrument i in instruments) { Console.WriteLine("Instrument ID {0}: {1} ({2}), Datasource: {3}", i.ID, i.Symbol, i.Type, i.Datasource.Name); } Thread.Sleep(3000); //then we grab some historical data from Yahoo //start by finding the SPY instrument var spy = client.FindInstruments(x => x.Symbol == "SPY" && x.Datasource.Name == "Yahoo").FirstOrDefault(); if (spy != null) { var req = new HistoricalDataRequest( spy, BarSize.OneDay, new DateTime(2013, 1, 1), new DateTime(2013, 1, 15), dataLocation: DataLocation.Both, saveToLocalStorage: true, rthOnly: true); client.RequestHistoricalData(req); Thread.Sleep(3000); //now that we downloaded the data, let's make a request to see what is stored locally client.GetLocallyAvailableDataInfo(spy); Thread.Sleep(3000); //finally send a real time data request (from the simulated data datasource) spy.Datasource.Name = "SIM"; var rtReq = new RealTimeDataRequest(spy, BarSize.OneSecond); client.RequestRealTimeData(rtReq); Thread.Sleep(3000); //And then cancel the real time data stream client.CancelRealTimeData(spy); } Console.WriteLine("Press enter to exit."); Console.ReadLine(); client.Disconnect(); client.Dispose(); }
static void Main() { //create the client, assuming the default port settings QDMSClient.QDMSClient client = new QDMSClient.QDMSClient( "SampleClient", "127.0.0.1", 5556, 5557, 5558, 5555); //hook up the events needed to receive data & error messages client.HistoricalDataReceived += client_HistoricalDataReceived; client.RealTimeDataReceived += client_RealTimeDataReceived; client.LocallyAvailableDataInfoReceived += client_LocallyAvailableDataInfoReceived; client.Error += client_Error; //connect to the server client.Connect(); //make sure the connection was succesful before we continue if (!client.Connected) { Console.WriteLine("Could not connect."); Console.WriteLine("Press enter to exit."); Console.ReadLine(); return; } //request the list of available instruments List<Instrument> instruments = client.FindInstruments(); foreach (Instrument i in instruments) { Console.WriteLine("Instrument ID {0}: {1} ({2}), Datasource: {3}", i.ID, i.Symbol, i.Type, i.Datasource.Name); } Thread.Sleep(3000); //then we grab some historical data from Yahoo //start by finding the SPY instrument var spy = client.FindInstruments(x => x.Symbol == "SPY" && x.Datasource.Name == "Yahoo").FirstOrDefault(); if (spy != null) { var req = new HistoricalDataRequest( spy, BarSize.OneDay, new DateTime(2013, 1, 1), new DateTime(2013, 1, 15), dataLocation: DataLocation.Both, saveToLocalStorage: true, rthOnly: true); client.RequestHistoricalData(req); Thread.Sleep(3000); //now that we downloaded the data, let's make a request to see what is stored locally client.GetLocallyAvailableDataInfo(spy); Thread.Sleep(3000); //finally send a real time data request (from the simulated data datasource) spy.Datasource.Name = "SIM"; var rtReq = new RealTimeDataRequest(spy, BarSize.OneSecond); client.RequestRealTimeData(rtReq); Thread.Sleep(3000); //And then cancel the real time data stream client.CancelRealTimeData(spy); } Console.WriteLine("Press enter to exit."); Console.ReadLine(); client.Disconnect(); client.Dispose(); }
/// <summary> /// Called by the <see cref="T:Quartz.IScheduler"/> when a <see cref="T:Quartz.ITrigger"/> /// fires that is associated with the <see cref="T:Quartz.IJob"/>. /// </summary> /// <remarks> /// The implementation may wish to set a result object on the /// JobExecutionContext before this method exits. The result itself /// is meaningless to Quartz, but may be informative to /// <see cref="T:Quartz.IJobListener"/>s or /// <see cref="T:Quartz.ITriggerListener"/>s that are watching the job's /// execution. /// </remarks> /// <param name="context">The execution context.</param> public void Execute(IJobExecutionContext context) { _logger = LogManager.GetCurrentClassLogger(); JobDataMap dataMap = context.JobDetail.JobDataMap; var details = (DataUpdateJobDetails)dataMap["details"]; _jobName = details.Name; Log(LogLevel.Info, string.Format("Data Update job {0} triggered.", details.Name)); //Multiple jobs may be called simultaneously, so what we do is seed the Random based on the job name byte[] bytes = new byte[details.Name.Length * sizeof(char)]; System.Buffer.BlockCopy(details.Name.ToCharArray(), 0, bytes, 0, bytes.Length); var r = new Random((int)DateTime.Now.TimeOfDay.TotalSeconds ^ BitConverter.ToInt32(bytes, 0)); var im = new InstrumentManager(); List<Instrument> instruments = details.UseTag ? im.FindInstruments(pred: x => x.Tags.Any(y => y.ID == details.TagID)) : im.FindInstruments(pred: x => x.ID == details.InstrumentID); if (instruments.Count == 0) { Log(LogLevel.Error, string.Format("Aborting data update job {0}: no instruments found.", details.Name)); return; } using (var client = new QDMSClient.QDMSClient( "DataUpdateJobClient" + r.Next().ToString(), "127.0.0.1", Properties.Settings.Default.rtDBReqPort, Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.instrumentServerPort, Properties.Settings.Default.hDBPort)) { //try to connect try { client.Connect(); } catch (Exception ex) { Log(LogLevel.Error, string.Format("Aborting data update job {0}: connection error {1}", details.Name, ex.Message)); return; } //Hook up the error event, we want to log that stuff client.Error += client_Error; //What we do here: we check what we have available locally.. //If there is something, we send a query to grab data between the last stored time and "now" //Otherwise we send a query to grab everything since 1900 using (var localStorage = DataStorageFactory.Get()) { foreach (Instrument i in instruments) { if (!i.ID.HasValue) continue; //don't request data on expired securities unless the expiration was recent if (i.Expiration.HasValue && (DateTime.Now - i.Expiration.Value).TotalDays > 15) { Log(LogLevel.Trace, string.Format("Data update job {0}: ignored instrument w/ ID {1} due to expiration date.", details.Name, i.ID)); continue; } DateTime startingDT = new DateTime(1900, 1, 1); var storageInfo = localStorage.GetStorageInfo(i.ID.Value); if (storageInfo.Any(x => x.Frequency == details.Frequency)) { var relevantStorageInfo = storageInfo.First(x => x.Frequency == details.Frequency); startingDT = relevantStorageInfo.LatestDate; } client.RequestHistoricalData(new HistoricalDataRequest( i, details.Frequency, startingDT, DateTime.Now, //TODO this should be in the instrument's timezone... forceFreshData: true, localStorageOnly: false, saveToLocalStorage: true, rthOnly: true)); } } //Requests aren't sent immediately so wait before killing the client to make sure the request gets to the server Thread.Sleep(50); client.Disconnect(); } Log(LogLevel.Info, string.Format("Data Update job {0} completed.", details.Name)); }