public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool shouldBeEmpty, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var brokerage = (BitfinexBrokerage)Brokerage;

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false, new DataPermissionManager()));

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest(now.Add(-period),
                                       now,
                                       typeof(TradeBar),
                                       symbol,
                                       resolution,
                                       SecurityExchangeHours.AlwaysOpen(TimeZones.Utc),
                                       DateTimeZone.Utc,
                                       Resolution.Minute,
                                       false,
                                       false,
                                       DataNormalizationMode.Adjusted,
                                       TickType.Trade)
                };

                // 'GetBrokerageSymbol' method called inside 'GetHistory' may throw an ArgumentException for invalid symbol supplied
                var history = historyProvider.GetHistory(requests, TimeZones.Utc).ToList();

                foreach (var slice in history)
                {
                    var bar = slice.Bars[symbol];
                    Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);

                if (shouldBeEmpty)
                {
                    Assert.IsTrue(history.Count == 0);
                }
                else
                {
                    Assert.IsTrue(history.Count > 0);
                }
            };

            // assert for ArgumentException
            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }
        public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var brokerage = (BitfinexBrokerage)Brokerage;

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(null, null, null, null, null, null);

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest(now.Add(-period),
                                       now,
                                       typeof(TradeBar),
                                       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)
                    {
                        foreach (var tick in slice.Ticks[symbol])
                        {
                            Log.Trace("{0}: {1} - {2} / {3}", tick.Time.ToString("yyyy-MM-dd HH:mm:ss.fff"), tick.Symbol, tick.BidPrice, tick.AskPrice);
                        }
                    }
                    else
                    {
                        var bar = slice.Bars[symbol];

                        Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
            };

            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }
        public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var environment = Config.Get("oanda-environment").ConvertTo <Environment>();
                var accessToken = Config.Get("oanda-access-token");
                var accountId   = Config.Get("oanda-account-id");

                var brokerage = new OandaBrokerage(null, null, environment, accessToken, accountId);

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(null, null, null, null, null, null);

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest
                    {
                        Symbol       = symbol,
                        Resolution   = resolution,
                        StartTimeUtc = now.Add(-period),
                        EndTimeUtc   = now
                    }
                };

                var history = historyProvider.GetHistory(requests, TimeZones.Utc);

                foreach (var slice in history)
                {
                    if (resolution == Resolution.Tick)
                    {
                        foreach (var tick in slice.Ticks[symbol])
                        {
                            Log.Trace("{0}: {1} - {2} / {3}", tick.Time, tick.Symbol, tick.BidPrice, tick.AskPrice);
                        }
                    }
                    else
                    {
                        var bar = slice.QuoteBars[symbol];

                        Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
            };

            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }
        public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var brokerage = (FxcmBrokerage)Brokerage;

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(null, null, null, null, null, null);

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest
                    {
                        Symbol       = symbol,
                        Resolution   = resolution,
                        StartTimeUtc = now.Add(-period),
                        EndTimeUtc   = now
                    }
                };

                var history = historyProvider.GetHistory(requests, TimeZones.Utc);

                foreach (var slice in history)
                {
                    if (resolution == Resolution.Tick)
                    {
                        foreach (var tick in slice.Ticks[symbol])
                        {
                            Log.Trace("{0}: {1} - {2} / {3}", tick.Time.ToString("yyyy-MM-dd HH:mm:ss.fff"), tick.Symbol, tick.BidPrice, tick.AskPrice);
                        }
                    }
                    else
                    {
                        var bar = slice.Bars[symbol];

                        Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
            };

            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }
Example #5
0
        public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType, TimeSpan period, bool shouldBeEmpty)
        {
            var restClient      = new RestClient("https://api.pro.coinbase.com");
            var webSocketClient = new WebSocketClientWrapper();
            var aggregator      = new AggregationManager();

            var brokerage = new GDAXBrokerage(
                Config.Get("gdax-url", "wss://ws-feed.pro.coinbase.com"), webSocketClient, restClient,
                Config.Get("gdax-api-key"), Config.Get("gdax-api-secret"), Config.Get("gdax-passphrase"), null, null, aggregator, null);

            var historyProvider = new BrokerageHistoryProvider();

            historyProvider.SetBrokerage(brokerage);
            historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false, new DataPermissionManager()));

            var now = DateTime.UtcNow;

            var requests = new[]
            {
                new HistoryRequest(now.Add(-period),
                                   now,
                                   typeof(TradeBar),
                                   symbol,
                                   resolution,
                                   SecurityExchangeHours.AlwaysOpen(TimeZones.Utc),
                                   DateTimeZone.Utc,
                                   resolution,
                                   false,
                                   false,
                                   DataNormalizationMode.Adjusted,
                                   tickType)
            };

            var history = historyProvider.GetHistory(requests, TimeZones.Utc).ToList();

            foreach (var slice in history)
            {
                var bar = slice.Bars[symbol];

                Log.Trace($"{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);
            }

            Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
        }
