args = cmdLineParser.parse_args() print("Using args", args) # IB allows a max of 30 requests / 10 minutes. # If necessary, we wait for the time here max_request_per_ten_minutes = 29 # NY Stock Exchange operates between 9:30 AM and 4:00 PM dates = Dates() day = '2020-07-18' initial_date = day + 'T09:33' final_date = day + 'T16:03' frequency = '3T' start_hour = '9:31' final_hour = '16:00' dates_list = dates.obtain_dates(initial_date, final_date, frequency, start_hour, final_hour) print(dates_list) print(len(dates_list)) # exit() app = IBapi() app.connect("127.0.0.1", args.port, 0) # Start the socket in a thread api_thread = threading.Thread(target=run_loop, daemon=True) api_thread.start() time.sleep(1) # Sleep interval to allow time for connection to server contract = Contract() contract.symbol = "MSFT" contract.secType = "STK"