public void IEXCouldSubscribeAndUnsubscribe() { // MBLY is the most liquid IEX instrument var iex = new IEXDataQueueHandler(); var unsubscribed = false; ProcessFeed(iex, tick => { Console.WriteLine(tick.ToString()); if (unsubscribed && tick.Symbol.Value == "MBLY") { Assert.Fail("Should not receive data for unsubscribed symbol"); } }); iex.Subscribe(null, new[] { Symbol.Create("MBLY", SecurityType.Equity, Market.USA), Symbol.Create("USO", SecurityType.Equity, Market.USA) }); Thread.Sleep(20000); iex.Unsubscribe(null, new[] { Symbol.Create("MBLY", SecurityType.Equity, Market.USA) }); Console.WriteLine("Unsubscribing"); Thread.Sleep(2000); // some messages could be inflight, but after a pause all MBLY messages must have beed consumed by ProcessFeed unsubscribed = true; Thread.Sleep(20000); iex.Dispose(); }
public void IEXCouldConnect() { var iex = new IEXDataQueueHandler(); Thread.Sleep(5000); Assert.IsTrue(iex.IsConnected); iex = null; GC.Collect(2, GCCollectionMode.Forced, true); Thread.Sleep(1000); // finalizer should print disconnected message }
public void IEXCouldGetHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool received, bool throwsException = false) { var historyProvider = new IEXDataQueueHandler(); historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false, null)); var now = DateTime.UtcNow; var requests = new[] { new HistoryRequest(now.Add(-period), now, typeof(QuoteBar), symbol, resolution, SecurityExchangeHours.AlwaysOpen(TimeZones.Utc), DateTimeZone.Utc, Resolution.Minute, false, false, DataNormalizationMode.Adjusted, TickType.Quote) }; var history = historyProvider.GetHistory(requests, TimeZones.Utc); foreach (var slice in history) { if (resolution == Resolution.Tick || resolution == Resolution.Second || resolution == Resolution.Hour) { Assert.IsNull(slice); } else if (resolution == Resolution.Daily || resolution == Resolution.Minute) { Assert.IsNotNull(slice); var bar = slice.Bars[symbol]; Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}: {6}, {7}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close, resolution, period); } } Log.Trace("Data points retrieved: " + historyProvider.DataPointCount); if (received) { Assert.IsTrue(historyProvider.DataPointCount > 0); } else { Assert.IsTrue(historyProvider.DataPointCount == 0); } }
public void IEXCouldSubscribeMoreThan100Symbols() { var configs = HardCodedSymbolsSNP.Select(s => GetSubscriptionDataConfig <TradeBar>(Symbol.Create(s, SecurityType.Equity, Market.USA), Resolution.Second)).ToArray(); using (var iex = new IEXDataQueueHandler()) { Array.ForEach(configs, dataConfig => iex.Subscribe(dataConfig, (s, e) => { })); Thread.Sleep(20000); Assert.IsTrue(iex.IsConnected); } }
public void IEXCouldSubscribeToAll() { var iex = new IEXDataQueueHandler(); ProcessFeed(iex, tick => Console.WriteLine(tick.ToString())); iex.Subscribe(null, new[] { Symbol.Create("firehose", SecurityType.Equity, Market.USA) }); Thread.Sleep(30000); iex.Dispose(); }
public void IEXCouldGetHistory(Symbol symbol, Resolution resolution, Type dataType, TimeSpan period, bool received, bool throwsException) { TestDelegate test = () => { var historyProvider = new IEXDataQueueHandler(); var now = DateTime.UtcNow; var requests = new[] { new HistoryRequest(now.Add(-period), now, dataType, symbol, resolution, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), TimeZones.NewYork, resolution, true, false, DataNormalizationMode.Raw, TickType.Trade) }; var slices = historyProvider.GetHistory(requests, TimeZones.Utc).ToArray(); Log.Trace("Data points retrieved: " + historyProvider.DataPointCount); if (received) { // Slices not empty Assert.IsNotEmpty(slices); // And are ordered by time Assert.That(slices, Is.Ordered.By("Time")); } else { Assert.IsEmpty(slices); } }; if (throwsException) { Assert.That(test, Throws.Exception); } else { Assert.DoesNotThrow(test); } }
public void IEXCouldSubscribeManyTimes() { var iex = new IEXDataQueueHandler(); ProcessFeed(iex, tick => Console.WriteLine(tick.ToString())); iex.Subscribe(null, new[] { Symbol.Create("MBLY", SecurityType.Equity, Market.USA), }); iex.Subscribe(null, new[] { Symbol.Create("FB", SecurityType.Equity, Market.USA), }); iex.Subscribe(null, new[] { Symbol.Create("AAPL", SecurityType.Equity, Market.USA), }); iex.Subscribe(null, new[] { Symbol.Create("USO", SecurityType.Equity, Market.USA), }); Thread.Sleep(10000); Console.WriteLine("Unsubscribing from all except MBLY"); iex.Unsubscribe(null, new[] { Symbol.Create("FB", SecurityType.Equity, Market.USA), }); iex.Unsubscribe(null, new[] { Symbol.Create("AAPL", SecurityType.Equity, Market.USA), }); iex.Unsubscribe(null, new[] { Symbol.Create("USO", SecurityType.Equity, Market.USA), }); Thread.Sleep(10000); iex.Dispose(); }
public void IEXCouldReconnect() { var iex = new IEXDataQueueHandler(); var realEndpoint = iex.Endpoint; Thread.Sleep(1000); iex.Dispose(); iex.Endpoint = "https://badd.address"; iex.Reconnect(); Thread.Sleep(1000); iex.Dispose(); iex.Endpoint = realEndpoint; iex.Reconnect(); Thread.Sleep(1000); Assert.IsTrue(iex.IsConnected); iex.Dispose(); }
public void IEXCouldSubscribeToAll() { var iex = new IEXDataQueueHandler(new AggregationManager()); ProcessFeed( iex.Subscribe(GetSubscriptionDataConfig <TradeBar>(Symbol.Create("firehose", SecurityType.Equity, Market.USA), Resolution.Second), (s, e) => { }), tick => { if (tick != null) { Console.WriteLine(tick.ToString()); } }); Thread.Sleep(30000); iex.Dispose(); }
public void IEXCouldSubscribe() { var iex = new IEXDataQueueHandler(); ProcessFeed(iex, tick => Console.WriteLine(tick.ToString())); iex.Subscribe(null, new[] { Symbol.Create("FB", SecurityType.Equity, Market.USA), Symbol.Create("AAPL", SecurityType.Equity, Market.USA), Symbol.Create("XIV", SecurityType.Equity, Market.USA), Symbol.Create("PTN", SecurityType.Equity, Market.USA), Symbol.Create("USO", SecurityType.Equity, Market.USA), }); Thread.Sleep(10000); iex.Dispose(); }
public void IEXCouldSubscribeAndUnsubscribe() { // MBLY is the most liquid IEX instrument var iex = new IEXDataQueueHandler(); var unsubscribed = false; Action <BaseData> callback = (tick) => { if (tick == null) { return; } Console.WriteLine(tick.ToString()); if (unsubscribed && tick.Symbol.Value == "MBLY") { Assert.Fail("Should not receive data for unsubscribed symbol"); } }; var configs = new[] { GetSubscriptionDataConfig <TradeBar>(Symbol.Create("MBLY", SecurityType.Equity, Market.USA), Resolution.Second), GetSubscriptionDataConfig <TradeBar>(Symbol.Create("USO", SecurityType.Equity, Market.USA), Resolution.Second) }; Array.ForEach(configs, (c) => { ProcessFeed( iex.Subscribe(c, (s, e) => { }), callback); }); Thread.Sleep(20000); iex.Unsubscribe(Enumerable.First(configs, c => string.Equals(c.Symbol.Value, "MBLY"))); Console.WriteLine("Unsubscribing"); Thread.Sleep(2000); // some messages could be inflight, but after a pause all MBLY messages must have beed consumed by ProcessFeed unsubscribed = true; Thread.Sleep(20000); iex.Dispose(); }
public void IEXCouldSubscribe() { var iex = new IEXDataQueueHandler(new AggregationManager()); Array.ForEach(new[] { "FB", "AAPL", "XIV", "PTN", "USO" }, (ticker) => { ProcessFeed( iex.Subscribe(GetSubscriptionDataConfig <TradeBar>(Symbol.Create(ticker, SecurityType.Equity, Market.USA), Resolution.Second), (sender, e) => { }), tick => { if (tick != null) { Console.WriteLine(tick.ToString()); } }); }); Thread.Sleep(10000); iex.Dispose(); }
public void IEXCouldSubscribeManyTimes() { var iex = new IEXDataQueueHandler(); var configs = new[] { GetSubscriptionDataConfig <TradeBar>(Symbol.Create("GOOG", SecurityType.Equity, Market.USA), Resolution.Second), GetSubscriptionDataConfig <TradeBar>(Symbol.Create("FB", SecurityType.Equity, Market.USA), Resolution.Second), GetSubscriptionDataConfig <TradeBar>(Symbol.Create("AAPL", SecurityType.Equity, Market.USA), Resolution.Second), GetSubscriptionDataConfig <TradeBar>(Symbol.Create("MSFT", SecurityType.Equity, Market.USA), Resolution.Second) }; Array.ForEach(configs, (c) => { ProcessFeed( iex.Subscribe(c, (s, e) => { }), tick => { if (tick != null) { Console.WriteLine(tick.ToString()); } }); }); Thread.Sleep(20000); Log.Trace("Unsubscribing from all except AAPL"); Array.ForEach(configs, (c) => { if (!string.Equals(c.Symbol.Value, "AAPL")) { iex.Unsubscribe(c); } }); Thread.Sleep(20000); iex.Dispose(); }
private void ProcessFeed(IEXDataQueueHandler iex, Action <BaseData> callback = null) { Task.Run(() => { foreach (var tick in iex.GetNextTicks()) { try { if (callback != null) { callback.Invoke(tick); } } catch (AssertionException) { throw; } catch (Exception err) { Console.WriteLine(err.Message); } } }); }