Exemple #1
0
        private void CreateDatabases()
        {
            //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();
            }

            entityContext.Dispose();

            //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);
        }
Exemple #2
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 #3
0
        private void ComposeObjects()
        {
            var container = new Container();

            container.Options.SuppressLifestyleMismatchVerification = true;

            container.RegisterSingleton <ISettings>(() => Settings.Default);
            container.Register <IMyDbContext, MyDBContext>(Lifestyle.Transient);
            container.Register <IInstrumentSource, InstrumentRepository>(Lifestyle.Transient);
            container.RegisterSingleton <IDataClient>(() => new QDMSClient.QDMSClient(
                                                          "SERVERCLIENT",
                                                          "127.0.0.1",
                                                          Settings.Default.rtDBReqPort,
                                                          Settings.Default.rtDBPubPort,
                                                          Settings.Default.hDBPort,
                                                          Settings.Default.httpPort,
                                                          Settings.Default.apiKey,
                                                          useSsl: Settings.Default.useSsl));

            container.Register(DataStorageFactory.Get);
            container.Register <ICountryCodeHelper, CountryCodeHelper>(Lifestyle.Singleton);

            //These sources provide both real time and historical data
            var ibReg      = Lifestyle.Singleton.CreateRegistration <IB>(container);
            var binanceReg = Lifestyle.Singleton.CreateRegistration <Binance>(container);

            var bothSources = new[] { ibReg, binanceReg };

            //Realtime sources
            container.Register <IIBClient, IBClient>();
            var realtimeSources = new Type[]
            {
            };

            container.Collection.Register <IRealTimeDataSource>(realtimeSources
                                                                .Select(type => Lifestyle.Singleton.CreateRegistration(type, container))
                                                                .Concat(bothSources));


            //Historical sources
            var historicalSources = new[]
            {
                typeof(Yahoo),
                typeof(FRED),
                typeof(Quandl),
                typeof(BarChart)
            };

            container.Collection.Register <IHistoricalDataSource>(historicalSources
                                                                  .Select(type => Lifestyle.Singleton.CreateRegistration(type, container))
                                                                  .Concat(bothSources));

            //economic release sources
            var econReleaseSources = new[]
            {
                typeof(fx.FXStreet)
            };

            container.Collection.Register <IEconomicReleaseSource>(econReleaseSources
                                                                   .Select(type => Lifestyle.Singleton.CreateRegistration(type, container)));

            //dividend sources
            var dividendSources = new[]
            {
                typeof(NasdaqDs.Nasdaq),
                typeof(DivDotCom.DividendDotCom)
            };

            container.Collection.Register <IDividendDataSource>(dividendSources
                                                                .Select(type => Lifestyle.Singleton.CreateRegistration(type, container)));

            //earnings announcement sources
            var earningsSources = new[]
            {
                typeof(CBOEModule.CBOE)
            };

            container.Collection.Register <IEarningsAnnouncementSource>(earningsSources
                                                                        .Select(type => Lifestyle.Singleton.CreateRegistration(type, container)));

            //brokers
            container.Register <IContinuousFuturesBroker, ContinuousFuturesBroker>(Lifestyle.Singleton);
            container.Register <IRealTimeDataBroker, RealTimeDataBroker>(Lifestyle.Singleton);
            container.Register <IHistoricalDataBroker, HistoricalDataBroker>(Lifestyle.Singleton);
            container.Register <IEconomicReleaseBroker, EconomicReleaseBroker>(Lifestyle.Singleton);
            container.Register <IDividendsBroker, DividendsBroker>(Lifestyle.Singleton);
            container.Register <IEarningsAnnouncementBroker, EarningsAnnouncementBroker>(Lifestyle.Singleton);

            //servers
            container.Register <IRealTimeDataServer, RealTimeDataServer>(Lifestyle.Singleton);
            container.Register <IHistoricalDataServer, HistoricalDataServer> (Lifestyle.Singleton);

            //scheduler
            container.Register <IJobFactory, JobFactory>(Lifestyle.Singleton);

            var quartzSettings = QuartzUtils.GetQuartzSettings(Settings.Default.databaseType);
            var factory        = new StdSchedulerFactory(quartzSettings);

            container.RegisterSingleton(() => factory.GetScheduler());
            container.RegisterInitializer <IScheduler>(scheduler =>
            {
                scheduler.JobFactory = container.GetInstance <IJobFactory>();
            });

            //http server
            container.Register <INancyBootstrapper, CustomBootstrapper>();

            //UI
            container.Register(() => DialogCoordinator.Instance);

            //ViewModels
            container.Register <MainViewModel>();
            var vm         = container.GetInstance <MainViewModel>();
            var mainWindow = new MainWindow(vm, container.GetInstance <IDataClient>());

            mainWindow.Show();
        }
Exemple #4
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();
        }