Esempio n. 1
0
        public void TestClearSymbols2()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string source       = "NTV";
            string symbol       = "AAPL";
            string candleString = "XBT/USD{=d}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSource(source);
                    s.AddSymbol(symbol);
                    listener.WaitSnapshot <IDxOrder>(symbol, source);

                    s.Clear();
                    listener.ClearEvents <IDxOrder>();
                    Assert.AreEqual(0, s.GetSymbols().Count);

                    Thread.Sleep(10000);
                    Assert.AreEqual(0, listener.GetSnapshotsCount <IDxOrder>(symbol));

                    //add another symbol
                    s.AddSymbols(CandleSymbol.ValueOf(candleString));
                    listener.WaitSnapshot <IDxCandle>(candleString);
                }
            }
        }
Esempio n. 2
0
        public void TestAddSymbols()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string source = "NTV";
            string symbol = "AAPL";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    Assert.Throws <ArgumentException>(delegate { s.AddSymbols((string[])null); });
                    Assert.Throws <InvalidOperationException>(delegate { s.AddSymbols(new string[] { }); });
                    Assert.Throws <ArgumentException>(delegate { s.AddSymbols(new string[] { string.Empty }); });
                    Assert.Throws <InvalidOperationException>(delegate { s.AddSymbols(new string[] { "AAPL", "XBT/USD" }); });

                    s.AddSource(source);
                    s.AddSymbols(new string[] { symbol });

                    listener.WaitSnapshot <IDxOrder>(symbol, source);

                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); });
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); });
                }
            }
        }
Esempio n. 3
0
        public void TestAddSource()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string initialSource          = "NTV";
            string symbol      = "AAPL";
            string otherSource = "DEX";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    Assert.Throws <ArgumentException>(delegate { s.SetSource((string[])null); });
                    Assert.Throws <InvalidOperationException>(delegate { s.SetSource(new string[] { }); });
                    Assert.Throws <ArgumentException>(delegate { s.SetSource(new string[] { string.Empty }); });
                    Assert.Throws <InvalidOperationException>(delegate { s.SetSource(new string[] { "DEA", "DEX" }); });
                    s.AddSource(initialSource);
                    s.AddSymbol(symbol);
                    listener.WaitSnapshot <IDxOrder>(symbol, initialSource);

                    //try add source
                    Assert.Throws <InvalidOperationException>(delegate { s.AddSource(otherSource); });
                }
            }
        }
Esempio n. 4
0
        public void TestGetSymbols()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string source = "NTV";
            string symbol = "AAPL";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSource(source);
                    s.AddSymbol(symbol);
                    listener.WaitSnapshot <IDxOrder>(symbol, source);

                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(symbol, returnedSymbolList[0]);

                    s.Clear();
                    returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(0, returnedSymbolList.Count);
                }
            }
        }
Esempio n. 5
0
        public void TestAddSymbolsCandle()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string candleString           = "XBT/USD{=d}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    Assert.Throws <ArgumentException>(delegate { s.AddSymbols((CandleSymbol[])null); });
                    Assert.Throws <InvalidOperationException>(delegate { s.AddSymbols(new CandleSymbol[] { }); });
                    Assert.Throws <ArgumentException>(delegate { s.AddSymbols(new CandleSymbol[] { null }); });
                    Assert.Throws <InvalidOperationException>(delegate
                    {
                        s.AddSymbols(new CandleSymbol[] {
                            CandleSymbol.ValueOf("AAPL{=d,price=mark}"),
                            CandleSymbol.ValueOf("XBT/USD{=d,price=mark}")
                        });
                    });

                    s.AddSymbols(new CandleSymbol[] { CandleSymbol.ValueOf(candleString) });

                    listener.WaitSnapshot <IDxCandle>(candleString);

                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); });
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); });
                }
            }
        }
Esempio n. 6
0
 private void PrintSnapshots<TE>(SnapshotTestListener listener, params SnapshotCase[] cases)
 {
     Console.WriteLine(string.Format("Snapshots of {0}: Total count: {1}", typeof(TE), listener.GetSnapshotsCount<TE>()));
     foreach (SnapshotCase snapshotCase in cases)
     {
         if (snapshotCase.SnapshotType != typeof(TE))
             continue;
         if (snapshotCase.SnapshotType == typeof(IDxOrder))
             Console.WriteLine("    symbol {0}#{1}: data count: {2}",
                 snapshotCase.Symbol, snapshotCase.Source,
                 listener.GetSnapshotsCount<IDxOrder>(snapshotCase.Symbol));
         else if (snapshotCase.SnapshotType == typeof(IDxCandle))
             Console.WriteLine("    symbol {0}: data count: {1}",
                 snapshotCase.Symbol,
                 listener.GetSnapshotsCount<IDxCandle>(snapshotCase.Symbol));
     }
 }
Esempio n. 7
0
        public void TestAddSourceCandle2()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string initialSource          = "NTV";
            string candleString           = "XBT/USD{=d}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSymbol(CandleSymbol.ValueOf(candleString));
                    s.AddSource(initialSource);
                    listener.WaitSnapshot <IDxCandle>(candleString);
                    s.AddSource(initialSource);
                }
            }
        }
