Пример #1
0
        public void TestSetSymbols()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string source      = "NTV";
            string symbol      = "AAPL";
            string otherSymbol = "IBM";

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

                    s.AddSource(source);
                    s.SetSymbols(new string[] { symbol });
                    listener.WaitSnapshot <IDxOrder>(symbol, source);

                    s.SetSymbols(new string[] { otherSymbol });
                    listener.ClearEvents <IDxOrder>();
                    Thread.Sleep(10000);
                    listener.WaitSnapshot <IDxOrder>(otherSymbol, source);
                    Assert.AreEqual(1, listener.GetSnapshotsCount <IDxOrder>(otherSymbol));
                    Assert.AreEqual(0, listener.GetSnapshotsCount <IDxOrder>(symbol));

                    // add another symbols
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); });
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); });
                }
            }
        }
Пример #2
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);
                }
            }
        }
Пример #3
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));
     }
 }
Пример #4
0
        public void TestSetSymbolsCandle()
        {
            SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string candleString           = "XBT/USD{=d}";
            string otherCandleString      = "XBT/USD{=2d}";

            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.SetSymbols(new CandleSymbol[] { CandleSymbol.ValueOf(candleString) });
                    listener.WaitSnapshot <IDxCandle>(candleString);

                    s.SetSymbols(new CandleSymbol[] { CandleSymbol.ValueOf(otherCandleString) });
                    listener.ClearEvents <IDxCandle>();
                    Thread.Sleep(10000);
                    listener.WaitSnapshot <IDxCandle>(otherCandleString);
                    Assert.AreEqual(1, listener.GetSnapshotsCount <IDxCandle>(otherCandleString));
                    Assert.AreEqual(0, listener.GetSnapshotsCount <IDxCandle>(candleString));

                    // add another symbols
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); });
                    Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); });
                }
            }
        }
Пример #5
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>());
                }
            }
        }
Пример #6
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>());
                }
            }
        }