Пример #1
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();
            }
        }
Пример #2
0
        public void AcceptAvailableDataRequestsAreForwardedToTheHistoricalDataBroker()
        {
            var fixture    = new Fixture();
            var instrument = new Instrument
            {
                ID         = 1,
                Symbol     = "SPY",
                Datasource = new Datasource {
                    ID = 1, Name = "MockSource"
                }
            };

            _historicalDataBrokerMock
            .Setup(x => x.GetAvailableDataInfo(It.Is <Instrument>(i => i.ID.HasValue && i.ID.Value == 1 && i.Symbol.Equals("SPY", StringComparison.InvariantCultureIgnoreCase))))
            .Returns(fixture.CreateMany <StoredDataInfo>().ToList());

            _client.GetLocallyAvailableDataInfo(instrument);
            // TODO: Think about delay amount
            Thread.Sleep(1000);

            _historicalDataBrokerMock.Verify(
                x => x.GetAvailableDataInfo(
                    It.Is <Instrument>(
                        y =>
                        y.ID == 1 &&
                        y.Symbol == "SPY")
                    ),
                Times.Once);
        }
Пример #3
0
        /// <summary>
        /// Tries to retrieve data on locally available data for a given instrument.
        /// Returns DateTime(1,1,1) if the request is not filled.
        /// </summary>
        /// <param name="instrument"></param>
        /// <returns></returns>
        private StoredDataInfo TryGetStorageInfo(Instrument instrument)
        {
            if (instrument.ID == null)
            {
                throw new Exception("Null instrument ID return wtf");
            }
            _client.GetLocallyAvailableDataInfo(instrument);

            //wait until the storage info arrives
            int i = 0;

            while (i < 100)
            {
                Thread.Sleep(20);
                lock (_storageInfoLock)
                {
                    if (_storageInfo.ContainsKey(instrument.ID.Value))
                    {
                        return(_storageInfo[instrument.ID.Value]);
                    }
                }
                i++;
            }

            return(null);
        }
Пример #4
0
        public void AcceptAvailableDataRequestsAreForwardedToTheHistoricalDataBroker()
        {
            var instrument = new Instrument
            {
                ID         = 1,
                Symbol     = "SPY",
                Datasource = new Datasource {
                    ID = 1, Name = "MockSource"
                }
            };

            _client.GetLocallyAvailableDataInfo(instrument);

            Thread.Sleep(50);

            _brokerMock.Verify(x => x.GetAvailableDataInfo(
                                   It.Is <Instrument>(y =>
                                                      y.ID == 1 &&
                                                      y.Symbol == "SPY")
                                   ), Times.Once);
        }
Пример #5
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();
        }