public void TestClearSymbols()
        {
            TestListener listener           = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string       candleSymbolString = "XBT/USD{=d}";
            string       aaplSymbolString   = "AAPL{=d,price=mark}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(defaultDateTime, listener))
                {
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    listener.WaitEvents <IDxCandle>(candleSymbolString);

                    s.Clear();
                    listener.ClearEvents <IDxCandle>();
                    Thread.Sleep(10000);
                    Assert.AreEqual(0, listener.GetEventCount <IDxCandle>());

                    //try to restore symbols
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    listener.WaitEvents <IDxCandle>(candleSymbolString);

                    //set other symbol
                    s.Clear();
                    listener.ClearEvents <IDxCandle>();
                    s.AddSymbol(CandleSymbol.ValueOf(aaplSymbolString));
                    listener.WaitEvents <IDxCandle>(aaplSymbolString);
                    Assert.AreEqual(listener.GetEventCount <IDxCandle>(), listener.GetEventCount <IDxCandle>(aaplSymbolString));
                }
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo 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); });
                }
            }
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 5
0
        public void TestClearSymbols()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbols("AAPL", "IBM");

                    listener.WaitEvents <IDxOrder>("AAPL", "IBM");

                    s.Clear();
                    listener.ClearEvents <IDxOrder>();

                    Thread.Sleep(10000);
                    Assert.AreEqual(0, listener.GetEventCount <IDxOrder>("AAPL", "IBM"));

                    //add another symbol
                    s.AddSymbols("XBT/USD");
                    listener.WaitEvents <IDxOrder>("XBT/USD");
                }
            }
        }
Ejemplo n.º 6
0
        public void TestSetSymbolsCandle()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbols("AAPL", "IBM");

                    listener.WaitEvents <IDxOrder>("AAPL", "IBM");

                    CandleSymbol[] candleSymbols = new CandleSymbol[] {
                        CandleSymbol.ValueOf("XBT/USD{=d}"),
                        CandleSymbol.ValueOf("AAPL{=d}"),
                        CandleSymbol.ValueOf("IBM{=d}")
                    };
                    s.SetSymbols(candleSymbols);

                    listener.ClearEvents <IDxOrder>();
                    Assert.AreEqual(2, s.GetSymbols().Count);
                    listener.WaitEvents <IDxOrder>("AAPL", "IBM");
                }
            }
        }
        public void TestAddSymbols()
        {
            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))
                {
                    //add candle symbol
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(candleSymbolString, returnedSymbolList[0]);

                    //try to add other non-candle symbols
                    s.AddSymbols("AAPL", "IBM");
                    returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(candleSymbolString, returnedSymbolList[0]);

                    listener.WaitEvents <IDxCandle>(candleSymbolString);
                }
            }
        }
Ejemplo n.º 8
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}")); });
                }
            }
        }
Ejemplo n.º 9
0
        public void TestGetSymbols()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    List <string> symbols = new List <string>(new string[] { "AAPL", "IBM" });
                    s.AddSymbols(symbols.ToArray());

                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(symbols.Count, returnedSymbolList.Count);
                    foreach (string symbol in returnedSymbolList)
                    {
                        Assert.True(symbols.Contains(symbol));
                    }

                    s.Clear();
                    returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(0, returnedSymbolList.Count);
                }
            }
        }
Ejemplo n.º 10
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);
                }
            }
        }
Ejemplo n.º 11
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}")); });
                }
            }
        }
        public void TestSetSymbolsCandle()
        {
            TestListener listener           = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string       candleSymbolString = "XBT/USD{=d}";
            string       aaplSymbolString   = "AAPL{=d,price=mark}";
            string       ibmSymbolString    = "IBM{=d,price=mark}";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(defaultDateTime, listener))
                {
                    //add candle symbol
                    s.AddSymbols(new CandleSymbol[] {
                        CandleSymbol.ValueOf(aaplSymbolString),
                        CandleSymbol.ValueOf(ibmSymbolString)
                    });
                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(2, returnedSymbolList.Count);
                    listener.WaitEvents <IDxCandle>(aaplSymbolString, ibmSymbolString);

                    //try to set other non-candle symbols
                    s.SetSymbols(CandleSymbol.ValueOf(candleSymbolString));
                    returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(candleSymbolString, returnedSymbolList[0]);
                    listener.ClearEvents <IDxCandle>();
                    listener.WaitEvents <IDxCandle>(candleSymbolString);
                }
            }
        }
