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); } } }
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 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 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); } } }
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 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); }); } } }
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); } } }
public void TestClearSymbols2() { SnapshotTestListener listener = new SnapshotTestListener(eventsTimeout, eventsSleepTime, IsConnected); string source = "NTV"; string symbol = "AAPL"; string candleString = "XBT/USD{=d}"; using (var con = new NativeConnection(address, OnDisconnect)) { Interlocked.Exchange(ref isConnected, 1); using (IDxSubscription s = con.CreateSnapshotSubscription(0, listener)) { s.AddSource(source); s.AddSymbol(symbol); listener.WaitSnapshot <IDxOrder>(symbol, source); s.Clear(); listener.ClearEvents <IDxOrder>(); Assert.AreEqual(0, s.GetSymbols().Count); Thread.Sleep(10000); Assert.AreEqual(0, listener.GetSnapshotsCount <IDxOrder>(symbol)); //add another symbol s.AddSymbols(CandleSymbol.ValueOf(candleString)); listener.WaitSnapshot <IDxCandle>(candleString); } } }
public void 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}")); }); } } }
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"); } } }
public SnapshotCollection(NativeConnection connection, IDxSnapshotListener listener, SnapshotCase[] snapshotCases) { this.snapshotCases = snapshotCases; foreach (SnapshotCase snapshot in this.snapshotCases) snapshot.Initialize(connection, listener); }
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); } } }
/// <summary> /// <para> /// Connects to the specified remove address. Previously established connections /// are closed if the new address is different from the old one. /// This method does nothing if address does not change or if this endpoint is /// <see cref="DXEndpointState.Closed"/>. /// The endpoint <see cref="State"/> immediately becomes /// <see cref="DXEndpointState.Connecting"/> otherwise. /// </para> /// <para> /// The address string is provided with the market data vendor agreement. /// Use "demo.dxfeed.com:7300" for a demo quote feed. /// </para> /// <list type="table"> /// <listheader> /// <description> /// The simplest address strings have the following format: /// </description> /// </listheader> /// <item> /// <description> /// <c>host:port</c> to establish a TCP/IP connection /// </description> /// </item> /// <item> /// <description> /// <c>:port</c> to listen for a TCP/IP connection with a plain socket /// connector (good for up to a few hundred of connections). /// </description> /// </item> /// </list> /// <para> /// For premium services access credentials must be configured before invocation of /// <c>Connect</c> method using <see cref="User(string)"/> and /// <see cref="Password(string)"/> methods. /// </para> /// </summary> /// <param name="address">The data source address.</param> /// <returns>This <see cref="DXEndpoint"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="address"/> is null.</exception> public IDXEndpoint Connect(string address) { if (string.IsNullOrWhiteSpace(address)) { throw new ArgumentNullException("The address is null!"); } if (this.address.Equals(address) && State != DXEndpointState.NotConnected || State == DXEndpointState.Closed) { return(this); } if (State == DXEndpointState.Connected || State == DXEndpointState.Connecting) { Disconnect(); } State = DXEndpointState.Connecting; lock (stateLocker) { this.address = address; connection = new NativeConnection(this.address, null); connection.OnCreation += ConnectionInstance_OnCreation; } return(this); }
private void UnsafeCloseConnection() { if (connection != null) { connection.OnCreation -= ConnectionInstance_OnCreation; connection.Disconnect(); connection = null; } }
/// <summary> /// Closes the connection to the database. /// </summary> public void Close() { if (NativeConnection == null) { return; } NativeConnection.Dispose(); NativeConnection = null; }
/// <summary> /// Changes database /// </summary> /// <param name="databaseName"></param> public void ChangeDatabase(string databaseName) { if (0 == NativeConnection.mysql_select_db(databaseName)) { this.Dbname = databaseName; } else { throw new MySqlException("MySQLDriverCS Error: change database failed, perhaps user is not authorized to access that database." + NativeConnection.mysql_error()); } }
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); } }
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 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); } } }
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]); } } }
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 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"); } } }
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); } } }
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>()); } } }
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>()); } } }
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"); } } }
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]); } } }
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); } } }