Example #1
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}")); });
                }
            }
        }
Example #2
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); });
                }
            }
        }
Example #3
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);
                }
            }
        }
Example #4
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);
                }
            }
        }
Example #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}")); });
                }
            }
        }
Example #6
0
 public void Initialize(NativeConnection connection, IDxSnapshotListener listener)
 {
     snapshotSubscription = connection.CreateSnapshotSubscription(time, listener);
     if (candleSymbol != null)
     {
         snapshotSubscription.AddSymbol(candleSymbol);
     }
     else
     {
         snapshotSubscription.AddSource(source);
         snapshotSubscription.AddSymbol(symbol);
     }
 }
Example #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);
                }
            }
        }
Example #8
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>());
                }
            }
        }
Example #9
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>());
                }
            }
        }
Example #10
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);
                }
            }
        }