public void SeedsSecurityCorrectly() { var symbol = Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda); var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = new LiveNodePacket { UserId = 1, ProjectId = 1, DeployId = "1", Brokerage = "PaperBrokerage", DataQueueHandler = "none" }; // Increasing RAM limit, else the tests fail. This is happening in master, when running all the tests together, locally (not travis). job.Controls.RamAllocation = 1024 * 1024 * 1024; var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount>()); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding> { new Holding { Symbol = symbol, Type = symbol.SecurityType, Quantity = 100, MarketPrice = 99 } }); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(new SetupHandlerParameters(_dataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object))); Security security; Assert.IsTrue(algorithm.Portfolio.Securities.TryGetValue(symbol, out security)); Assert.AreEqual(symbol, security.Symbol); Assert.AreEqual(99, security.Price); var last = security.GetLastData(); Assert.IsTrue((DateTime.UtcNow.ConvertFromUtc(security.Exchange.TimeZone) - last.Time) < TimeSpan.FromSeconds(1)); }
public void Initialize() { _algorithm = new TestAlgorithm { HistoryProvider = new EmptyHistoryProvider() }; _algorithm.SetBrokerageModel(BrokerageName.FxcmBrokerage); _algorithm.SetCash(100000); _algorithm.AddSecurity(SecurityType.Forex, Ticker); _algorithm.SetFinishedWarmingUp(); }
public void LoadsHoldingsForExpectedMarket() { var symbol = Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda); var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = new LiveNodePacket { UserId = 1, ProjectId = 1, DeployId = "1", Brokerage = "PaperBrokerage", DataQueueHandler = "none" }; // Increasing RAM limit, else the tests fail. This is happening in master, when running all the tests together, locally (not travis). job.Controls.RamAllocation = 1024 * 1024 * 1024; var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <Cash>()); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding> { new Holding { Symbol = symbol, Type = symbol.SecurityType, Quantity = 100 } }); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object)); Security security; Assert.IsTrue(algorithm.Portfolio.Securities.TryGetValue(symbol, out security)); Assert.AreEqual(symbol, security.Symbol); }
public void SeedsSecurityCorrectly() { var symbol = Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda); var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = GetJob(); var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount>()); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding> { new Holding { Symbol = symbol, Quantity = 100, MarketPrice = 99 } }); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(new SetupHandlerParameters(_dataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object, TestGlobals.DataCacheProvider, TestGlobals.MapFileProvider))); Security security; Assert.IsTrue(algorithm.Portfolio.Securities.TryGetValue(symbol, out security)); Assert.AreEqual(symbol, security.Symbol); Assert.AreEqual(99, security.Price); var last = security.GetLastData(); Assert.IsTrue((DateTime.UtcNow.ConvertFromUtc(security.Exchange.TimeZone) - last.Time) < TimeSpan.FromSeconds(1)); }
public void SkipsLoadingHoldingsAndOrders() { var symbol = Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda); var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = GetJob(); job.BrokerageData["load-existing-holdings"] = "false"; var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount>()); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding> { new Holding { Symbol = symbol, Type = symbol.SecurityType, Quantity = 100 } }); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order> { new LimitOrder(Symbols.SPY, 1, 1, DateTime.UtcNow) }); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(new SetupHandlerParameters(_dataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object))); Security security; Assert.IsFalse(algorithm.Portfolio.Securities.TryGetValue(symbol, out security)); Assert.IsFalse(algorithm.Portfolio.Securities.TryGetValue(Symbols.SPY, out security)); }
public void LoadsHoldingsForExpectedMarket() { var symbol = Symbol.Create("AUDUSD", SecurityType.Forex, Market.Oanda); var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = GetJob(); var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount>()); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding> { new Holding { Symbol = symbol, Quantity = 100 } }); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(new SetupHandlerParameters(_dataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object, TestGlobals.DataProvider))); Security security; Assert.IsTrue(algorithm.Portfolio.Securities.TryGetValue(symbol, out security)); Assert.AreEqual(symbol, security.Symbol); }
public void EnforcesCashAmounts() { var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new BrokerageTransactionHandlerTests.BrokerageTransactionHandlerTests.EmptyHistoryProvider()); var job = GetJob(); job.BrokerageData["max-cash-limit"] = "[{\"amount\":20, \"currency\": \"USD\"}, {\"Amount\":1, \"Currency\": \"EUR\"}]"; var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount> { new CashAmount(10000, Currencies.USD), new CashAmount(11, Currencies.GBP) }); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding>()); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.IsTrue(setupHandler.Setup(new SetupHandlerParameters(_dataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object))); Assert.AreEqual(20, algorithm.Portfolio.CashBook[Currencies.USD].Amount); Assert.IsFalse(algorithm.Portfolio.CashBook.ContainsKey(Currencies.GBP)); Assert.IsFalse(algorithm.Portfolio.CashBook.ContainsKey(Currencies.EUR)); }
public void EnforcesTotalPortfolioValue(bool fails) { var algorithm = new TestAlgorithm(); algorithm.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage); algorithm.SetHistoryProvider(new TestHistoryProvider()); var job = GetJob(); job.BrokerageData[BrokerageSetupHandler.MaxAllocationLimitConfig] = fails ? "1" : "1000000000"; var resultHandler = new Mock <IResultHandler>(); var transactionHandler = new Mock <ITransactionHandler>(); var realTimeHandler = new Mock <IRealTimeHandler>(); var brokerage = new Mock <IBrokerage>(); var objectStore = new Mock <IObjectStore>(); brokerage.Setup(x => x.IsConnected).Returns(true); brokerage.Setup(x => x.AccountBaseCurrency).Returns(Currencies.USD); brokerage.Setup(x => x.GetCashBalance()).Returns(new List <CashAmount> { new CashAmount(10000, Currencies.USD), new CashAmount(11, Currencies.GBP) }); brokerage.Setup(x => x.GetAccountHoldings()).Returns(new List <Holding>()); brokerage.Setup(x => x.GetOpenOrders()).Returns(new List <Order>()); var setupHandler = new BrokerageSetupHandler(); IBrokerageFactory factory; setupHandler.CreateBrokerage(job, algorithm, out factory); Assert.AreEqual(!fails, setupHandler.Setup(new SetupHandlerParameters(algorithm.DataManager.UniverseSelection, algorithm, brokerage.Object, job, resultHandler.Object, transactionHandler.Object, realTimeHandler.Object, objectStore.Object, TestGlobals.DataCacheProvider, TestGlobals.MapFileProvider))); Assert.AreEqual(10000, algorithm.Portfolio.CashBook[Currencies.USD].Amount); Assert.AreEqual(11, algorithm.Portfolio.CashBook[Currencies.GBP].Amount); }