Пример #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();
            }
        }
Пример #2
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();
        }
Пример #3
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.");
        }