Beispiel #1
0
        private static void LoadSettings(string testScriptFile)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.dev.json", true, true)
                         .AddEnvironmentVariables()
                         .Build();

            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            // If it's Development environment load local settings file, else load settings from Lykke.Settings
            var mtSettings = (env == "Development") ?
                             config.Get <TradingBotSettings>() :
                             Lykke.SettingsReader.SettingsProcessor.Process <TradingBotSettings>(config["SettingsUrl"].GetStringAsync().Result);

            _settings = mtSettings.MtTradingBot;

            string script;

            if (!string.IsNullOrEmpty(_settings.TestFile))
            {
                script = _settings.TestFile;
            }
            else if (!string.IsNullOrEmpty(testScriptFile))
            {
                script = testScriptFile;
            }
            else
            {
                throw new Exception("Invalid configuration file");
            }

            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), script));

            if (!testFile.Exists)
            {
                throw new FileNotFoundException($"Script file not found: {testFile.Name}");
            }

            config = new ConfigurationBuilder()
                     .SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile("appsettings.dev.json", true, true)
                     .AddJsonFile(script, true, true)
                     .AddEnvironmentVariables()
                     .Build();

            _testSettings = config.Get <MtTradingBotTestSettings>();

            if (string.IsNullOrEmpty(_settings?.MTAuthorizationAddress) || string.IsNullOrEmpty(_settings.MTServerAddress))
            {
                throw new Exception("Invalid configuration file");
            }
            LogInfo("LoadSettings", $"Configuration Loaded: {script}");
        }
Beispiel #2
0
        public void Start(MtTradingBotSettings settings, MtTradingBotTestSettings testSettings)
        {
            _settings     = settings;
            _testSettings = testSettings;

            // Create Bots
            try { CreateBots(); }
            catch (Exception ex01)
            {
                LogError("CreateEnvironment", ex01);
                throw;
            }

            // Initialize Bots
            Task.Run(async() => await StartBots())
            .Wait();
        }