Exemplo n.º 1
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); });
                }
            }
        }
Exemplo n.º 2
0
        public void TestSetSource3()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;
            string       source   = "NTV";

            string[] sources2  = new string[] { "DEX", "DEA" };
            string[] allSource = new string[] { "NTV", "DEX", "DEA" };
            string[] symbols   = new string[] { "AAPL", "IBM", "XBT/USD" };
            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbols(symbols);
                    listener.WaitOrders(allSource);
                    listener.WaitEvents <IDxOrder>(symbols);

                    s.SetSource(source);
                    Thread.Sleep(12000);
                    listener.ClearEvents <IDxOrder>();
                    Thread.Sleep(3000);
                    listener.WaitOrders(source);
                    listener.WaitEvents <IDxOrder>(symbols);
                    Assert.AreEqual(0, listener.GetOrderCount(sources2));

                    s.AddSource(sources2);
                    Thread.Sleep(1000);
                    listener.ClearEvents <IDxOrder>();
                    Thread.Sleep(3000);
                    listener.WaitOrders(allSource);
                    listener.WaitEvents <IDxOrder>(symbols);
                }
            }
        }
Exemplo n.º 3
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}")); });
                }
            }
        }
Exemplo 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);
                }
            }
        }
Exemplo n.º 5
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);
                }
            }
        }
        public void TestAddSource()
        {
            TestListener listener           = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string       candleSymbolString = "XBT/USD{=d}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(defaultDateTime, listener))
                {
                    s.AddSource("IST");
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    s.AddSource("NTV", "DEX");
                    listener.WaitEvents <IDxCandle>(candleSymbolString);
                }
            }
        }
Exemplo 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);
                }
            }
        }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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);
                        }
                    }
            }
        }
Exemplo 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>());
                }
            }
        }