public HistoricalRequestWindow(Instrument instrument)
        {
            InitializeComponent();
            DataContext = this;

            Random r = new Random(); //we have to randomize the name of the client, can't reuse the identity

            Title = string.Format("Data Request - {0} @ {1}", instrument.Symbol, instrument.Datasource.Name);

            _client = new QDMSClient.QDMSClient(
            string.Format("DataRequestClient-{0}", r.Next()),
            "localhost",
            Properties.Settings.Default.rtDBReqPort,
            Properties.Settings.Default.rtDBPubPort,
            Properties.Settings.Default.instrumentServerPort,
            Properties.Settings.Default.hDBPort);

            _client.HistoricalDataReceived += _client_HistoricalDataReceived;
            _client.Error += _client_Error;
            _client.Connect();

            Data = new ObservableCollection<OHLCBar>();

            TheInstrument = instrument;

            StartTime = new DateTime(1950, 1, 1, 0, 0, 0, 0);
            EndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);

            if (!TheInstrument.ID.HasValue) return;

            ShowDialog();
        }
Exemple #2
0
        private static void Main()
        {
            //create the client, assuming the default port settings
            using (var 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
                var instruments = client.FindInstruments();

                foreach (var i in instruments)
                {
                    Console.WriteLine($"Instrument ID {i.ID}: {i.Symbol} ({i.Type}), Datasource: {i.Datasource.Name}");
                }

                Thread.Sleep(3000);
                //then we grab some historical data from Yahoo
                //start by finding the SPY instrument
                var spy = instruments.FirstOrDefault(x => x.Symbol == "SPY" && x.Datasource.Name == "Yahoo");
                if (spy != null)
                {
                    var req = new HistoricalDataRequest(
                        spy,
                        BarSize.OneDay,
                        new DateTime(2013, 1, 1),
                        new DateTime(2013, 1, 15));

                    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();
            }
        }
        public void SetUp()
        {
            _instrumentSourceMock = new Mock<IInstrumentSource>();
            _server = new InstrumentsServer(5555, _instrumentSourceMock.Object);

            _server.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5553, 5554, 5555, 5556);
        }
        public void SetUp()
        {
            _brokerMock = new Mock<IRealTimeDataBroker>();
            // Also need the real time server to keep the "heartbeat" going
            _rtServer = new RealTimeDataServer(5555, 5554, _brokerMock.Object);
            _rtServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5554, 5555, 5556, 5557);
            _client.Connect();
        }
Exemple #5
0
        public void SetUp()
        {
            _brokerMock = new Mock <IRealTimeDataBroker>();
            // Also need the real time server to keep the "heartbeat" going
            _rtServer = new RealTimeDataServer(5555, 5554, _brokerMock.Object);
            _rtServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5554, 5555, 5556, 5557);
            _client.Connect();
        }
Exemple #6
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (_connectionTimer != null)
     {
         _connectionTimer.Dispose();
         _connectionTimer = null;
     }
     if (_client != null)
     {
         _client.Dispose();
         _client = null;
     }
 }
        public void SetUp()
        {
            _instrumentSourceMock = new Mock <IInstrumentSource>();
            _instrumentsServer    = new InstrumentsServer(5555, _instrumentSourceMock.Object);

            _rtdBrokerMock = new Mock <IRealTimeDataBroker>();
            _rtdServer     = new RealTimeDataServer(5554, 5553, _rtdBrokerMock.Object);

            _instrumentsServer.StartServer();
            _rtdServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5553, 5554, 5555, 5556);
            _client.Connect();
        }
Exemple #8
0
        public void SetUp()
        {
            _instrumentSourceMock = new Mock<IInstrumentSource>();
            _instrumentsServer = new InstrumentsServer(5555, _instrumentSourceMock.Object);

            _rtdBrokerMock = new Mock<IRealTimeDataBroker>();
            _rtdServer = new RealTimeDataServer(5554, 5553, _rtdBrokerMock.Object);

            _instrumentsServer.StartServer();
            _rtdServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5553, 5554, 5555, 5556);
            _client.Connect();
        }
Exemple #9
0
        public void SetUp()
        {
            _brokerMock = new Mock <IRealTimeDataBroker>();

            var settings = new Mock <ISettings>();

            settings.SetupGet(x => x.rtDBPubPort).Returns(5555);
            settings.SetupGet(x => x.rtDBReqPort).Returns(5554);

            // Also need the real time server to keep the "heartbeat" going
            _rtServer = new RealTimeDataServer(settings.Object, _brokerMock.Object);
            _rtServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5554, 5555, 5557, 5559, "");
            _client.Connect();
        }
Exemple #10
0
        public HistoricalRequestWindow(Instrument instrument)
        {
            InitializeComponent();
            DataContext = this;

            Random r = new Random(); //we have to randomize the name of the client, can't reuse the identity

            Title = string.Format("Data Request - {0} @ {1}", instrument.Symbol, instrument.Datasource.Name);

            _client = new QDMSClient.QDMSClient(
                string.Format("DataRequestClient-{0}", r.Next()),
                "localhost",
                Properties.Settings.Default.rtDBReqPort,
                Properties.Settings.Default.rtDBPubPort,
                Properties.Settings.Default.hDBPort,
                Properties.Settings.Default.httpPort,
                Properties.Settings.Default.apiKey,
                useSsl: Properties.Settings.Default.useSsl);

            _client.HistoricalDataReceived += _client_HistoricalDataReceived;
            _client.Error += _client_Error;
            _client.Connect();

            Data = new ObservableCollection <OHLCBar>();

            TheInstrument = instrument;

            StartTime = new DateTime(1950, 1, 1, 0, 0, 0, 0);
            EndTime   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);
            StartDate = new DateTime(1950, 1, 1, 0, 0, 0, 0);
            EndDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);

            if (!TheInstrument.ID.HasValue)
            {
                return;
            }

            Show();
        }
