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 CandleSymbolSessionTest(string symbolString, int expectedId)
        {
            var symbol = CandleSymbol.ValueOf(symbolString);

            Assert.AreEqual(symbolString, symbol.ToString());
            Assert.AreEqual(expectedId, symbol.SessionId);
        }
Exemple #3
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 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);
                }
            }
        }
        private void PrintSnapshot <TE>(IDxEventBuf <TE> buf)
        {
            var symbolStr = buf.Symbol;

            if (buf.EventType == EventType.Candle)
            {
                var candleSymbol = CandleSymbol.ValueOf(symbolStr);
                if (candleSymbol.IsDefault())
                {
                    symbolStr = candleSymbol.ToFullString();
                }
            }

            Console.WriteLine("Snapshot {0} {{Symbol: '{1}', RecordsCount: {2}}}", buf.EventType, symbolStr, buf.Size);
            var count = 0;

            foreach (var o in buf)
            {
                Console.WriteLine("   {{ {0} }}", o);
                if (++count < recordsPrintLimit || recordsPrintLimit == 0)
                {
                    continue;
                }

                Console.WriteLine("   {{ ... {0} records left ...}}", buf.Size - count);

                break;
            }
        }
Exemple #6
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);
                }
            }
        }
Exemple #7
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}")); });
                }
            }
        }
Exemple #8
0
 /// <summary>
 ///     Set multiply symbols to subscription.
 /// </summary>
 /// <param name="symbols">List of symbols.</param>
 /// <exception cref="ArgumentException">Invalid <paramref name="symbols"/> parameter.</exception>
 /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
 /// <exception cref="DxException">Internal error.</exception>
 public void SetSymbols(params string[] symbols)
 {
     if (symbols == null || symbols.Length == 0)
     {
         throw new ArgumentException("Invalid symbol parameter");
     }
     if (eventType.HasFlag(EventType.Candle) && HasCandleSymbol(symbols))
     {
         Clear();
         foreach (var s in symbols)
         {
             if (IsCandleSymbol(s))
             {
                 AddSymbol(CandleSymbol.ValueOf(s));
             }
             else
             {
                 AddSymbol(s);
             }
         }
     }
     else
     {
         C.CheckOk(C.Instance.dxf_set_symbols(subscriptionPtr, symbols, symbols.Length));
     }
 }
Exemple #9
0
        /// <summary>
        /// Creates Candle events via all parameters.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="time"></param>
        /// <param name="sequence"></param>
        /// <param name="count"></param>
        /// <param name="open"></param>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="close"></param>
        /// <param name="volume"></param>
        /// <param name="vwap"></param>
        /// <param name="bidVolume"></param>
        /// <param name="askVolume"></param>
        /// <param name="index"></param>
        /// <param name="openInterest"></param>
        /// <param name="impVolatility"></param>
        /// <param name="eventFlags"></param>
        internal PlayedCandle(string symbol, long time, int sequence, double count, double open,
                              double high, double low, double close, double volume, double vwap, double bidVolume,
                              double askVolume, long index, long openInterest, double impVolatility,
                              EventFlag eventFlags)
        {
            EventSymbol = CandleSymbol.ValueOf(symbol);
            EventFlags  = eventFlags;

            TimeStamp     = time;
            Time          = Tools.UnixTimeToDate(time);
            Sequence      = sequence;
            Count         = count;
            Open          = open;
            High          = high;
            Low           = low;
            Close         = close;
            Volume        = volume;
            VWAP          = vwap;
            BidVolume     = bidVolume;
            AskVolume     = askVolume;
            DateTime      = Tools.UnixTimeToDate(time);
            Index         = index;
            ImpVolatility = impVolatility;
            OpenInterest  = openInterest;

            Params = new EventParams(EventFlags, ((ulong)time << 32) + (uint)sequence, 0);
            Data   = new DxTestCandle(eventFlags, index, time, sequence, count, open, high, low, close, volume, vwap, bidVolume, askVolume, (int)openInterest, impVolatility);
        }
        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);
                }
            }
        }