Ejemplo n.º 13
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);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        ///     Creates a time event subscription.
        /// </summary>
        /// <remarks>
        ///     Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="type">Event type.</param>
        /// <param name="time">Date time in the past.</param>
        /// <param name="listener">Event listener callback.</param>
        /// <returns>Subscription object.</returns>
        /// <exception cref="ArgumentNullException">Listener is null.</exception>
        /// <exception cref="DxException"></exception>
        public IDxSubscription CreateSubscription(EventType type, DateTime?time, IDxEventListener listener)
        {
            if (handle == IntPtr.Zero)
            {
                throw new NativeDxException("not connected");
            }

            IDxSubscription result = (time == null)
                ? new NativeSubscription(this, type, 0L, listener)
                : new NativeSubscription(this, type, (DateTime)time, listener);

            subscriptions.Add(result);
            return(result);
        }
        public void TestSetSource()
        {
            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.SetSource("IST");
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    s.SetSource("NTV", "DEX");
                    listener.WaitEvents <IDxCandle>(candleSymbolString);
                }
            }
        }
        public void TestGetSymbols()
        {
            TestListener listener           = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string       candleSymbolString = "XBT/USD{=d}";
            CandleSymbol candleSymbol       = CandleSymbol.ValueOf(candleSymbolString);

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(defaultDateTime, listener))
                {
                    s.AddSymbol(candleSymbol);
                    IList <string> returnedSymbolList = s.GetSymbols();
                    Assert.AreEqual(1, returnedSymbolList.Count);
                    Assert.AreEqual(candleSymbolString, returnedSymbolList[0]);
                }
            }
        }
Ejemplo n.º 17
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);
                }
            }
        }
Ejemplo n.º 18
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);
                        }
                    }
            }
        }
Ejemplo n.º 19
0
        /// <inheritdoc />
        public void SetSource(params string[] sources)
        {
            if (connection == null)
            {
                throw new InvalidOperationException("Object is disposed");
            }

            if (subscription != null)
            {
                throw new InvalidOperationException("Sources is already configured for this subscription.");
            }

            subscription = connection.CreateSubscription(EventType.Order, this);
            subscription.SetSource(sources);
            foreach (var source in sources)
            {
                this.sources.Add(OrderSource.ValueOf(source));
            }
        }
Ejemplo n.º 20
0
        public void TestAddSymbols()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbols("AAPL", "XBT/USD");

                    listener.WaitEvents <IDxOrder>("AAPL", "XBT/USD");

                    listener.ClearEvents <IDxOrder>();
                    s.AddSymbols("IBM", "MSFT");
                    listener.WaitEvents <IDxOrder>("AAPL", "XBT/USD", "IBM", "MSFT");
                }
            }
        }
        public void TestAddSymbolCandle()
        {
            TestListener listener                  = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            string       candleSymbolString        = "XBT/USD{=d}";
            string       anotherCandleSymbolString = "AAPL{=d,price=mark}";
            CandleSymbol anotherCandleSymbol       = CandleSymbol.ValueOf(anotherCandleSymbolString);

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(defaultDateTime, listener))
                {
                    s.AddSymbol(CandleSymbol.ValueOf(candleSymbolString));
                    listener.WaitEvents <IDxCandle>(candleSymbolString);

                    s.AddSymbol(anotherCandleSymbol);
                    listener.ClearEvents <IDxCandle>();
                    listener.WaitEvents <IDxCandle>(candleSymbolString, anotherCandleSymbolString);
                }
            }
        }
