コード例 #1
0
        public ScheduledJobsWindow()
        {
            InitializeComponent();
            DataContext = this;

            Jobs        = new ObservableCollection <DataUpdateJobDetails>();
            Tags        = new ObservableCollection <Tag>();
            Instruments = new ObservableCollection <Instrument>();

            using (var context = new MyDBContext())
            {
                var jobs = context.DataUpdateJobs.ToList();
                foreach (DataUpdateJobDetails job in jobs)
                {
                    Jobs.Add(job);
                }

                var tags = context.Tags.ToList();
                foreach (Tag tag in tags)
                {
                    Tags.Add(tag);
                }

                var im = new InstrumentManager();

                List <Instrument> instruments = im.FindInstruments(context);
                foreach (Instrument i in instruments)
                {
                    Instruments.Add(i);
                }
            }
        }
コード例 #2
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;

            var instrumentSource = new InstrumentManager();

            foreach (FredUtils.FredSeries series in InstrumentGrid.SelectedItems)
            {
                var newInstrument = FredUtils.SeriesToInstrument(series);
                newInstrument.Datasource = _thisDS;

                try
                {
                    if (instrumentSource.AddInstrument(newInstrument) != null)
                    {
                        count++;
                    }
                    AddedInstruments.Add(newInstrument);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
コード例 #3
0
        public ScheduledJobsWindow()
        {
            InitializeComponent();
            DataContext = this;

            Jobs = new ObservableCollection<DataUpdateJobDetails>();
            Tags = new ObservableCollection<Tag>();
            Instruments = new ObservableCollection<Instrument>();

            using (var context = new MyDBContext())
            {
                var jobs = context.DataUpdateJobs.ToList();
                foreach (DataUpdateJobDetails job in jobs)
                {
                    Jobs.Add(job);
                }

                var tags = context.Tags.ToList();
                foreach (Tag tag in tags)
                {
                    Tags.Add(tag);
                }

                var im = new InstrumentManager();

                List<Instrument> instruments = im.FindInstruments(context);
                foreach (Instrument i in instruments)
                {
                    Instruments.Add(i);
                }
            }
        }
コード例 #4
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count            = 0;
            var instrumentSource = new InstrumentManager();

            foreach (Instrument newInstrument in InstrumentGrid.SelectedItems)
            {
                if (newInstrument.Exchange != null)
                {
                    newInstrument.ExchangeID = newInstrument.Exchange.ID;
                }
                if (newInstrument.PrimaryExchange != null)
                {
                    newInstrument.PrimaryExchangeID = newInstrument.PrimaryExchange.ID;
                }

                try
                {
                    if (instrumentSource.AddInstrument(newInstrument) != null)
                    {
                        count++;
                    }
                    AddedInstruments.Add(newInstrument);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: minhpascal/qdms
        //delete one or more instruments
        private void DeleteInstrumentBtn_ItemClick(object sender, RoutedEventArgs routedEventArgs)
        {
            var selectedInstruments = InstrumentsGrid.SelectedItems;

            if (selectedInstruments.Count == 0)
            {
                return;
            }

            if (selectedInstruments.Count == 1)
            {
                var inst             = (Instrument)selectedInstruments[0];
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} @ {1}?", inst.Symbol, inst.Datasource.Name),
                                                       "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }
            else
            {
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} instruments?", selectedInstruments.Count),
                                                       "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }

            List <Instrument> toRemove = new List <Instrument>();

            foreach (Instrument i in InstrumentsGrid.SelectedItems)
            {
                InstrumentManager.RemoveInstrument(i, DataStorageFactory.Get());
                toRemove.Add(i);
            }

            while (toRemove.Count > 0)
            {
                Instruments.Remove(toRemove[toRemove.Count - 1]);
                toRemove.RemoveAt(toRemove.Count - 1);
            }
        }
コード例 #6
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;

            var instrumentSource = new InstrumentManager();

            foreach (FredUtils.FredSeries series in InstrumentGrid.SelectedItems)
            {
                var newInstrument = FredUtils.SeriesToInstrument(series);
                newInstrument.Datasource = _thisDS;

                try
                {
                    if (instrumentSource.AddInstrument(newInstrument) != null)
                        count++;
                    AddedInstruments.Add(newInstrument);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
コード例 #7
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;
            var instrumentSource = new InstrumentManager();

            foreach (Instrument newInstrument in InstrumentGrid.SelectedItems)
            {
                try
                {
                    if (instrumentSource.AddInstrument(newInstrument) != null)
                    {
                        count++;
                        AddedInstruments.Add(newInstrument);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
コード例 #8
0
ファイル: DataServer.cs プロジェクト: leo90skk/qdms
        public void Initialisize()
        {
            _log.Info($"Server is initialisizing ...");

            //create data db if it doesn't exist
            DataDBContext dataContext;
            try
            {
                dataContext = new DataDBContext(_config.LocalStorage.ConnectionString);
                dataContext.Database.Initialize(false);
            }
            catch (System.Data.Entity.Core.ProviderIncompatibleException ex)
            {
                throw new NotSupportedException("Could not connect to context DataDB!", ex);
            }
            dataContext.Dispose();

            MyDBContext entityContext;
            try
            {
                entityContext = new MyDBContext(_config.DataStorage.ConnectionString);
                entityContext.Database.Initialize(false);
            }
            catch (System.Data.Entity.Core.ProviderIncompatibleException ex)
            {
                throw new NotSupportedException("Could not connect to context MyDB!", ex);
            }

            // initialisize helper classes
            _instrumentManager = new InstrumentManager();

            var cfRealtimeBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient("RTDBCFClient", "127.0.0.1",
                _config.RealtimeDataService.RequestPort, _config.RealtimeDataService.PublisherPort,
                _config.InstrumentService.Port, _config.HistoricalDataService.Port), _instrumentManager, false);
            var cfHistoricalBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient("HDBCFClient", "127.0.0.1",
                _config.RealtimeDataService.RequestPort, _config.RealtimeDataService.PublisherPort,
                _config.InstrumentService.Port, _config.HistoricalDataService.Port), _instrumentManager, false);

            IDataStorage localStorage;

            switch (_config.LocalStorage.Type)
            {
                case Config.LocalStorageType.MySql:
                    localStorage = new QDMSServer.DataSources.MySQLStorage(_config.LocalStorage.ConnectionString);
                    break;
                case Config.LocalStorageType.SqlServer:
                    localStorage = new QDMSServer.DataSources.SqlServerStorage(_config.LocalStorage.ConnectionString);
                    break;
                default:
                    throw new NotSupportedException("Not supported local storage type: " + _config.LocalStorage.Type);
            }

            // create brokers
            _historicalDataBroker = new HistoricalDataBroker(cfHistoricalBroker, localStorage, new IHistoricalDataSource[] {
                // @todo please add here some historical data sources the service should provide
            });
            _realTimeDataBroker = new RealTimeDataBroker(cfRealtimeBroker, localStorage, new IRealTimeDataSource[] {
                // @todo please add here some real time data sources the service should provide
            });

            // create servers
            _instrumentsServer = new InstrumentsServer(_config.InstrumentService.Port, _instrumentManager);
            _historicalDataServer = new HistoricalDataServer(_config.HistoricalDataService.Port, _historicalDataBroker);
            _realTimeDataServer = new RealTimeDataServer(_config.RealtimeDataService.PublisherPort, _config.RealtimeDataService.RequestPort, _realTimeDataBroker);

            // ... start the servers
            _instrumentsServer.StartServer();
            _historicalDataServer.StartServer();
            _realTimeDataServer.StartServer();

            _log.Info($"Server is ready.");
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: minhpascal/qdms
        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();
        }
コード例 #10
0
ファイル: DataUpdateJob.cs プロジェクト: KeithNel/qdms
        /// <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));
        }
コード例 #11
0
ファイル: InstrumentsServer.cs プロジェクト: kod3r/qdms
        private void ContractServer()
        {
            var timeout = new TimeSpan(100000);
            _socket = _context.CreateSocket(SocketType.REP);
            _socket.Bind("tcp://*:" + _socketPort);
            var ms = new MemoryStream();
            List<Instrument> instruments;
            var mgr = new InstrumentManager();

            while (_runServer)
            {
                string request = _socket.Receive(Encoding.UTF8, timeout);
                if(request == null) continue;

                //if the request is for a search, receive the instrument w/ the search parameters and pass it to the searcher
                if (request == "SEARCH" && _socket.ReceiveMore)
                {
                    int size;
                    byte[] buffer = _socket.Receive(null, timeout, out size);
                    var searchInstrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);

                    instruments = mgr.FindInstruments(null, searchInstrument);
                }
                else if (request == "ALL") //if the request is for all the instruments, we don't need to receive anything else
                {
                    instruments = mgr.FindInstruments();
                }
                else if (request == "ADD") //request to add instrument
                {
                    int size;
                    byte[] buffer = _socket.Receive(null, timeout, out size);
                    var instrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);

                    bool addResult = InstrumentManager.AddInstrument(instrument);
                    _socket.Send(addResult ? "SUCCESS" : "FAILURE", Encoding.UTF8);

                    continue;
                }
                else //no request = loop again
                {
                    continue;
                }

                byte[] uncompressed = MyUtils.ProtoBufSerialize(instruments, ms);//serialize the list of instruments
                ms.Read(uncompressed, 0, (int)ms.Length); //get the uncompressed data
                byte[] result = LZ4Codec.Encode(uncompressed, 0, (int)ms.Length); //compress it

                //before we send the result we must send the length of the uncompressed array, because it's needed for decompression
                _socket.SendMore(BitConverter.GetBytes(uncompressed.Length));

                //then finally send the results
                _socket.Send(result);
            }

            _socket.Dispose();
        }
コード例 #12
0
ファイル: MainWindow.xaml.cs プロジェクト: kod3r/qdms
        public MainWindow()
        {
            //make sure we can connect to the database
            CheckDBConnection();

            //and that the db we want is there...create it otherwise
            CheckDBExists();

            //set the log directory
            SetLogDirectory();

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

            InitializeComponent();
            DataContext = this;

            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);
            }

            var entityContext = new MyDBContext();

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

            Instruments = new ObservableCollection<Instrument>();

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

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

            _realTimeBroker = new RealTimeDataBroker(Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.rtDBReqPort);
            _instrumentsServer = new InstrumentsServer(Properties.Settings.Default.instrumentServerPort);
            _historicalDataBroker = new HistoricalDataBroker(Properties.Settings.Default.hDBPort);

            _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; //doesn't really work properly

            entityContext.Dispose();
        }
コード例 #13
0
ファイル: MainWindow.xaml.cs プロジェクト: KeithNel/qdms
        public MainWindow()
        {
            Common.Logging.LogManager.Adapter = new NLogLoggerFactoryAdapter(null);

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

            //set the log directory
            SetLogDirectory();

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

            //dim the backup/restore menu items in case of sql server, which isn't implemented yet
            if (Properties.Settings.Default.databaseType != "MySql")
            {
                BackupMenuItem.IsEnabled = false;
                RestoreMenuItem.IsEnabled = false;
            }

            InitializeComponent();
            DataContext = this;

            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);

            //check for any datasources, seed the db with initial values if nothing is found
            if (!entityContext.Datasources.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);

            Instruments = new ObservableCollection<Instrument>();

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

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

            //create brokers
            _realTimeBroker = new RealTimeDataBroker();
            _historicalBroker = new HistoricalDataBroker();

            //create the various servers
            _realTimeServer = new RealTimeDataServer(Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.rtDBReqPort, _realTimeBroker);
            _instrumentsServer = new InstrumentsServer(Properties.Settings.Default.instrumentServerPort);
            _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.Start();

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

            entityContext.Dispose();
        }
コード例 #14
0
ファイル: MainWindow.xaml.cs プロジェクト: leo90skk/qdms
        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();

            //set EF configuration, necessary for MySql to work
            DBUtils.SetDbConfiguration();

            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 ConcurrentNotifierBlockingList<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;

            //Log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            //we subscribe to the messages and send them all to the LogMessages collection
            if (target != null)
                target.Messages.Subscribe(msg => LogMessages.TryAdd(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();

            //create quartz db if it doesn't exist
            QuartzUtils.InitializeDatabase(Settings.Default.databaseType);

            //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.ibClientHost, Properties.Settings.Default.ibClientPort, 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.ibClientHost, Properties.Settings.Default.ibClientPort, Properties.Settings.Default.histClientIBID),
                    new Quandl(Properties.Settings.Default.quandlAuthCode),
                    new BarChart(Properties.Settings.Default.barChartApiKey)
                });

            var countryCodeHelper = new CountryCodeHelper(entityContext.Countries.ToList());

            EconomicReleaseBroker = new EconomicReleaseBroker("FXStreet",
                new[] { new fx.FXStreet(countryCodeHelper) });

            //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
            var quartzSettings = QuartzUtils.GetQuartzSettings(Settings.Default.databaseType);
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory(quartzSettings);
            _scheduler = schedulerFactory.GetScheduler();
            _scheduler.JobFactory = new JobFactory(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(),
                EconomicReleaseBroker
                );
            _scheduler.Start();

            //Take jobs stored in the qmds db and move them to the quartz db - this can be removed in the next version
            MigrateJobs(entityContext, _scheduler);

            entityContext.Dispose();

            ShowChangelog();
        }