Exemple #11
0
        /// <summary>
        ///     Creates Candle event from another object.
        /// </summary>
        /// <param name="candle">Other Candle object.</param>
        internal PlayedCandle(IDxCandle candle)
        {
            EventSymbol = CandleSymbol.ValueOf(candle.EventSymbol.ToString());
            EventFlags  = candle.EventFlags;

            TimeStamp     = candle.TimeStamp;
            Time          = Tools.UnixTimeToDate(TimeStamp);
            Sequence      = candle.Sequence;
            Count         = candle.Count;
            Open          = candle.Open;
            High          = candle.High;
            Low           = candle.Low;
            Close         = candle.Close;
            Volume        = candle.Volume;
            VWAP          = candle.VWAP;
            BidVolume     = candle.BidVolume;
            AskVolume     = candle.AskVolume;
            DateTime      = Tools.UnixTimeToDate(TimeStamp);
            Index         = candle.Index;
            ImpVolatility = candle.ImpVolatility;
            OpenInterest  = candle.OpenInterest;

            Params = new EventParams(EventFlags, ((ulong)TimeStamp << 32) + (uint)Sequence, 0);
            Data   = new DxTestCandle(EventFlags, Index, Tools.DateToUnixTime(Time), Sequence, Count, Open, High, Low, Close, Volume, VWAP, BidVolume, AskVolume, (int)OpenInterest, ImpVolatility);
        }
        public void CandleSymbolAlignmentTest(string symbolString, int expectedId)
        {
            var symbol = CandleSymbol.ValueOf(symbolString);

            Assert.AreEqual(symbolString, symbol.ToString());
            Assert.AreEqual(expectedId, symbol.AlignmentId);
        }
        public void CandleSymbolPriceLevelTest(string symbolString, double expectedPriceLevel)
        {
            var symbol = CandleSymbol.ValueOf(symbolString);

            Assert.AreEqual(symbolString, symbol.ToString());
            Assert.AreEqual(expectedPriceLevel, symbol.PriceLevel, Delta);
        }
        public void CandleSymbolPeriodTest(string symbolString, double expectedValue,
                                           CandleType expectedType)
        {
            var symbol = CandleSymbol.ValueOf(symbolString);

            Assert.AreEqual(symbolString, symbol.ToString());
            Assert.AreEqual(expectedValue, symbol.PeriodValue, Delta);
            Assert.AreEqual(expectedType.Id, symbol.PeriodId);
        }
        /// <summary>
        ///     Adds a symbol to the subscription.
        /// </summary>
        /// <remarks>
        ///     Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="symbol">Symbol.</param>
        /// <exception cref="ArgumentException">Invalid <paramref name="symbol"/> parameter.</exception>
        /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
        /// <exception cref="DxException">Internal error.</exception>
        public void AddSymbol(string symbol)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("Invalid symbol parameter");
            }
            if (snapshotPtr != InvalidSnapshot)
            {
                throw new InvalidOperationException("It is allowed to add only one symbol to snapshot subscription");
            }

            if ((eventType == EventType.Candle) ||
                (eventType == EventType.None) && NativeSubscription.IsCandleSymbol(symbol))
            {
                AddSymbol(CandleSymbol.ValueOf(symbol));
                return;
            }


            byte[] sourceBytes = null;
            if (source != string.Empty)
            {
                var ascii = Encoding.ASCII;
                sourceBytes = ascii.GetBytes(source);
            }

            if (eventType == EventType.None)
            {
                eventType = EventType.Order;
                C.CheckOk(C.Instance.dxf_create_order_snapshot(connectionPtr, symbol, sourceBytes, time, out snapshotPtr));
            }
            else
            {
                C.CheckOk(C.Instance.dxf_create_snapshot(connectionPtr, EventTypeUtil.GetEventId(eventType), symbol, sourceBytes, time, out snapshotPtr));
            }

            try
            {
                if (listener is IDxIncOrderSnapshotListener)
                {
                    C.CheckOk(C.Instance.dxf_attach_snapshot_inc_listener(snapshotPtr, incCallback = OnIncOrderSnapshot, IntPtr.Zero));
                }
                else
                {
                    C.CheckOk(C.Instance.dxf_attach_snapshot_listener(snapshotPtr, callback = OnEvent, IntPtr.Zero));
                }
            }
            catch (DxException)
            {
                Dispose();
                throw;
            }
        }