Ejemplo n.º 22
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>());
                }
            }
        }
Ejemplo n.º 23
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>());
                }
            }
        }
Ejemplo n.º 24
0
        public void TestAddSymbolCandle()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;
            string       symbol   = "AAPL";

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbol(symbol);

                    listener.WaitEvents <IDxOrder>();

                    CandleSymbol candleSymbol = CandleSymbol.ValueOf("XBT/USD{=d}");
                    s.AddSymbol(candleSymbol);
                    listener.ClearEvents <IDxOrder>();
                    Assert.AreEqual(1, s.GetSymbols().Count);
                    Assert.AreEqual(symbol, s.GetSymbols()[0]);
                }
            }
        }
Ejemplo n.º 25
0
        public void TestAddSymbol()
        {
            TestListener listener = new TestListener(eventsTimeout, eventsSleepTime, IsConnected);
            EventType    events   = EventType.Order;

            using (var con = new NativeConnection(address, OnDisconnect))
            {
                Interlocked.Exchange(ref isConnected, 1);
                using (IDxSubscription s = con.CreateSubscription(events, listener))
                {
                    s.AddSymbol("AAPL");

                    listener.WaitEvents <IDxOrder>();

                    TestListener.ReceivedEvent <IDxOrder> e = listener.GetLastEvent <IDxOrder>();
                    Assert.AreEqual("AAPL", e.Symbol);

                    s.AddSymbol("IBM");
                    listener.ClearEvents <IDxOrder>();
                    listener.WaitEvents <IDxOrder>("AAPL", "IBM");
                }
            }
        }
Ejemplo n.º 26
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);
                }
            }
        }
Ejemplo n.º 27
0
        private bool disposedValue = false; // To detect redundant calls

        /// <summary>
        ///   This code added to correctly implement the disposable pattern.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (connection != null)
            {
                connection.RemoveSubscription(this);
                connection = null;
            }

            if (disposedValue)
            {
                return;
            }

            if (disposing)
            {
                if (subscription != null)
                {
                    subscription.Dispose();
                    subscription = null;
                }
            }

            disposedValue = true;
        }
Ejemplo n.º 28
0
        private static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 9)
            {
                ShowUsage();

                return;
            }

            var address             = args[HostIndex];
            var symbol              = args[SymbolIndex];
            var source              = new InputParam <string>(OrderSource.NTV.Name);
            var dateTime            = new InputParam <DateTime?>(null);
            var recordsPrintLimit   = new InputParam <int>(DefaultRecordsPrintLimit);
            var token               = new InputParam <string>(null);
            var logDataTransferFlag = false;

            for (var i = SymbolIndex + 1; i < args.Length; i++)
            {
                if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                {
                    continue;
                }

                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;

                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;

                    continue;
                }

                if (!source.IsSet)
                {
                    source.Value = args[i];
                }
            }

            Console.WriteLine(
                $"Connecting to {address} for [Order#{source.Value} (book)] on [{symbol}] ...");

            using (var con = token.IsSet
                ? new NativeConnection(address, token.Value, DisconnectHandler, ConnectionStatusChangeHandler)
                : new NativeConnection(address, DisconnectHandler, ConnectionStatusChangeHandler))
            {
                IDxSubscription s = null;
                try
                {
                    NativeTools.InitializeLogging("dxf_simple_order_book_sample.log", true, true, logDataTransferFlag);
                    s = con.CreateSnapshotSubscription(EventType.Order, dateTime.Value, new OrderListener(recordsPrintLimit.Value));
                    s.SetSource(source.Value);
                    s.AddSymbols(symbol);

                    Console.WriteLine("Press enter to stop");
                    Console.ReadLine();
                }
                catch (DxException dxException)
                {
                    Console.WriteLine($"Native exception occured: {dxException.Message}");
                }
                catch (Exception exc)
                {
                    Console.WriteLine($"Exception occured: {exc.Message}");
                }
                finally
                {
                    s?.Dispose();
                }
            }
        }
