Example #1
0
        /// <summary>
        /// Main program for testing and/or standalone execution
        /// </summary>
        public static void Main(string[] args)
        {
            var json   = File.ReadAllText("config.json");
            var config = JObject.Parse(json);

            var ibDirectory = config["ib-tws-dir"].ToString();
            var userName    = config["ib-user-name"].ToString();
            var password    = config["ib-password"].ToString();
            var tradingMode = config["ib-trading-mode"].ToString();
            var portNumber  = config["ib-port"].ToObject <int>();
            var ibVersion   = "974";

            if (config["ib-version"] != null)
            {
                ibVersion = config["ib-version"].ToString();
            }

            var automater = new IBAutomater(ibDirectory, ibVersion, userName, password, tradingMode, portNumber);

            automater.OutputDataReceived += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} {e}");
            automater.ErrorDataReceived  += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} {e}");
            automater.Exited             += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} IBAutomater exited [{e}]");

            automater.Start(true);
        }
Example #2
0
        /// <summary>
        /// Main program for testing and/or standalone execution
        /// </summary>
        public static void Main(string[] args)
        {
            var json   = File.ReadAllText("config.json");
            var config = JObject.Parse(json);

            var ibDirectory = config["ib-tws-dir"].ToString();
            var userName    = config["ib-user-name"].ToString();
            var password    = config["ib-password"].ToString();
            var tradingMode = config["ib-trading-mode"].ToString();
            var portNumber  = config["ib-port"].ToObject <int>();
            var ibVersion   = "974";

            if (config["ib-version"] != null)
            {
                ibVersion = config["ib-version"].ToString();
            }
            var exportIbGatewayLogs = config["ib-export-ibgateway-logs"].ToObject <bool>();

            // Create a new instance of the IBAutomater class
            var automater = new IBAutomater(ibDirectory, ibVersion, userName, password, tradingMode, portNumber, exportIbGatewayLogs);

            // Attach the event handlers
            automater.OutputDataReceived += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} {e.Data}");
            automater.ErrorDataReceived  += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} {e.Data}");
            automater.Exited             += (s, e) => Console.WriteLine($"{DateTime.UtcNow:O} IBAutomater exited [ExitCode:{e.ExitCode}]");

            // Start the IBAutomater
            Console.WriteLine("===> Starting IBAutomater");
            var result = automater.Start(false);

            if (result.HasError)
            {
                Console.WriteLine($"Failed to start IBAutomater - Code: {result.ErrorCode}, Message: {result.ErrorMessage}");
                automater.Stop();
                return;
            }

            // Restart the IBAutomater
            Console.WriteLine("===> Restarting IBAutomater");
            result = automater.Restart();
            if (result.HasError)
            {
                Console.WriteLine($"Failed to restart IBAutomater - Code: {result.ErrorCode}, Message: {result.ErrorMessage}");
                automater.Stop();
                return;
            }

            // Stop the IBAutomater
            Console.WriteLine("===> Stopping IBAutomater");
            automater.Stop();
            Console.WriteLine("IBAutomater stopped");
        }