Exemple #16
0
 /// <summary>
 ///     <para>
 ///         Add symbol to subscription.
 ///     </para>
 ///     <para>
 ///         A wildcard symbol "*" will replace all symbols: there will be an unsubscription from messages on all current symbols
 ///         and a subscription to "*". The subscription type will be changed to STREAM
 ///         If there is already a subscription to "*", then nothing will happen
 ///     </para>
 /// </summary>
 /// <param name="symbol">Symbol.</param>
 /// <exception cref="ArgumentException">Invalid <paramref name="symbol"/> parameter.</exception>
 /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
 /// <exception cref="DxException">Internal error.</exception>
 public void AddSymbol(string symbol)
 {
     if (string.IsNullOrWhiteSpace(symbol))
     {
         throw new ArgumentException("Invalid symbol parameter.");
     }
     if (eventType.HasFlag(EventType.Candle) && IsCandleSymbol(symbol))
     {
         AddSymbol(CandleSymbol.ValueOf(symbol));
     }
     C.CheckOk(C.Instance.dxf_add_symbol(subscriptionPtr, symbol));
 }
        /// <summary>
        ///     Add candle symbol to subscription.
        /// </summary>
        /// <param name="symbol"><see cref="CandleSymbol"/>.</param>
        /// <exception cref="ArgumentException">Invalid <paramref name="symbol"/> parameter.</exception>
        /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
        /// <exception cref="DxException">Internal error.</exception>
        public void AddSymbol(CandleSymbol symbol)
        {
            if (snapshotPtr != InvalidSnapshot)
            {
                throw new InvalidOperationException("It is allowed to add only one symbol to snapshot subscription");
            }
            if (symbol == null)
            {
                throw new ArgumentException("Invalid symbol parameter");
            }
            if (eventType != EventType.None && eventType != EventType.Candle)
            {
                throw new InvalidOperationException("It is allowed only for Candle subscription");
            }

            IntPtr candleAttributesPtr = IntPtr.Zero;

            try
            {
                C.CheckOk(C.Instance.dxf_create_candle_symbol_attributes(symbol.BaseSymbol,
                                                                         symbol.ExchangeCode, symbol.PeriodValue, symbol.PeriodId, symbol.PriceId,
                                                                         symbol.SessionId, symbol.AlignmentId, symbol.PriceLevel, out candleAttributesPtr));
            }
            catch (DxException)
            {
                throw;
            }

            try
            {
                C.CheckOk(C.Instance.dxf_create_candle_snapshot(connectionPtr, candleAttributesPtr, time, out snapshotPtr));
            }
            finally
            {
                C.CheckOk(C.Instance.dxf_delete_candle_symbol_attributes(candleAttributesPtr));
            }

            try
            {
                C.CheckOk(C.Instance.dxf_attach_snapshot_listener(snapshotPtr, callback = OnEvent, IntPtr.Zero));
            }
            catch (DxException)
            {
                Dispose();
                throw;
            }

            eventType = EventType.Candle;
        }
