Hello. I am trying to write a small program to place bracket orders on IB TWS through their Python API. I am not that versed in Python (or other IB APIs); just piecing together bits of code that I am come across here and here. I am using Python 3.6 and Tkinter as the GUI. Where I am current stuck is getting the prices for currency pairs. The code below works fine for stocks:
def create_contract(self, symbol, sec_type, exch, prim_exch, curr):#*
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
def request_market_data(self, symbol_id, symbol):
contract = self.create_contract(symbol,
'STK',
'SMART',
'NASDAQ',
'USD')
self.tws_conn.reqMktData(symbol_id, contract, '', False)
But when I amend it for a currency pair as follows:
def create_contract(self, symbol, sec_type, exch, curr): # *
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_currency = curr
return contract
def request_market_data(self, symbol_id, symbol):
contract = self.create_contract(symbol,
'CASH',
'IDEALPRO',
'USD')
self.tws_conn.reqMktData(symbol_id, contract, '', False)
it does not work and geneartes the error: Server Error: <error id=0, errorCode=300, errorMsg=Can't find EId with tickerId:0>
Would be most grateful for any assistance please. Thanks
def create_contract(self, symbol, sec_type, exch, prim_exch, curr):#*
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
def request_market_data(self, symbol_id, symbol):
contract = self.create_contract(symbol,
'STK',
'SMART',
'NASDAQ',
'USD')
self.tws_conn.reqMktData(symbol_id, contract, '', False)
But when I amend it for a currency pair as follows:
def create_contract(self, symbol, sec_type, exch, curr): # *
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_currency = curr
return contract
def request_market_data(self, symbol_id, symbol):
contract = self.create_contract(symbol,
'CASH',
'IDEALPRO',
'USD')
self.tws_conn.reqMktData(symbol_id, contract, '', False)
it does not work and geneartes the error: Server Error: <error id=0, errorCode=300, errorMsg=Can't find EId with tickerId:0>
Would be most grateful for any assistance please. Thanks