Executing trade on another exchange ie SEHK

75 views
Skip to first unread message

Matt

unread,
Jan 27, 2014, 8:01:58 PM1/27/14
to ibpy-d...@googlegroups.com
I'd like execute an order for a stock given only the stock symbol.  Is there a way to look up the exchange?  I can search for the symbol in TWS ie 1259 and it comes up with the correct symbol etc, however when I attempt to execute the order w/ IBPY it does not find the stock unless I specify the exchange.  ie

def createContract(sym):
    print "Creating Contract"
    contract = Contract()
    contract.m_symbol = sym
    contract.m_localSymbol = sym
    contract.m_secType = 'STK'
    contract.m_exchange = 'SMART'
    contract.m_primaryExch = 'SMART'    
    contract.m_strike = 0.00
    contract.m_currency = 'USD'
    return contract

createContract(1259)

Error:
Placing order with id  240
Creating Contract
<error id=240, errorCode=200, errorMsg=No security definition has been found for
 the request>
Cancelling order
All done
Exception in thread EReader (most likely raised during interpreter shutdown):
C:\Users\Administrator>

-----------------

def createContract(sym):
    print "Creating Contract"
    contract = Contract()
    contract.m_symbol = sym
    contract.m_localSymbol = sym
    contract.m_secType = 'STK'
    contract.m_exchange = 'SEHK'
    contract.m_primaryExch = 'SEHK'    
    contract.m_strike = 0.00
    contract.m_currency = 'USD'
    return contract

createContract(1259)

Goes through no problem.... any suggestions on being able to submit an order w/out knowing the exchange beforehand?

Thanks you!
Matt

Derek Tishler

unread,
May 2, 2016, 5:35:36 PM5/2/16
to IbPy Discuss
From the java FAQ:

When using these methods for a stock contract, leave Global Symbol and Trading Class blank."

Have you attempted to leave m_symbol blank and only use the m_localSymbol? Maybe you could try using a m_secId and m_secIdType to zone in on the particular contract since you are using:

Derek Tishler

unread,
May 2, 2016, 6:55:59 PM5/2/16
to IbPy Discuss

Also, in order to get all possible exchanges for a contract you must call conn.reqContractDetails(tickerID, contract) after connecting. Before connecting be sure to have registered for the message: conn.register(contract_detail_handler, message.contractDetails). This will send a message of ContractDetails which will contain the valid exchanged: print sorted(msg.contractDetails.m_validExchanges.split(','))

I usually submit a contract with just the required items like symbol, sec_type, and currency. Then I receive back the ContractDetails and build a list of exchanges per equity so I can then create a contract and live market data request for level I or II data per exchange per stock. You can then put it all together and get something like:


Source & API info:

https://www.interactivebrokers.com/en/software/api/apiguide/java/reqcontractdetails.htm

https://www.interactivebrokers.com/en/software/api/apiguide/java/contractdetails.htm

https://www.interactivebrokers.com/en/software/api/apiguide/java/contractdetailsjava.htm

Reply all
Reply to author
Forward
0 new messages