Exemple #18
0
        public void RemoveSymbolsTest()
        {
            object[] symbolsSet = new object[] { "IBM", CandleSymbol.ValueOf("AAPL{=d}"), "C", "XBT/USD" };
            isFiresOnSymbolsRemoved = false;
            var s = DXEndpoint.Create().Feed.CreateSubscription <IDxOrder>();

            s.OnSymbolsRemoved += OnSymbolsRemoved;
            s.AddSymbols(symbolsSet);

            s.RemoveSymbols(null);
            s.RemoveSymbols(new List <object>());
            s.RemoveSymbols(new object[] { });
            Assert.Catch(typeof(ArgumentNullException), () =>
            {
                s.RemoveSymbols(new List <object>(new object[] { null }));
            });

            ICollection <object> removeCollection = new List <object>(
                new object[] { CandleSymbol.ValueOf("AAPL{=d}"), "C", "XBT/USD" }
                );

            s.RemoveSymbols(removeCollection);
            Assert.True(isFiresOnSymbolsRemoved);
            Assert.AreEqual(1, s.GetSymbols().Count);
            Assert.True(s.GetSymbols().SetEquals(new object[] { "IBM" }));
            isFiresOnSymbolsRemoved = false;
            s.RemoveSymbols("IBM");
            Assert.True(isFiresOnSymbolsRemoved);
            Assert.AreEqual(0, s.GetSymbols().Count);

            var totalSymbolsCount = 0;

            foreach (var set in SimulatedSymbolsSet)
            {
                s.AddSymbols(set);
                totalSymbolsCount += set.Length;
            }
            Assert.AreEqual(totalSymbolsCount, s.GetSymbols().Count);
            Parallel.For(ParallelFrom, ParallelTo, i =>
            {
                Assert.DoesNotThrow(() =>
                {
                    s.RemoveSymbols(SimulatedSymbolsSet[i % SimulatedSymbolsSet.Length]);
                });
            });
            Assert.AreEqual(0, s.GetSymbols().Count);
        }
        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);
                }
            }
        }
Exemple #20
0
        public void AddSymbolsTest()
        {
            object[] symbolsSet1      = new object[] { "IBM", CandleSymbol.ValueOf("AAPL{=d}"), "C" };
            object[] symbolsSetString = new object[] { "IBM", "AAPL{=d}", "C" };
            object   symbolSet2       = "XBT/USD";

            isFiresOnSymbolsAdded = false;
            var s = DXEndpoint.Create().Feed.CreateSubscription <IDxOrder>();

            s.OnSymbolsAdded += OnSymbolsAdded;

            s.AddSymbols(null);
            s.AddSymbols(new List <object>());
            s.AddSymbols(new object[] { });
            Assert.Catch(typeof(ArgumentNullException), () =>
            {
                s.AddSymbols(new List <object>(new object[] { null }));
            });

            s.AddSymbols(symbolsSet1);
            Assert.True(isFiresOnSymbolsAdded);
            Assert.AreEqual(symbolsSetString.Length, s.GetSymbols().Count);
            Assert.True(s.GetSymbols().SetEquals(symbolsSetString));

            isFiresOnSymbolsAdded = false;
            object[] newSymbolSet = symbolsSetString.Concat(new object[] { symbolSet2 }).ToArray();
            s.AddSymbols(symbolSet2);
            Assert.True(isFiresOnSymbolsAdded);
            Assert.AreEqual(newSymbolSet.Length, s.GetSymbols().Count);
            Assert.True(s.GetSymbols().SetEquals(newSymbolSet));

            Parallel.For(ParallelFrom, ParallelTo, i =>
            {
                Assert.DoesNotThrow(() =>
                {
                    s.AddSymbols(SimulatedSymbolsSet[i % SimulatedSymbolsSet.Length]);
                });
            });
            foreach (var set in SimulatedSymbolsSet)
            {
                newSymbolSet = newSymbolSet.Concat(set).ToArray();
            }
            Assert.AreEqual(newSymbolSet.Length, s.GetSymbols().Count);
            Assert.True(s.GetSymbols().SetEquals(newSymbolSet));
        }
        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]);
                }
            }
        }
