Exemple #1
0
 private void MigrateJobs(MyDBContext context, IScheduler scheduler)
 {
     //Check if there are jobs in the QDMS db and no jobs in the quartz db - in that case we migrate them
     if (context.DataUpdateJobs.Any() && scheduler.GetJobKeys(GroupMatcher <JobKey> .AnyGroup()).Count == 0)
     {
         foreach (DataUpdateJobSettings job  in context.DataUpdateJobs)
         {
             JobsManager.ScheduleJob(scheduler, job);
         }
     }
 }
Exemple #2
0
        private void DataJobsBtn_OnClick(object sender, RoutedEventArgs e)
        {
            var window = new ScheduledJobsWindow();

            window.ShowDialog();

            //clear and re-schedule all jobs, allowing any existing jobs to finish first.
            _scheduler.PauseAll();
            using (var entityContext = new MyDBContext())
            {
                JobsManager.ScheduleJobs(_scheduler, entityContext.DataUpdateJobs.Include(t => t.Instrument).Include(t => t.Tag).ToList());
            }

            var alljobs = _scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .AnyGroup());

            _scheduler.ResumeAll();
        }
Exemple #3
0
        public MainWindow()
        {
            Common.Logging.LogManager.Adapter = new NLogLoggerFactoryAdapter(new Common.Logging.Configuration.NameValueCollection());

            //make sure we can connect to the database
            CheckDBConnection();

            //set the log directory
            SetLogDirectory();

            //set the connection string
            DBUtils.SetConnectionString();

            InitializeComponent();
            DataContext = this;

            //load datagrid layout
            string layoutFile = AppDomain.CurrentDomain.BaseDirectory + "GridLayout.xml";

            if (File.Exists(layoutFile))
            {
                try
                {
                    InstrumentsGrid.DeserializeLayout(File.ReadAllText(layoutFile));
                }
                catch
                {
                }
            }

            LogMessages = new ObservableCollection <LogEventInfo>();

            //target is where the log managers send their logs, here we grab the memory target which has a Subject to observe
            var target = LogManager.Configuration.AllTargets.Single(x => x.Name == "myTarget") as MemoryTarget;

            //we subscribe to the messages and send them all to the LogMessages collection
            if (target != null)
            {
                target.Messages.Subscribe(msg => LogMessages.Add(msg));
            }

            //build the instruments grid context menu
            //we want a button for each BarSize enum value in the UpdateFreqSubMenu menu
            foreach (int value in Enum.GetValues(typeof(BarSize)))
            {
                var button = new MenuItem
                {
                    Header = Regex.Replace(((BarSize)value).ToString(), "([A-Z])", " $1").Trim(),
                    Tag    = (BarSize)value
                };
                button.Click += UpdateHistoricalDataBtn_ItemClick;
                ((MenuItem)Resources["UpdateFreqSubMenu"]).Items.Add(button);
            }

            //create metadata db if it doesn't exist
            var entityContext = new MyDBContext();

            entityContext.Database.Initialize(false);

            //seed the datasources no matter what, because these are added frequently
            Seed.SeedDatasources(entityContext);

            //check for any exchanges, seed the db with initial values if nothing is found
            if (!entityContext.Exchanges.Any())
            {
                Seed.DoSeed();
            }

            //create data db if it doesn't exist
            var dataContext = new DataDBContext();

            dataContext.Database.Initialize(false);
            dataContext.Dispose();

            //build the tags menu
            var allTags = entityContext.Tags.ToList();

            BuildTagContextMenu(allTags);

            //build session templates menu
            BuildSetSessionTemplateMenu();

            Instruments = new ObservableCollection <Instrument>();

            var mgr            = new InstrumentManager();
            var instrumentList = mgr.FindInstruments(entityContext);

            foreach (Instrument i in instrumentList)
            {
                Instruments.Add(i);
            }

            //create brokers
            var cfRealtimeBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient(
                                                                   "RTDBCFClient",
                                                                   "127.0.0.1",
                                                                   Properties.Settings.Default.rtDBReqPort,
                                                                   Properties.Settings.Default.rtDBPubPort,
                                                                   Properties.Settings.Default.instrumentServerPort,
                                                                   Properties.Settings.Default.hDBPort), new InstrumentManager(), connectImmediately: false);
            var cfHistoricalBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient(
                                                                     "HDBCFClient",
                                                                     "127.0.0.1",
                                                                     Properties.Settings.Default.rtDBReqPort,
                                                                     Properties.Settings.Default.rtDBPubPort,
                                                                     Properties.Settings.Default.instrumentServerPort,
                                                                     Properties.Settings.Default.hDBPort), new InstrumentManager(), connectImmediately: false);
            var localStorage = DataStorageFactory.Get();

            RealTimeBroker = new RealTimeDataBroker(cfRealtimeBroker, localStorage,
                                                    new IRealTimeDataSource[] {
                //new Xignite(Properties.Settings.Default.xigniteApiToken),
                //new Oanda(Properties.Settings.Default.oandaAccountId, Properties.Settings.Default.oandaAccessToken),
                new IB(Properties.Settings.Default.rtdClientIBID),
                //new ForexFeed(Properties.Settings.Default.forexFeedAccessKey, ForexFeed.PriceType.Mid)
            });
            HistoricalBroker = new HistoricalDataBroker(cfHistoricalBroker, localStorage,
                                                        new IHistoricalDataSource[] {
                new Yahoo(),
                new FRED(),
                //new Forexite(),
                new IB(Properties.Settings.Default.histClientIBID),
                new Quandl(Properties.Settings.Default.quandlAuthCode),
            });

            //create the various servers
            _realTimeServer       = new RealTimeDataServer(Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.rtDBReqPort, RealTimeBroker);
            _instrumentsServer    = new InstrumentsServer(Properties.Settings.Default.instrumentServerPort, mgr);
            _historicalDataServer = new HistoricalDataServer(Properties.Settings.Default.hDBPort, HistoricalBroker);

            //and start them
            _realTimeServer.StartServer();
            _instrumentsServer.StartServer();
            _historicalDataServer.StartServer();

            //we also need a client to make historical data requests with
            _client = new QDMSClient.QDMSClient(
                "SERVERCLIENT",
                "localhost",
                Properties.Settings.Default.rtDBReqPort,
                Properties.Settings.Default.rtDBPubPort,
                Properties.Settings.Default.instrumentServerPort,
                Properties.Settings.Default.hDBPort);
            _client.Connect();
            _client.HistoricalDataReceived += _client_HistoricalDataReceived;

            ActiveStreamGrid.ItemsSource = RealTimeBroker.ActiveStreams;

            //create the scheduler
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();

            _scheduler            = schedulerFactory.GetScheduler();
            _scheduler.JobFactory = new DataUpdateJobFactory(HistoricalBroker,
                                                             Properties.Settings.Default.updateJobEmailHost,
                                                             Properties.Settings.Default.updateJobEmailPort,
                                                             Properties.Settings.Default.updateJobEmailUsername,
                                                             Properties.Settings.Default.updateJobEmailPassword,
                                                             Properties.Settings.Default.updateJobEmailSender,
                                                             Properties.Settings.Default.updateJobEmail,
                                                             new UpdateJobSettings(
                                                                 noDataReceived: Properties.Settings.Default.updateJobReportNoData,
                                                                 errors: Properties.Settings.Default.updateJobReportErrors,
                                                                 outliers: Properties.Settings.Default.updateJobReportOutliers,
                                                                 requestTimeouts: Properties.Settings.Default.updateJobTimeouts,
                                                                 timeout: Properties.Settings.Default.updateJobTimeout,
                                                                 toEmail: Properties.Settings.Default.updateJobEmail,
                                                                 fromEmail: Properties.Settings.Default.updateJobEmailSender),
                                                             localStorage, new InstrumentManager());
            _scheduler.Start();

            //Grab jobs and schedule them
            JobsManager.ScheduleJobs(_scheduler, entityContext.DataUpdateJobs.Include(t => t.Instrument).Include(t => t.Tag).ToList());

            entityContext.Dispose();

            ShowChangelog();
        }