Example #6
0
        public void GetsFullDayTickHistory()
        {
            var symbol = Symbols.EURUSD;
            const Resolution resolution = Resolution.Tick;

            var startDate = new DateTime(2016, 11, 1);
            var endDate   = startDate.AddDays(1);

            var brokerage = (FxcmBrokerage)Brokerage;

            var historyProvider = new BrokerageHistoryProvider();

            historyProvider.SetBrokerage(brokerage);
            historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false));

            var stopwatch = Stopwatch.StartNew();

            var requests = new[]
            {
                new HistoryRequest(startDate,
                                   endDate,
                                   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);
            var tickCount = history.SelectMany(slice => slice.Ticks[symbol]).Count();

            stopwatch.Stop();
            Log.Trace("Download time: " + stopwatch.Elapsed);

            Log.Trace("History ticks returned: " + tickCount);
            Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);

            Assert.AreEqual(tickCount, historyProvider.DataPointCount);
            Assert.AreEqual(241233, tickCount);
        }
        public void GetsFullDayTickHistory()
        {
            var symbol = Symbols.EURUSD;
            const Resolution resolution = Resolution.Tick;

            var startDate = new DateTime(2016, 11, 1);
            var endDate   = startDate.AddDays(1);

            var brokerage = (FxcmBrokerage)Brokerage;

            var historyProvider = new BrokerageHistoryProvider();

            historyProvider.SetBrokerage(brokerage);
            historyProvider.Initialize(null, null, null, null, null, null);

            var stopwatch = Stopwatch.StartNew();

            var requests = new[]
            {
                new HistoryRequest
                {
                    Symbol       = symbol,
                    Resolution   = resolution,
                    StartTimeUtc = startDate,
                    EndTimeUtc   = endDate
                }
            };

            var history   = historyProvider.GetHistory(requests, TimeZones.Utc);
            var tickCount = history.SelectMany(slice => slice.Ticks[symbol]).Count();

            stopwatch.Stop();
            Log.Trace("Download time: " + stopwatch.Elapsed);

            Log.Trace("History ticks returned: " + tickCount);
            Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);

            Assert.AreEqual(tickCount, historyProvider.DataPointCount);
            Assert.AreEqual(241233, tickCount);
        }
Example #8
0
        public void GetEmptyHistory(Symbol symbol, Resolution resolution, TimeSpan period)
        {
            TestDelegate test = () =>
            {
                var brokerage = (BinanceBrokerage)Brokerage;

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(new HistoryProviderInitializeParameters(null, null, null, null, null, null, null, false, new DataPermissionManager()));

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest(now.Add(-period),
                                       now,
                                       typeof(TradeBar),
                                       symbol,
                                       resolution,
                                       SecurityExchangeHours.AlwaysOpen(TimeZones.Utc),
                                       DateTimeZone.Utc,
                                       Resolution.Minute,
                                       false,
                                       false,
                                       DataNormalizationMode.Adjusted,
                                       TickType.Quote)
                };

                var history = historyProvider.GetHistory(requests, TimeZones.Utc).ToList();

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
                Assert.AreEqual(0, historyProvider.DataPointCount);
            };

            Assert.DoesNotThrow(test);
        }
        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 GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var environment = Config.Get("oanda-environment").ConvertTo <Environment>();
                var accessToken = Config.Get("oanda-access-token");
                var accountId   = Config.Get("oanda-account-id");

                var brokerage = new OandaBrokerage(null, null, null, environment, accessToken, accountId);

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                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.EasternStandard),
                                       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)
                    {
                        foreach (var tick in slice.Ticks[symbol])
                        {
                            Log.Trace("{0}: {1} - {2} / {3}", tick.Time, tick.Symbol, tick.BidPrice, tick.AskPrice);
                        }
                    }
                    else
                    {
                        var bar = slice.QuoteBars[symbol];

                        Log.Trace("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
            };

            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }
        public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var keyId       = Config.Get("alpaca-key-id");
                var secretKey   = Config.Get("alpaca-secret-key");
                var tradingMode = Config.Get("alpaca-trading-mode");
                var brokerage   = new AlpacaBrokerage(null, null, keyId, secretKey, tradingMode);

                var historyProvider = new BrokerageHistoryProvider();
                historyProvider.SetBrokerage(brokerage);
                historyProvider.Initialize(null, null, null, null, null, null);

                var now = DateTime.UtcNow;

                var requests = new[]
                {
                    new HistoryRequest(now.Add(-period),
                                       now,
                                       typeof(TradeBar),
                                       symbol,
                                       resolution,
                                       SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork),
                                       DateTimeZone.Utc,
                                       Resolution.Daily,
                                       false,
                                       false,
                                       DataNormalizationMode.Adjusted,
                                       TickType.Trade)
                };

                var history = historyProvider.GetHistory(requests, TimeZones.Utc);

                foreach (var slice in history)
                {
                    if (resolution == Resolution.Tick)
                    {
                        foreach (var tick in slice.Ticks[symbol])
                        {
                            Console.WriteLine("{0}: {1} - {2} / {3}", tick.Time, tick.Symbol, tick.BidPrice, tick.AskPrice);
                        }
                    }
                    else if (resolution == Resolution.Second)
                    {
                        var bar = slice.QuoteBars[symbol];

                        Console.WriteLine("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                    else
                    {
                        var bar = slice.Bars[symbol];

                        Console.WriteLine("{0}: {1} - O={2}, H={3}, L={4}, C={5}", bar.Time, bar.Symbol, bar.Open, bar.High, bar.Low, bar.Close);
                    }
                }

                Log.Trace("Data points retrieved: " + historyProvider.DataPointCount);
            };

            if (throwsException)
            {
                Assert.Throws <ArgumentException>(test);
            }
            else
            {
                Assert.DoesNotThrow(test);
            }
        }