def get_IB_historical_data(self, ibcontract, durationStr="1 Y", barSizeSetting="1 day", tickerid=999): """ Returns historical prices for a contract, up to today tws is a result of calling IBConnector() """ global historicdata global finished global iserror finished = False iserror = False today = datetime.datetime.now() historicdata = autodf("date", "open", "high", "low", "close", "volume") # Request some historical data. self.tws.reqHistoricalData( tickerid, # tickerId, ibcontract, # contract, today.strftime("%Y%m%d %H:%M:%S %Z"), # endDateTime, durationStr, # durationStr, barSizeSetting, # barSizeSetting, "TRADES", # whatToShow, 1, # useRTH, 1 # formatDate ) start_time = time.time() while not finished: if (time.time() - start_time) > MAX_WAIT: finished = True iserror = True pass if iserror: raise Exception("Problem getting historic data") results = historicdata.to_pandas("date") return results
def get_IB_historical_data(self, ibcontract, durationStr="1 Y", barSizeSetting="1 day", tickerid=999): """ Returns historical prices for a contract, up to today tws is a result of calling IBConnector() """ global historicdata global finished global iserror finished=False iserror=False today=datetime.datetime.now() historicdata=autodf("date", "open", "high", "low", "close", "volume") # Request some historical data. self.tws.reqHistoricalData( tickerid, # tickerId, ibcontract, # contract, today.strftime("%Y%m%d %H:%M:%S %Z"), # endDateTime, durationStr, # durationStr, barSizeSetting, # barSizeSetting, "TRADES", # whatToShow, 1, # useRTH, 1 # formatDate ) start_time=time.time() while not finished: if (time.time() - start_time) > MAX_WAIT: finished=True iserror=True pass if iserror: raise Exception("Problem getting historic data") results=historicdata.to_pandas("date") return results
from swigibpy import EWrapper import time import datetime from swigibpy import EPosixClientSocket from sysIB.IButils import autodf MEANINGLESS_NUMBER = 999 EMPTY_HDATA = autodf("date", "open", "high", "low", "close", "volume") ### how many seconds before we give up MAX_WAIT = 30 def return_IB_connection_info(): """ Returns the tuple host, port, clientID required by eConnect """ host = "" port = 4001 clientid = 999 return (host, port, clientid) class IBWrapper(EWrapper):
import time import datetime from swigibpy import EWrapper from swigibpy import EPosixClientSocket from sysIB.IButils import autodf MEANINGLESS_NUMBER = 9999 CLIENT_ID = 99999 # collect all available data from IB EMPTY_HDATA = autodf('date', 'open', 'high', 'low', 'close', 'volume', 'barCount', 'wap', 'hasGaps') # how many seconds before we give up MAX_WAIT = 10 TWS_PORT = 7496 GATEWAY_PORT = 4001 PORT = GATEWAY_PORT def return_IB_connection_info(): """ Returns the tuple host, port, clientID required by eConnect """ host = "" port = PORT clientid = CLIENT_ID