Exemplo n.º 1
0
        public void InstrumentAdditionRequestsAreSentCorrectly()
        {
            var instrumentSourceMock = new Mock <IInstrumentSource>();

            using (var instrumentsServer = new InstrumentsServer(5555, instrumentSourceMock.Object)) {
                instrumentsServer.StartServer();

                var rtdBrokerMock = new Mock <IRealTimeDataBroker>();

                using (var rtdServer = new RealTimeDataServer(5554, 5553, rtdBrokerMock.Object)) {
                    rtdServer.StartServer();

                    _client.Connect();

                    var exchange = new Exchange {
                        ID = 1, Name = "NYSE", Sessions = new List <ExchangeSession>(), Timezone = "Eastern Standard Time"
                    };
                    var datasource = new Datasource {
                        ID = 1, Name = "Yahoo"
                    };
                    var instrument = new Instrument
                    {
                        Symbol           = "SPY",
                        UnderlyingSymbol = "SPY",
                        Type             = InstrumentType.Stock,
                        Currency         = "USD",
                        Exchange         = exchange,
                        Datasource       = datasource,
                        Multiplier       = 1
                    };

                    instrumentSourceMock.Setup(x => x.AddInstrument(It.IsAny <Instrument>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns(instrument);

                    var result = _client.AddInstrument(instrument);

                    Thread.Sleep(50);

                    Assert.IsTrue(result != null);

                    instrumentSourceMock.Verify(
                        x => x.AddInstrument(
                            It.Is <Instrument>(
                                y =>
                                y.Symbol == "SPY" &&
                                y.Exchange != null &&
                                y.Exchange.Name == "NYSE" &&
                                y.Datasource != null &&
                                y.Datasource.Name == "Yahoo" &&
                                y.Type == InstrumentType.Stock &&
                                y.Currency == "USD" &&
                                y.Multiplier == 1),
                            It.Is <bool>(y => y == false),
                            It.Is <bool>(y => y)));

                    rtdServer.StopServer();
                }

                instrumentsServer.StopServer();
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
        private void CreateAndStartServers()
        {
            RealTimeServer          = new RealTimeDataServer(Settings.Default.RealTimeDataServerRequestPort, RealTimeBroker);
            DataServer              = new HistoricalDataServer(Settings.Default.HistoricalServerPort, HistoricalBroker);
            MessagesServer          = new MessagesServer(Settings.Default.MessagesServerPushPort);
            EquityUpdateServer      = new EquityUpdateServer(Settings.Default.EquityUpdateServerRouterPort);
            InstrumentRequestServer = new RequestResponseServer(Settings.Default.InstrumetnUpdateRequestSocketPort);

            RealTimeServer.StartServer();
            DataServer.StartServer();
            MessagesServer.StartServer();
            InstrumentRequestServer.StartServer();
            //not using poller.Async, need to spawn thread
            Task.Factory.StartNew(EquityUpdateServer.StartServer, TaskCreationOptions.LongRunning);
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        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.");
        }
Exemplo n.º 7
0
        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

            var cfRealtimeBroker   = new ContinuousFuturesBroker(GetClient("RTDBCFClient"), false);
            var cfHistoricalBroker = new ContinuousFuturesBroker(GetClient("HDBCFClient"), false);

            IDataStorage localStorage;

            switch (_config.LocalStorage.Type)
            {
            case LocalStorageType.MySql:
                localStorage = new QDMSServer.DataSources.MySQLStorage(_config.LocalStorage.ConnectionString);
                break;

            case 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
            });
            _economicReleaseBroker = new EconomicReleaseBroker("FXStreet",
                                                               new[] { new fx.FXStreet(new CountryCodeHelper(entityContext.Countries.ToList())) });

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

            // create scheduler
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); //todo need settings for scheduler + jobfactory

            _scheduler = schedulerFactory.GetScheduler();

            var bootstrapper = new CustomBootstrapper(
                localStorage,
                _economicReleaseBroker,
                _historicalDataBroker,
                _realTimeDataBroker,
                _scheduler,
                _config.WebService.ApiKey);
            var uri = new Uri((_config.WebService.UseSsl ? "https" : "http") + "://localhost:" + _config.WebService.Port);

            _httpServer = new NancyHost(bootstrapper, uri);

            // ... start the servers
            _historicalDataServer.StartServer();
            _realTimeDataServer.StartServer();
            _httpServer.Start();
            _scheduler.Start();

            _log.Info($"Server is ready.");
        }