Ejemplo n.º 29
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(
                    "Usage: dxf_ipf_connect_sample <ipf_host> <user> <password> <host:port> <events>\n" +
                    "or:    dxf_ipf_connect_sample <file> <host:port> <event>\n" +
                    "where\n" +
                    "    ipf_host  - The valid ipf host to download instruments (https://tools.dxfeed.com/ipf)\n" +
                    "    user      - The user name to host access\n" +
                    "    password  - The user password to host access\n" +
                    "    host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    events    - Any of the {Profile,Quote,Trade,TimeAndSale,Summary,\n" +
                    "                TradeETH,Candle,Greeks,TheoPrice,Underlying,Series,\n" +
                    "                Configuration}\n" +
                    "    file      - The name of file or archive (.gz or .zip) contains instrument profiles\n\n" +
                    "example: dxf_ipf_connect_sample https://tools.dxfeed.com/ipf?TYPE=STOCK demo demo demo.dxfeed.com:7300 Quote,Trade\n" +
                    "or:      dxf_ipf_connect_sample https://demo:[email protected]/ipf?TYPE=STOCK demo.dxfeed.com:7300 Quote,Trade\n" +
                    "or:      dxf_ipf_connect_sample profiles.zip demo.dxfeed.com:7300 Quote,Trade\n"
                    );
                return;
            }

            var           path     = args[0];
            var           user     = string.Empty;
            var           password = string.Empty;
            string        dxFeedAddress;
            EventType     events;
            List <string> symbols;

            try {
                var reader = new InstrumentProfileReader();
                IList <InstrumentProfile> profiles;
                var dxFeedAddressParamIndex = 1;

                if (IsFilePath(path))
                {
                    //Read profiles from local file system
                    using (var inputStream = new FileStream(path, FileMode.Open)) {
                        profiles = reader.Read(inputStream, path);
                    }
                }
                else
                {
                    if (args.Length == 5)
                    {
                        user     = args[1];
                        password = args[2];
                        dxFeedAddressParamIndex += 2;
                    }

                    //Read profiles from server
                    profiles = reader.ReadFromFile(path, user, password);
                }

                dxFeedAddress = args[dxFeedAddressParamIndex];
                var eventsString = args[dxFeedAddressParamIndex + 1];

                if (!Enum.TryParse(eventsString, true, out events))
                {
                    Console.WriteLine($"Unsupported event type: {eventsString}");
                    return;
                }


                if (profiles.Count == 0)
                {
                    Console.WriteLine("There are no profiles");

                    return;
                }

                Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count);

                symbols = profiles.Select(profile => profile.GetSymbol()).ToList();

                Console.WriteLine(value: $"Symbols: {string.Join(", ", symbols.Take(42).ToArray())}...");
            } catch (Exception exc) {
                Console.WriteLine($"Exception occured: {exc}");

                return;
            }

            Console.WriteLine($"Connecting to {dxFeedAddress} for [{events} on [{string.Join(", ", symbols.Take(42).ToArray())}...] ...");

            NativeTools.InitializeLogging("dxf_ipf_connect_sample.log", true, true);

            using (var connection = new NativeConnection(dxFeedAddress, DisconnectHandler, ConnectionStatusChangeHandler)) {
                IDxSubscription subscription = null;
                try {
                    subscription = connection.CreateSubscription(events, new EventPrinter());

                    if (events == EventType.Candle)
                    {
                        subscription.AddSymbols(symbols.ConvertAll(CandleSymbol.ValueOf).ToArray());
                    }
                    else
                    {
                        subscription.AddSymbols(symbols.ToArray());
                    }

                    Console.WriteLine("Press enter to stop");
                    Console.ReadLine();
                } catch (DxException dxException) {
                    Console.WriteLine($"Native exception occured: {dxException.Message}");
                } catch (Exception exc) {
                    Console.WriteLine($"Exception occured: {exc.Message}");
                } finally {
                    subscription?.Dispose();
                }
            }
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 13)
            {
                Console.WriteLine(
                    "Usage: dxf_client <host:port> <event> <symbol> [<date>] [<source>] [snapshot] [-l <records_print_limit>] [-T <token>] [-s <subscr_data>] [-p]\n" +
                    "where\n" +
                    "    host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n" +
                    "    event     - Any of the {Profile,Order,Quote,Trade,TimeAndSale,Summary,\n" +
                    "                TradeETH,SpreadOrder,Candle,Greeks,TheoPrice,Underlying,Series,\n" +
                    "                Configuration}\n" +
                    "    symbol    - a) IBM, MSFT, ... ; * - all symbols\n" +
                    "                b) if it is Candle event you can specify candle symbol\n" +
                    "                   attribute by string, for example: XBT/USD{=d}\n" +
                    "    date      - The date of time series event in the format YYYY-MM-DD (optional)\n" +
                    "    source    - Used only for Order or MarketMaker subscription:\n" +
                    "                a) OPTIONAL source for order events is any combination of:\n" +
                    "                   NTV,NFX,ESPD,XNFI,ICE,ISE,DEA,DEX,BYX,BZX,BATE,CHIX,CEUX,\n" +
                    "                   BXTR,IST,BI20,ABE,FAIR,GLBX,ERIS,XEUR,CFE,C2OX,SMFE...;\n" +
                    "                b) source for Order snapshot can be one of following: NTV,NFX,\n" +
                    "                   ESPD,XNFI,ICE,ISE,DEA,DEX,BYX,BZX,BATE,CHIX,CEUX,BXTR,IST,BI20,\n" +
                    "                   ABE,FAIR,GLBX,ERIS,XEUR,CFE,C2OX,SMFE...\n" +
                    "                c) source for MarketMaker snapshot, can be COMPOSITE_ASK\n" +
                    "                   or COMPOSITE_BID\n" +
                    "    snapshot  - Use keyword 'snapshot' for create snapshot subscription,\n" +
                    "                otherwise leave empty\n" +
                    $"    -l <records_print_limit> - The number of displayed records (0 - unlimited, default: {DEFAULT_RECORDS_PRINT_LIMIT})\n" +
                    "    -T <token>               - The authorization token\n\n" +
                    "    -s <subscr_data>         - The subscription data: ticker|TICKER, stream|STREAM, history|HISTORY\n" +
                    "    -p                       - Enables the data transfer logging\n\n" +
                    "examples:\n" +
                    "  events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST\n" +
                    "  events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST -s stream\n" +
                    "  order: dxf_client demo.dxfeed.com:7300 Order MSFT.TEST,IBM.TEST NTV,IST\n" +
                    "  candle: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10\n" +
                    "  underlying: dxf_client demo.dxfeed.com:7300 Underlyingn AAPL\n" +
                    "  series: dxf_client demo.dxfeed.com:7300 Series AAPL\n" +
                    "  order snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL NTV snapshot\n" +
                    "  order snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL NTV snapshot -l 0\n" +
                    "  market maker snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL COMPOSITE_BID snapshot\n" +
                    "  market maker snapshot: dxf_client demo.dxfeed.com:7300 Order AAPL COMPOSITE_BID snapshot -l 3\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10 snapshot\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d} 2016-10-10 snapshot -l 10\n" +
                    "  candle snapshot: dxf_client demo.dxfeed.com:7300 Candle XBT/USD{=d,pl=0.5} 2016-10-10 snapshot -l 10\n"
                    );
                return;
            }

            var address = args[HOST_INDEX];

            EventType events;

            if (!Enum.TryParse(args[EVENT_INDEX], true, out events))
            {
                Console.WriteLine($"Unsupported event type: {args[EVENT_INDEX]}");
                return;
            }

            var symbols             = args[SYMBOL_INDEX];
            var sources             = new InputParam <string[]>(new string[] { });
            var isSnapshot          = new InputParam <bool>(false);
            var dateTime            = new InputParam <DateTime?>(null);
            var recordsPrintLimit   = new InputParam <int>(DEFAULT_RECORDS_PRINT_LIMIT);
            var token               = new InputParam <string>(null);
            var subscriptionData    = new InputParam <EventSubscriptionFlag>(EventSubscriptionFlag.Default);
            var logDataTransferFlag = false;

            for (var i = SYMBOL_INDEX + 1; i < args.Length; i++)
            {
                if (!dateTime.IsSet && TryParseDateTimeParam(args[i], dateTime))
                {
                    continue;
                }
                if (!isSnapshot.IsSet && TryParseSnapshotParam(args[i], isSnapshot))
                {
                    continue;
                }
                if (!recordsPrintLimit.IsSet && i < args.Length - 1 &&
                    TryParseRecordsPrintLimitParam(args[i], args[i + 1], recordsPrintLimit))
                {
                    i++;

                    continue;
                }

                if (!token.IsSet && i < args.Length - 1 &&
                    TryParseTaggedStringParam("-T", args[i], args[i + 1], token))
                {
                    i++;

                    continue;
                }

                if (!subscriptionData.IsSet && i < args.Length - 1 &&
                    TryParseEventSubscriptionFlagParam("-s", args[i], args[i + 1], subscriptionData))
                {
                    i++;

                    continue;
                }

                if (logDataTransferFlag == false && args[i].Equals("-p"))
                {
                    logDataTransferFlag = true;
                    i++;

                    continue;
                }

                if (!sources.IsSet)
                {
                    TryParseSourcesParam(args[i], sources);
                }
            }

            var snapshotString   = isSnapshot.Value ? " snapshot" : string.Empty;
            var timeSeriesString = dateTime.IsSet && !isSnapshot.Value ? " time-series" : string.Empty;

            Console.WriteLine(
                $"Connecting to {address} for [{events}{snapshotString}]{timeSeriesString} on [{symbols}] ...");

            NativeTools.InitializeLogging("dxf_client.log", true, true, logDataTransferFlag);

            var listener = new EventPrinter();

            using (var con = token.IsSet
                ? new NativeConnection(address, token.Value, DisconnectHandler, ConnectionStatusChangeHandler)
                : new NativeConnection(address, DisconnectHandler, ConnectionStatusChangeHandler)) {
                IDxSubscription s = null;
                try {
                    if (isSnapshot.Value)
                    {
                        s = con.CreateSnapshotSubscription(events, dateTime.Value,
                                                           new SnapshotPrinter(recordsPrintLimit.Value));
                    }
                    else if (dateTime.IsSet)
                    {
                        s = subscriptionData.IsSet
                            ? con.CreateSubscription(events, dateTime.Value, subscriptionData.Value, listener)
                            : con.CreateSubscription(events, dateTime.Value, listener);
                    }
                    else
                    {
                        s = subscriptionData.IsSet
                            ? con.CreateSubscription(events, subscriptionData.Value, listener)
                            : con.CreateSubscription(events, listener);
                    }

                    if (events.HasFlag(EventType.Order) && sources.Value.Length > 0)
                    {
                        s.SetSource(sources.Value);
                    }

                    if (events == EventType.Candle)
                    {
                        var candleSymbol = CandleSymbol.ValueOf(symbols);
                        s.AddSymbol(candleSymbol);
                    }
                    else
                    {
                        s.AddSymbols(symbols.Split(','));
                    }

                    Console.WriteLine("Press enter to stop");
                    Console.ReadLine();
                } catch (DxException dxException) {
                    Console.WriteLine($"Native exception occured: {dxException.Message}");
                } catch (Exception exc) {
                    Console.WriteLine($"Exception occured: {exc.Message}");
                } finally {
                    s?.Dispose();
                }
            }
        }