Esempio n. 8
0
        public void TestAll()
        {
            TestListener          eventListener     = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            SnapshotTestListener  snapshotListener  = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            OrderViewTestListener orderViewListener = new OrderViewTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType             events            = EventType.Order | EventType.Profile |
                                                      EventType.Quote | EventType.Summary | EventType.TimeAndSale | EventType.Series |
                                                      EventType.Trade;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription eventSubscription = con.CreateSubscription(events, eventListener),
                       candleSubscription = con.CreateSubscription(oneMonth, eventListener),
                       orderViewSubscription = con.CreateOrderViewSubscription(orderViewListener))
                    using (SnapshotCollection snapshotCollection = new SnapshotCollection(con, snapshotListener, snapshotCases))
                    {
                        eventSubscription.AddSymbols(eventSymbols);
                        candleSubscription.AddSymbol(CandleSymbol.ValueOf(candleSymbols[0]));
                        orderViewSubscription.AddSource(orderViewSources);
                        orderViewSubscription.AddSymbols(orderViewSymbols);

                        DateTime startTime = DateTime.Now;
                        while (testCommonTime >= (DateTime.Now - startTime).TotalMilliseconds)
                        {
                            Console.WriteLine();
                            PrintEvents <IDxCandle>(eventListener, candleSymbols);
                            PrintEvents <IDxOrder>(eventListener, eventSymbols);
                            PrintEvents <IDxProfile>(eventListener, eventSymbols);
                            PrintEvents <IDxQuote>(eventListener, eventSymbols);
                            PrintEvents <IDxSummary>(eventListener, eventSymbols);
                            PrintEvents <IDxTimeAndSale>(eventListener, eventSymbols);
                            PrintEvents <IDxSeries>(eventListener, eventSymbols);
                            PrintEvents <IDxTrade>(eventListener, eventSymbols);

                            PrintSnapshots <IDxOrder>(snapshotListener, snapshotCases);
                            PrintSnapshots <IDxCandle>(snapshotListener, snapshotCases);

                            PrintOrderViews(orderViewListener, orderViewSymbols);
                            Thread.Sleep(testPrintInterval);
                        }
                    }
            }
        }
Esempio n. 9
0
        public void TestRemoveSymbolsCandle()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string candleString           = "XBT/USD{=d}";

            CandleSymbol[] unusingSymbols = new CandleSymbol[] {
                CandleSymbol.ValueOf("AAPL{=d,price=mark}"),
                CandleSymbol.ValueOf("XBT/USD{=d,price=mark}")
            };
            CandleSymbol[] usingSymbols = new CandleSymbol[] {
                CandleSymbol.ValueOf(candleString),
                CandleSymbol.ValueOf("AAPL{=d,price=mark}"),
                CandleSymbol.ValueOf("XBT/USD{=d,price=mark}")
            };
            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSymbol(CandleSymbol.ValueOf(candleString));

                    Assert.AreEqual(1, s.GetSymbols().Count);
                    listener.WaitSnapshot <IDxCandle>(candleString);

                    Assert.Throws <ArgumentException>(delegate { s.RemoveSymbols((CandleSymbol[])null); });
                    s.RemoveSymbols(new CandleSymbol[] { null });
                    s.RemoveSymbols("AAPL", "XBT/USD");
                    s.RemoveSymbols(unusingSymbols);
                    Thread.Sleep(5000);
                    Assert.AreEqual(1, s.GetSymbols().Count);

                    s.RemoveSymbols(usingSymbols);
                    Thread.Sleep(3000);
                    Assert.AreEqual(0, s.GetSymbols().Count);
                    listener.ClearEvents <IDxCandle>();
                    Thread.Sleep(10000);
                    Assert.AreEqual(0, listener.GetSnapshotsCount <IDxCandle>());
                }
            }
        }
Esempio n. 10
0
        public void TestRemoveSymbols()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string source = "NTV";
            string symbol = "AAPL";

            string[] unusingSymbols = { "IBM", "XBT/USD" };
            string[] usingSymbols   = { symbol, "IBM", "XBT/USD" };
            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSource(source);
                    s.AddSymbol(symbol);

                    Assert.AreEqual(1, s.GetSymbols().Count);
                    listener.WaitSnapshot <IDxOrder>(symbol, source);

                    Assert.Throws <ArgumentException>(delegate { s.RemoveSymbols((string[])null); });
                    s.RemoveSymbols(new string[] { string.Empty });
                    s.RemoveSymbols(new CandleSymbol[] {
                        CandleSymbol.ValueOf("AAPL{=d,price=mark}"),
                        CandleSymbol.ValueOf("XBT/USD{=d,price=mark}")
                    });
                    s.RemoveSymbols(unusingSymbols);
                    Thread.Sleep(5000);
                    Assert.AreEqual(1, s.GetSymbols().Count);

                    s.RemoveSymbols(usingSymbols);
                    Thread.Sleep(3000);
                    Assert.AreEqual(0, s.GetSymbols().Count);
                    listener.ClearEvents <IDxOrder>();
                    Thread.Sleep(10000);
                    Assert.AreEqual(0, listener.GetSnapshotsCount <IDxOrder>());
                }
            }
        }
Esempio n. 11
0
        public void TestGetSymbolsCandle()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string candleString           = "XBT/USD{=d}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener))
                {
                    s.AddSymbol(CandleSymbol.ValueOf(candleString));
                    listener.WaitSnapshot <IDxCandle>(candleString);

                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(candleString, returnedSymbolList[0]);

                    s.Clear();
                    returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(0, returnedSymbolList.Count);
                }
            }
        }