예제 #1
0
        public void RequestRealTimelDataRaisesErrorEventAndReturnsMinusOneWhenInstrumentIsNull()
        {
            var req = new RealTimeDataRequest
            {
                Instrument = null
            };

            bool errorTriggered = false;

            _client.Error += (sender, e) => errorTriggered = true;

            Assert.AreEqual(-1, _client.RequestRealTimeData(req));

            Assert.IsTrue(errorTriggered);
        }
예제 #2
0
파일: Program.cs 프로젝트: KBurov/qdms
        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();
            }
        }
예제 #3
0
        public void ServerCorrectlyForwardsRealTimeDataRequestsToBroker()
        {
            var ds = new Datasource()
            {
                ID = 1, Name = "TestDS"
            };
            var inst = new Instrument()
            {
                ID = 15, Datasource = ds, DatasourceID = 1, Symbol = "SPY", Type = InstrumentType.Stock
            };
            var req = new RealTimeDataRequest(inst, BarSize.FiveSeconds, rthOnly: false, savetoLocalStorage: false);

            _client.RequestRealTimeData(req);

            _brokerMock.Verify(x => x.RequestRealTimeData(It.Is <RealTimeDataRequest>(
                                                              y => y.Frequency == BarSize.FiveSeconds &&
                                                              y.RTHOnly == false &&
                                                              y.SaveToLocalStorage == false &&
                                                              y.Instrument.ID == 15 &&
                                                              y.Instrument.Symbol == "SPY" &&
                                                              y.Instrument.Datasource.Name == "TestDS")));
        }
예제 #4
0
파일: Program.cs 프로젝트: leo90skk/qdms
        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();
        }