Exemple #11
0
        public QDMS()
        {
            _client = QDMSClientFactory.Get();

            ConnectToDataServer();

            _allowFreshData = Properties.Settings.Default.qdmsAllowFreshData;

            _connectionTimer          = new Timer(2000);
            _connectionTimer.Elapsed += _connectionTimer_Elapsed;
            _connectionTimer.Start();

            _requestIDs                 = new Dictionary <int, bool>();
            _arrivedData                = new Dictionary <int, List <OHLCBar> >();
            _instrumentsList            = new List <Instrument>();
            _lastInstrumentsListRefresh = new DateTime(1, 1, 1);
            _storageInfo                = new Dictionary <int, StoredDataInfo>();

            _client.HistoricalDataReceived           += dataClient_HistoricalDataReceived;
            _client.LocallyAvailableDataInfoReceived += DataClient_LocallyAvailableDataInfoReceived;
            _client.Error += _client_Error;

            RefreshInstrumentsList();
        }
Exemple #12
0
        public QDMS()
        {
            _client = QDMSClientFactory.Get();

            ConnectToDataServer();

            _allowFreshData = Properties.Settings.Default.qdmsAllowFreshData;

            _connectionTimer = new Timer(2000);
            _connectionTimer.Elapsed += _connectionTimer_Elapsed;
            _connectionTimer.Start();

            _requestIDs = new Dictionary<int, bool>();
            _arrivedData = new Dictionary<int, List<OHLCBar>>();
            _instrumentsList = new List<Instrument>();
            _lastInstrumentsListRefresh = new DateTime(1, 1, 1);
            _storageInfo = new Dictionary<int, StoredDataInfo>();

            _client.HistoricalDataReceived += dataClient_HistoricalDataReceived;
            _client.LocallyAvailableDataInfoReceived += DataClient_LocallyAvailableDataInfoReceived;
            _client.Error += _client_Error;

            RefreshInstrumentsList();
        }
Exemple #13
0
 public TagsWindow(QDMSClient.QDMSClient client)
 {
     InitializeComponent();
     ViewModel   = new TagsViewModel(client, DialogCoordinator.Instance);
     DataContext = ViewModel;
 }
Exemple #14
0
 public void SetUp()
 {
     _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5553, 5554, 5556, 5559, "");
 }
Exemple #15
0
        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 instrumentList = InstrumentManager.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();
        }
Exemple #16
0
        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();
        }
Exemple #17
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();

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

            InitializeComponent();

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

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

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

            //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() ||
                (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun))
            {
                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();

            entityContext.Dispose();

            //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.hDBPort,
                Properties.Settings.Default.httpPort,
                Properties.Settings.Default.apiKey,
                useSsl: Properties.Settings.Default.useSsl);
            _client.HistoricalDataReceived += _client_HistoricalDataReceived;
            _client.Error += (s, e) => _clientLogger.Error(e.ErrorMessage);

            //Create ViewModel
            ViewModel   = new MainViewModel(_client, DialogCoordinator.Instance);
            DataContext = ViewModel;

            ShowChangelog();
        }
Exemple #18
0
 public void SetUp()
 {
     _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5553, 5554, 5555, 5556);
 }
Exemple #19
0
        /// <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));
        }
Exemple #20
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
            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.JobFactory = new DataUpdateJobFactory(HistoricalBroker);
            _scheduler.Start();

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

            entityContext.Dispose();

            ShowChangelog();
        }
Exemple #21
0
        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();
        }
Exemple #22
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (_connectionTimer != null)
     {
         _connectionTimer.Dispose();
         _connectionTimer = null;
     }
     if (_client != null)
     {
         _client.Dispose();
         _client = null;
     }
 }
Exemple #23
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();

            //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 instrumentRepo = new InstrumentRepository(entityContext);
            var instrumentList = instrumentRepo.FindInstruments().Result;

            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.hDBPort,
                                                                   Properties.Settings.Default.httpPort,
                                                                   Properties.Settings.Default.apiKey,
                                                                   useSsl: Properties.Settings.Default.useSsl),
                                                               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.hDBPort,
                                                                     Properties.Settings.Default.httpPort,
                                                                     Properties.Settings.Default.apiKey,
                                                                     useSsl: Properties.Settings.Default.useSsl),
                                                                 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);
            _historicalDataServer = new HistoricalDataServer(Properties.Settings.Default.hDBPort, HistoricalBroker);

            //and start them
            _realTimeServer.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.hDBPort,
                Properties.Settings.Default.httpPort,
                Properties.Settings.Default.apiKey,
                useSsl: Properties.Settings.Default.useSsl);
            _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,
                                                   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);

            var bootstrapper = new CustomBootstrapper(
                DataStorageFactory.Get(),
                EconomicReleaseBroker,
                HistoricalBroker,
                RealTimeBroker,
                Properties.Settings.Default.apiKey);
            var uri  = new Uri((Settings.Default.useSsl ? "https" : "http") + "://localhost:" + Properties.Settings.Default.httpPort);
            var host = new NancyHost(bootstrapper, uri);

            host.Start();

            entityContext.Dispose();

            ShowChangelog();
        }
Exemple #24
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();

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