Пример #1
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);
                }
            }
        }
Пример #2
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");
                }
            }
        }
Пример #3
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);
                }
            }
        }
        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);
                }
            }
        }
Пример #5
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 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));
                }
            }
        }
        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);
                }
            }
        }
Пример #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);
                        }
                    }
            }
        }
        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]);
                }
            }
        }
Пример #11
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");
                }
            }
        }
Пример #12
0
        private static void Main()
        {
            const string    ADDRESS       = "demo.dxfeed.com:7300";
            const string    SYMBOL        = "IBM";
            const string    SOURCE        = "NTV";
            const string    RAW_FILE_NAME = "test.raw";
            const EventType EVENT_TYPE    = EventType.Order;

            Console.WriteLine("Connecting to {0} for Order#{1} snapshot on {2}...", ADDRESS, SOURCE, SYMBOL);

            try {
                NativeTools.InitializeLogging("dxf_read_write_raw_data_sample.log", true, true);
                Console.WriteLine("Writing to raw file");
                using (var con = new NativeConnection(ADDRESS, DisconnectHandler)) {
                    con.WriteRawData(RAW_FILE_NAME);
                    using (var s = con.CreateSubscription(EVENT_TYPE, new EventListener())) {
                        s.AddSource(SOURCE);
                        s.AddSymbol(SYMBOL);

                        Console.WriteLine("Receiving events for 15 seconds");
                        Thread.Sleep(15000);
                    }
                }

                Console.WriteLine("Reading from raw file");
                using (var con = new NativeConnection(RAW_FILE_NAME, DisconnectHandler)) {
                    using (var s = con.CreateSubscription(EVENT_TYPE, new EventListener())) {
                        s.AddSource(SOURCE);
                        s.AddSymbol(SYMBOL);

                        Thread.Sleep(2000);
                        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}");
            }
        }
        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);
                }
            }
        }
Пример #14
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]);
                }
            }
        }
Пример #15
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");
                }
            }
        }
Пример #16
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();
                }
            }
        }