private void GetNextValideOrderId(EWrapperImpl ibClient) { ibClient.nextValidId(OrderDetails.NextOrderId); int num = 1; while (OrderDetails.NextOrderId == 0) { log.Info("Next Valid OrderId " + OrderDetails.NextOrderId); Thread.Sleep(1000); if (num > 25) { ibClient.nextValidId(OrderDetails.NextOrderId); } if (num > 50) { ibClient.nextValidId(OrderDetails.NextOrderId); } if (num > 75) { break; } num++; } log.Info("Next Valid OrderId " + OrderDetails.NextOrderId); }
public static void Main(string[] args) { EWrapperImpl ibClient = new EWrapperImpl(); EClientSocket clientSocket = ibClient.ClientSocket; Console.ForegroundColor = ConsoleColor.DarkGreen; string logo = @" /$$$$$$$ /$$ /$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$ | $$__ $$| $$ | $$ /$$__ $$ |__/ | $$ | $$ |_ $$_/ | $$ \ $$| $$ /$$$$$$ /$$$$$$$| $$ /$$| $$ \__/ /$$$$$$ /$$$$$$ /$$ /$$$$$$ /$$$$$$ | $$ | $$ /$$$$$$$ /$$$$$$$ | $$$$$$$ | $$ /$$__ $$ /$$_____/| $$ /$$/| $$ |____ $$ /$$__ $$| $$|_ $$_/ |____ $$| $$ | $$ | $$__ $$ /$$_____/ | $$__ $$| $$| $$ \ $$| $$ | $$$$$$/ | $$ /$$$$$$$| $$ \ $$| $$ | $$ /$$$$$$$| $$ | $$ | $$ \ $$| $$ | $$ \ $$| $$| $$ | $$| $$ | $$_ $$ | $$ $$ /$$__ $$| $$ | $$| $$ | $$ /$$ /$$__ $$| $$ | $$ | $$ | $$| $$ | $$$$$$$/| $$| $$$$$$/| $$$$$$$| $$ \ $$| $$$$$$/| $$$$$$$| $$$$$$$/| $$ | $$$$/| $$$$$$$| $$ /$$$$$$| $$ | $$| $$$$$$$ /$$ |_______/ |__/ \______/ \_______/|__/ \__/ \______/ \_______/| $$____/ |__/ \___/ \_______/|__/ |______/|__/ |__/ \_______/|__/ | $$ | $$ |__/ "; Console.WriteLine(logo); Console.ResetColor(); Console.Write("BlockShift Trading App"); Console.Write("\n"); Console.Write("DISCLAIMER: USING THIS SOFTWARE AT MY OWN RISK\n"); Console.Write("\n"); try { ConsoleWindow.QuickEditMode(false); Parameters @params = new Parameters(Path.Combine(Environment.CurrentDirectory, "config.conf")); SimpleLogger log = new SimpleLogger(); Slack slack = new Slack(@params); Prices prices = new Prices(log, @params); FuturesContract futures = new FuturesContract(@params); Strategy strategy = new Strategy(log); Broker broker = new Broker(clientSocket, log, @params, slack); Positions positions = new Positions(log, @params, slack); Transactions transactions = new Transactions(log); Controller ctl = new Controller(clientSocket, log, @params, strategy, broker, positions, futures, prices, transactions, slack); broker.ConnectionToBroker(strategy, positions); ctl.Run(); } catch (Exception ex) { Console.Write(ex.Message.ToString()); Console.Write(ex.StackTrace.ToString()); } Console.ReadLine(); }
public void ValidateConnectionToBroker(Strategy strategy, Positions positions) { int count = 0; int n; if (clientSocket.IsConnected()) { UpdateIBPositionList(strategy, positions); } else { EWrapperImpl ibClient = new EWrapperImpl(); while (!clientSocket.IsConnected()) { try { clientSocket.eConnect("127.0.0.1", 7496, 100); } catch (Exception ex) { this.log.Trace(ex.Message.ToString()); } if (clientSocket.IsConnected()) { var reader = new EReader(clientSocket, ibClient.Signal); reader.Start(); new Thread(() => { while (clientSocket.IsConnected()) { ibClient.Signal.waitForSignal(); reader.processMsgs(); } }) { IsBackground = true }.Start(); GetNextValideOrderId(ibClient); } if (!clientSocket.IsConnected()) { if (count < Ordinal.Length - 1) { n = count; } else { n = Ordinal.Length - 1; } log.Warning($"{count + 1}{Ordinal[n].ToString()} attempt could not connect to IBApi. Retry in {[email protected]} seconds."); // this.log.Warning($"{count + 1} attempt could not connect to IBApi. Retry in {[email protected]} seconds."); Thread.Sleep(TimeSpan.FromSeconds([email protected])); count++; } if (count > [email protected]) { this.log.Warning("Closing. Could not establish connection."); slack.SendMessageToSlack("*Closing App... Could not Establish Connection to Broker.*", @params); Environment.Exit(1); } } } }