def get_metal_data(symbol="XAUUSD", duration="20 D", period="30 mins", is_simulated=False): config = config_loader.load() ip = config.get("ib-gateway", "ip") #ip = "127.0.0.1" if (is_simulated): app = TestApp(ip, 4002, ClientID.HIST_METAL.value) else: app = TestApp(ip, 4001, ClientID.HIST_METAL.value) ibcontract = IBcontract() #ibcontract.lastTradeDateOrContractMonth="201803" ibcontract.secType = "CMDTY" ibcontract.symbol = symbol ibcontract.exchange = "SMART" resolved_ibcontract = app.resolve_ib_contract(ibcontract) historic_data = app.get_IB_historical_data(resolved_ibcontract, duration, period) #print(historic_data) #out_tup = resample.filter_data(historic_data, period) #historic_data = out_tup try: app.disconnect() except: print("Disconnect with errors (no harm)!") return historic_data
def get_fx_data(symbol, currency, duration="2 M", period="4 hours", is_simulated=False): config = config_loader.load() ip = config.get("ib-gateway", "ip") #ip = "127.0.0.1" if (is_simulated): app = TestApp(ip, 4002, ClientID.HIST_FX.value) else: app = TestApp(ip, 4001, ClientID.HIST_FX.value) ibcontract = IBcontract() #ibcontract.lastTradeDateOrContractMonth="201809" #ibcontract.secType = "FUT" #ibcontract.symbol="GE" #ibcontract.exchange="GLOBEX" ibcontract.symbol = symbol ibcontract.secType = "CASH" ibcontract.currency = currency ibcontract.exchange = "IDEALPRO" resolved_ibcontract = app.resolve_ib_contract(ibcontract) historic_data = app.get_IB_historical_data(resolved_ibcontract, duration, period) #print(historic_data) out_tup = resample.filter_data("FX", historic_data, period) historic_data = out_tup try: app.disconnect() except: print("Disconnect with errors (no harm)!") return historic_data
def get_hkfe_data(contractMonth, symbol="MHI", duration="20 D", period="30 mins", is_simulated=False): config = config_loader.load() ip = config.get("ib-gateway", "ip") #ip = "127.0.0.1" if (is_simulated): app = TestApp(ip, 4002, ClientID.HIST_HKFE.value) else: app = TestApp(ip, 4001, ClientID.HIST_HKFE.value) ibcontract = IBcontract() #YYYYMM ibcontract.lastTradeDateOrContractMonth = contractMonth ibcontract.secType = "FUT" ibcontract.symbol = symbol ibcontract.exchange = "HKFE" resolved_ibcontract = app.resolve_ib_contract(ibcontract) historic_data = app.get_IB_historical_data(resolved_ibcontract, duration, period, "TRADES") #print(historic_data) out_tup = resample.filter_data("HKFE", historic_data, period) historic_data = out_tup #print(historic_data) try: app.disconnect() except: print("Disconnect with errors (no harm)!") return historic_data
TestWrapper.__init__(self) TestClient.__init__(self, wrapper=self) self.connect(ipaddress, portid, clientid) thread = Thread(target = self.run) thread.start() setattr(self, "_thread", thread) self.init_error() if __name__ == '__main__': config = config_loader.load() ip = config.get("ib-gateway","ip") port = 4001 #ip = "127.0.0.1" #port = 4002 app = TestApp(ip, port, 59) print("Open orders (#################)") open_orders = app.get_open_orders() keys = open_orders.keys() for k in keys: orderInfo = open_orders[k]