예제 #1
0
        /// <summary>
        /// Creates the brokerage under test
        /// </summary>
        /// <returns>A connected brokerage instance</returns>
        protected IBrokerage CreateBrokerage(IOrderProvider orderProvider, ISecurityProvider securityProvider)
        {
            var securities = new SecurityManager(new TimeKeeper(DateTime.UtcNow, TimeZones.Kolkata))
            {
                { Symbol, CreateSecurity(Symbol) }
            };

            var transactions = new SecurityTransactionManager(null, securities);

            transactions.SetOrderProcessor(new FakeOrderProcessor());

            var algorithm = new Mock <IAlgorithm>();

            algorithm.Setup(a => a.Transactions).Returns(transactions);
            algorithm.Setup(a => a.BrokerageModel).Returns(new ZerodhaBrokerageModel());
            algorithm.Setup(a => a.Portfolio).Returns(new SecurityPortfolioManager(securities, transactions));

            var accessToken    = Config.Get("zerodha-access-token");
            var apiKey         = Config.Get("zerodha-api-key");
            var tradingSegment = Config.Get("zerodha-trading-segment");
            var productType    = Config.Get("zerodha-product-type");
            var zerodha        = new ZerodhaBrokerage(tradingSegment, productType, apiKey, accessToken, algorithm.Object, algorithm.Object.Portfolio, new AggregationManager());

            return(zerodha);
        }
예제 #2
0
        public void GetsHistory(Symbol symbol, Resolution resolution, TimeSpan period, bool throwsException)
        {
            TestDelegate test = () =>
            {
                var accessToken    = Config.Get("zerodha-access-token");
                var apiKey         = Config.Get("zerodha-api-key");
                var tradingSegment = Config.Get("zerodha-trading-segment");
                var productType    = Config.Get("zerodha-product-type");
                var brokerage      = new ZerodhaBrokerage(tradingSegment, productType, apiKey, accessToken, null, null, null);

                var now = DateTime.UtcNow;

                var request = new HistoryRequest(now.Add(-period),
                                                 now,
                                                 typeof(QuoteBar),
                                                 symbol,
                                                 resolution,
                                                 SecurityExchangeHours.AlwaysOpen(TimeZones.Kolkata),
                                                 TimeZones.Kolkata,
                                                 Resolution.Minute,
                                                 false,
                                                 false,
                                                 DataNormalizationMode.Adjusted,
                                                 TickType.Quote)
                {
                };


                var history = brokerage.GetHistory(request);

                foreach (var slice in history)
                {
                    Log.Trace("{0}: {1} - {2} / {3}", slice.Time, slice.Symbol, slice.Price, slice.IsFillForward);
                }

                Log.Trace("Base currency: " + brokerage.AccountBaseCurrency);
            };

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