/// <summary> /// Runs the algorithm with the given settings and file /// </summary> /// <param name="settings">Settings for Lean</param> /// <param name="file">File to run</param> private void RunLiveAlgorithm(BaseLiveAlgorithmSettings settings, ProjectFile file) { // Create a new project var project = _api.CreateProject($"Test project - {DateTime.Now.ToStringInvariant()}", Language.CSharp); // Add Project Files var addProjectFile = _api.AddProjectFile(project.Projects.First().ProjectId, file.Name, file.Code); Assert.IsTrue(addProjectFile.Success); // Create compile var compile = _api.CreateCompile(project.Projects.First().ProjectId); Assert.IsTrue(compile.Success); // Wait at max 30 seconds for project to compile Compile compileCheck = WaitForCompilerResponse(project.Projects.First().ProjectId, compile.CompileId, 30); Assert.IsTrue(compileCheck.Success); Assert.IsTrue(compileCheck.State == CompileState.BuildSuccess); // Get a live node to launch the algorithm on var nodes = _api.ReadNodes(_testOrganization); Assert.IsTrue(nodes.Success); var freeNode = nodes.LiveNodes.Where(x => x.Busy == false); Assert.IsNotEmpty(freeNode, "No free Live Nodes found"); // Create live default algorithm var createLiveAlgorithm = _api.CreateLiveAlgorithm(project.Projects.First().ProjectId, compile.CompileId, freeNode.FirstOrDefault().Id, settings); Assert.IsTrue(createLiveAlgorithm.Success); if (stopLiveAlgos) { // Liquidate live algorithm; will also stop algorithm var liquidateLive = _api.LiquidateLiveAlgorithm(project.Projects.First().ProjectId); Assert.IsTrue(liquidateLive.Success); // Delete the project var deleteProject = _api.DeleteProject(project.Projects.First().ProjectId); Assert.IsTrue(deleteProject.Success); } }
public LiveAlgorithm CreateLiveAlgorithm(int projectId, string compileId, string serverType, BaseLiveAlgorithmSettings baseLiveAlgorithmSettings, string versionId = "-1") { throw new NotImplementedException(); }
public void LiveAlgorithmSettings_CanBeCreated_Successfully() { string user = ""; string password = ""; BrokerageEnvironment environment = BrokerageEnvironment.Paper; string account = ""; // Oanda Custom Variables string accessToken = ""; var dateIssuedString = "20160920"; // Tradier Custom Variables string dateIssued = ""; string refreshToken = ""; string lifetime = ""; // Create and test settings for each brokerage foreach (BrokerageName brokerageName in Enum.GetValues(typeof(BrokerageName))) { BaseLiveAlgorithmSettings settings = null; switch (brokerageName) { case BrokerageName.Default: user = Config.Get("default-username"); password = Config.Get("default-password"); settings = new DefaultLiveAlgorithmSettings(user, password, environment, account); Assert.IsTrue(settings.Id == BrokerageName.Default.ToString()); break; case BrokerageName.FxcmBrokerage: user = Config.Get("fxcm-user-name"); password = Config.Get("fxcm-password"); settings = new FXCMLiveAlgorithmSettings(user, password, environment, account); Assert.IsTrue(settings.Id == BrokerageName.FxcmBrokerage.ToString()); break; case BrokerageName.InteractiveBrokersBrokerage: user = Config.Get("ib-user-name"); password = Config.Get("ib-password"); account = Config.Get("ib-account"); settings = new InteractiveBrokersLiveAlgorithmSettings(user, password, account); Assert.IsTrue(settings.Id == BrokerageName.InteractiveBrokersBrokerage.ToString()); break; case BrokerageName.OandaBrokerage: accessToken = Config.Get("oanda-access-token"); account = Config.Get("oanda-account-id"); settings = new OandaLiveAlgorithmSettings(accessToken, environment, account); Assert.IsTrue(settings.Id == BrokerageName.OandaBrokerage.ToString()); break; case BrokerageName.TradierBrokerage: dateIssued = Config.Get("tradier-issued-at"); refreshToken = Config.Get("tradier-refresh-token"); account = Config.Get("tradier-account-id"); settings = new TradierLiveAlgorithmSettings(refreshToken, dateIssued, refreshToken, account); break; default: throw new Exception($"Settings have not been implemented for this brokerage: {brokerageName}"); } // Tests common to all brokerage configuration classes Assert.IsTrue(settings != null); Assert.IsTrue(settings.Password == password); Assert.IsTrue(settings.User == user); // tradier brokerage is always live, the rest are variable if (brokerageName != BrokerageName.TradierBrokerage) { Assert.IsTrue(settings.Environment == environment); } // Oanda specific settings if (brokerageName == BrokerageName.OandaBrokerage) { var oandaSetting = settings as OandaLiveAlgorithmSettings; Assert.IsTrue(oandaSetting.AccessToken == accessToken); } // Tradier specific settings if (brokerageName == BrokerageName.TradierBrokerage) { var tradierLiveAlogrithmSettings = settings as TradierLiveAlgorithmSettings; Assert.IsTrue(tradierLiveAlogrithmSettings.DateIssued == dateIssued); Assert.IsTrue(tradierLiveAlogrithmSettings.RefreshToken == refreshToken); Assert.IsTrue(settings.Environment == BrokerageEnvironment.Live); } // reset variables user = ""; password = ""; environment = BrokerageEnvironment.Paper; account = ""; } }
public void LiveAlgorithmSettings_CanBeCreated_Successfully() { string user = ""; string password = ""; BrokerageEnvironment environment = BrokerageEnvironment.Paper; string account = ""; string key = ""; string secretKey = ""; // Oanda Custom Variables string accessToken = ""; var dateIssuedString = "20160920"; // Tradier Custom Variables string dateIssued = ""; string refreshToken = ""; string lifetime = ""; // Create and test settings for each brokerage foreach (BrokerageName brokerageName in Enum.GetValues(typeof(BrokerageName))) { BaseLiveAlgorithmSettings settings = null; switch (brokerageName) { case BrokerageName.Default: user = Config.Get("default-username"); password = Config.Get("default-password"); settings = new DefaultLiveAlgorithmSettings(user, password, environment, account); Assert.IsTrue(settings.Id == BrokerageName.Default.ToString()); break; case BrokerageName.FxcmBrokerage: user = Config.Get("fxcm-user-name"); password = Config.Get("fxcm-password"); settings = new FXCMLiveAlgorithmSettings(user, password, environment, account); Assert.IsTrue(settings.Id == BrokerageName.FxcmBrokerage.ToString()); break; case BrokerageName.InteractiveBrokersBrokerage: user = Config.Get("ib-user-name"); password = Config.Get("ib-password"); account = Config.Get("ib-account"); settings = new InteractiveBrokersLiveAlgorithmSettings(user, password, account); Assert.IsTrue(settings.Id == BrokerageName.InteractiveBrokersBrokerage.ToString()); break; case BrokerageName.OandaBrokerage: accessToken = Config.Get("oanda-access-token"); account = Config.Get("oanda-account-id"); settings = new OandaLiveAlgorithmSettings(accessToken, environment, account); Assert.IsTrue(settings.Id == BrokerageName.OandaBrokerage.ToString()); break; case BrokerageName.TradierBrokerage: dateIssued = Config.Get("tradier-issued-at"); refreshToken = Config.Get("tradier-refresh-token"); account = Config.Get("tradier-account-id"); settings = new TradierLiveAlgorithmSettings(refreshToken, dateIssued, refreshToken, account); break; case BrokerageName.Bitfinex: key = Config.Get("bitfinex-api-key"); secretKey = Config.Get("bitfinex-api-secret"); settings = new BitfinexLiveAlgorithmSettings(key, secretKey); break; case BrokerageName.Alpaca: key = Config.Get("alpaca-key-id"); secretKey = Config.Get("alpaca-secret-key"); environment = Config.Get("alpaca-trading-mode").ToLowerInvariant().Equals("live") ? BrokerageEnvironment.Live : BrokerageEnvironment.Paper; settings = new AlpacaLiveAlgorithmSettings(key, secretKey, environment); break; case BrokerageName.GDAX: key = Config.Get("gdax-api-key"); secretKey = Config.Get("gdax-api-secret"); var passphrase = Config.Get("gdax-api-passphrase"); settings = new GDAXLiveAlgorithmSettings(key, secretKey, passphrase); break; case BrokerageName.AlphaStreams: // No live algorithm settings settings = new BaseLiveAlgorithmSettings(); break; case BrokerageName.Binance: // No live algorithm settings settings = new BaseLiveAlgorithmSettings(); break; default: throw new Exception($"Settings have not been implemented for this brokerage: {brokerageName}"); } // Tests common to all brokerage configuration classes Assert.IsTrue(settings != null); Assert.IsTrue(settings.Password == password); Assert.IsTrue(settings.User == user); // Oanda specific settings if (brokerageName == BrokerageName.OandaBrokerage) { var oandaSetting = settings as OandaLiveAlgorithmSettings; Assert.IsTrue(oandaSetting.AccessToken == accessToken); } // Tradier specific settings if (brokerageName == BrokerageName.TradierBrokerage) { var tradierLiveAlogrithmSettings = settings as TradierLiveAlgorithmSettings; Assert.IsTrue(tradierLiveAlogrithmSettings.DateIssued == dateIssued); Assert.IsTrue(tradierLiveAlogrithmSettings.RefreshToken == refreshToken); Assert.IsTrue(settings.Environment == BrokerageEnvironment.Live); } // reset variables user = ""; password = ""; environment = BrokerageEnvironment.Paper; account = ""; } }