Exemple #22
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);
                }
            }
        }
Exemple #23
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 CandleSymbolParamsTest(CandleSymbolTestCase testCase)
 {
     if (testCase.attrs == null)
     {
         Assert.AreEqual(testCase.expected, CandleSymbol.ValueOf(testCase.baseSymbol).ToString());
     }
     else if (testCase.attrs.Length == 1)
     {
         Assert.AreEqual(testCase.expected,
                         CandleSymbol.ValueOf(testCase.baseSymbol, testCase.attrs[0]).ToString());
     }
     else
     {
         var nextAttrs = new ICandleSymbolAttribute[testCase.attrs.Length - 1];
         Array.Copy(testCase.attrs, 1, nextAttrs, 0, testCase.attrs.Length - 1);
         Assert.AreEqual(testCase.expected,
                         CandleSymbol.ValueOf(testCase.baseSymbol, testCase.attrs[0], nextAttrs).ToString());
     }
 }
Exemple #25
0
        /// <summary>
        ///     Add candle symbol to subscription.
        /// </summary>
        /// <param name="symbol"><see cref="CandleSymbol"/>.</param>
        /// <exception cref="ArgumentException">Invalid <paramref name="symbol"/> parameter.</exception>
        /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
        /// <exception cref="DxException">Internal error.</exception>
        public void AddSymbol(CandleSymbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentException("Invalid symbol parameter.");
            }
            IntPtr candleAttributesPtr = IntPtr.Zero;

            C.CheckOk(C.Instance.dxf_create_candle_symbol_attributes(symbol.BaseSymbol,
                                                                     symbol.ExchangeCode, symbol.PeriodValue, symbol.PeriodId, symbol.PriceId,
                                                                     symbol.SessionId, symbol.AlignmentId, symbol.PriceLevel, out candleAttributesPtr));
            try
            {
                C.CheckOk(C.Instance.dxf_add_candle_symbol(subscriptionPtr, candleAttributesPtr));
            }
            finally
            {
                C.CheckOk(C.Instance.dxf_delete_candle_symbol_attributes(candleAttributesPtr));
            }
        }
Exemple #26
0
        internal NativeCandle(IDxCandle candle)
        {
            EventSymbol = CandleSymbol.ValueOf(candle.EventSymbol.ToString());

            EventFlags    = candle.EventFlags;
            Index         = candle.Index;
            Time          = TimeConverter.ToUtcDateTime(TimeStamp);
            Sequence      = candle.Sequence;
            Count         = candle.Count;
            Open          = candle.Open;
            High          = candle.High;
            Low           = candle.Low;
            Close         = candle.Close;
            Volume        = candle.Volume;
            VWAP          = candle.VWAP;
            BidVolume     = candle.BidVolume;
            AskVolume     = candle.AskVolume;
            OpenInterest  = candle.OpenInterest;
            ImpVolatility = candle.ImpVolatility;
        }
        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);
                }
            }
        }
Exemple #28
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>());
                }
            }
        }
Exemple #29
0
        internal unsafe NativeCandle(DxCandle *c, string symbol)
        {
            DxCandle candle = *c;

            EventSymbol = CandleSymbol.ValueOf(symbol);

            EventFlags    = candle.event_flags;
            Index         = candle.index;
            Time          = TimeConverter.ToUtcDateTime(candle.time);
            Sequence      = candle.sequence;
            Count         = candle.count;
            Open          = candle.open;
            High          = candle.high;
            Low           = candle.low;
            Close         = candle.close;
            Volume        = candle.volume;
            VWAP          = candle.vwap;
            BidVolume     = candle.bid_volume;
            AskVolume     = candle.ask_volume;
            OpenInterest  = candle.open_interest;
            ImpVolatility = candle.imp_volatility;
        }
Exemple #30
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>());
                }
            }
        }