public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool shouldBeEmpty) { Log.LogHandler = new ConsoleLogHandler(); var keyId = Config.Get("alpaca-key-id"); var secretKey = Config.Get("alpaca-secret-key"); var tradingMode = Config.Get("alpaca-trading-mode"); using (var brokerage = new AlpacaBrokerage(null, null, keyId, secretKey, tradingMode, true)) { var historyProvider = new BrokerageHistoryProvider(); historyProvider.SetBrokerage(brokerage); historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false)); var now = DateTime.UtcNow; var requests = new[] { new HistoryRequest( now.Add(-period), now, typeof(TradeBar), symbol, resolution, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), TimeZones.NewYork, null, false, false, DataNormalizationMode.Adjusted, TickType.Trade) }; var history = historyProvider.GetHistory(requests, TimeZones.NewYork).ToList(); foreach (var slice in history) { if (resolution == Resolution.Tick) { foreach (var tick in slice.Ticks[symbol]) { Console.WriteLine($"{tick.Time}: {tick.Symbol} - P={tick.Price}, Q={tick.Quantity}"); } } else { var bar = slice.Bars[symbol]; Console.WriteLine($"{bar.Time}: {bar.Symbol} - O={bar.Open}, H={bar.High}, L={bar.Low}, C={bar.Close}, V={bar.Volume}"); } } if (shouldBeEmpty) { Assert.IsTrue(history.Count == 0); } else { Assert.IsTrue(history.Count > 0); } brokerage.Disconnect(); Log.Trace("Data points retrieved: " + historyProvider.DataPointCount); } }
public void TearDown() { _brokerage.Disconnect(); _brokerage.Dispose(); }