public void TestSetSymbols() { 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.SetSymbols("XBT/USD"); listener.ClearEvents <IDxOrder>(); Thread.Sleep(10000); listener.WaitEvents <IDxOrder>("XBT/USD"); Assert.GreaterOrEqual(listener.GetEventCount <IDxOrder>("XBT/USD"), 1); Assert.AreEqual(0, listener.GetEventCount <IDxOrder>("AAPL", "IBM")); // add another symbols s.AddSymbols("AAPL", "IBM"); listener.WaitEvents <IDxOrder>("XBT/USD", "AAPL", "IBM"); } } }
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); } } }
public void TestSetSymbols() { SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected); string source = "NTV"; string symbol = "AAPL"; string otherSymbol = "IBM"; using (var con = new NativeConnection(address, OnDisconnect)) { Interlocked.Exchange(ref isConnected, 1); using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener)) { Assert.Throws <ArgumentException>(delegate { s.SetSymbols((string[])null); }); Assert.Throws <InvalidOperationException>(delegate { s.SetSymbols(new string[] { }); }); Assert.Throws <ArgumentException>(delegate { s.SetSymbols(new string[] { string.Empty }); }); Assert.Throws <InvalidOperationException>(delegate { s.SetSymbols(new string[] { "AAPL", "XBT/USD" }); }); s.AddSource(source); s.SetSymbols(new string[] { symbol }); listener.WaitSnapshot <IDxOrder>(symbol, source); s.SetSymbols(new string[] { otherSymbol }); listener.ClearEvents <IDxOrder>(); Thread.Sleep(10000); listener.WaitSnapshot <IDxOrder>(otherSymbol, source); Assert.AreEqual(1, listener.GetSnapshotsCount <IDxOrder>(otherSymbol)); Assert.AreEqual(0, listener.GetSnapshotsCount <IDxOrder>(symbol)); // add another symbols Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); }); Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); }); } } }
public void TestSetSymbolsCandle() { SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected); string candleString = "XBT/USD{=d}"; string otherCandleString = "XBT/USD{=2d}"; 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.SetSymbols(new CandleSymbol[] { CandleSymbol.ValueOf(candleString) }); listener.WaitSnapshot <IDxCandle>(candleString); s.SetSymbols(new CandleSymbol[] { CandleSymbol.ValueOf(otherCandleString) }); listener.ClearEvents <IDxCandle>(); Thread.Sleep(10000); listener.WaitSnapshot <IDxCandle>(otherCandleString); Assert.AreEqual(1, listener.GetSnapshotsCount <IDxCandle>(otherCandleString)); Assert.AreEqual(0, listener.GetSnapshotsCount <IDxCandle>(candleString)); // add another symbols Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols("IBM"); }); Assert.Throws(typeof(InvalidOperationException), delegate { s.AddSymbols(CandleSymbol.ValueOf("AAPL{=d,price=mark}")); }); } } }
/// <inheritdoc /> public void SetSymbols(params string[] symbols) { if (subscription == null) { throw new InvalidOperationException(AddSymbolBeforeSourceErrorText); } subscription.SetSymbols(symbols); this.symbols.Clear(); snapshots.Clear(); symbolSourceToKey.Clear(); receivedSnapshots.Clear(); foreach (var symbol in symbols) { var upperSymbol = symbol.ToUpper(); this.symbols.Add(upperSymbol); receivedSnapshots.Add(upperSymbol, new HashSet <IndexedEventSource>()); } orderViewStates.Clear(); }
public void TestSetSymbols() { 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 set other non-candle symbols s.SetSymbols("AAPL", "IBM"); returnedSymbolList = s.GetSymbols(); Assert.AreEqual(1, returnedSymbolList.Count); Assert.AreEqual(candleSymbolString, returnedSymbolList[0]); } } }