<s> from ib . ext . Contract import Contract <EOL> from ib . ext . ExecutionFilter import ExecutionFilter <EOL> from ib . opt import ibConnection , message <EOL> from time import sleep <EOL> def watcher ( msg ) : <EOL> print '<STR_LIT>' , msg <EOL> def dummyHandler ( msg ) : <EOL> pass <EOL> def my_BidAsk ( msg ) : <EOL> print '<STR_LIT>' <EOL> print msg <EOL> if msg . field == <NUM_LIT:1> : <EOL> print '<STR_LIT>' % ( contractTuple [ <NUM_LIT:0> ] , msg . price ) <EOL> elif msg . field == <NUM_LIT:2> : <EOL> print '<STR_LIT>' % ( contractTuple [ <NUM_LIT:0> ] , msg . price ) <EOL> def my_BidAsk2 ( msg ) : <EOL> print '<STR_LIT>' <EOL> print msg <EOL> def portfolioHandler ( msg ) : <EOL> print msg <EOL> print msg . contract . m_symbol <EOL> def makeStkContract ( contractTuple ) : <EOL> newContract = Contract ( ) <EOL> newContract . m_symbol = contractTuple [ <NUM_LIT:0> ] <EOL> newContract . m_secType = contractTuple [ <NUM_LIT:1> ] <EOL> newContract . m_exchange = contractTuple [ <NUM_LIT:2> ] <EOL> newContract . m_currency = contractTuple [ <NUM_LIT:3> ] <EOL> print '<STR_LIT>' % contractTuple <EOL> return newContract <EOL> def testMarketData ( ) : <EOL> tickId = <NUM_LIT:1> <EOL> contractTuple = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> stkContract = makeStkContract ( contractTuple ) <EOL> print '<STR_LIT>' <EOL> con . reqMktData ( tickId , stkContract , '<STR_LIT>' , False ) <EOL> sleep ( <NUM_LIT:3> ) <EOL> print '<STR_LIT>' <EOL> con . cancelMktData ( tickId ) <EOL> def testExecutions ( ) : <EOL> print '<STR_LIT>' <EOL> f = ExecutionFilter ( ) <EOL> f . m_time = '<STR_LIT>' <EOL> f . m_symbol = '<STR_LIT>' <EOL> f . m_secType = '<STR_LIT>' <EOL> f . m_exchange = '<STR_LIT>' <EOL> con . reqExecutions ( f ) <EOL> sleep ( <NUM_LIT:2> ) <EOL> def testAccountUpdates ( ) : <EOL> con . reqAccountUpdates ( True , '<STR_LIT>' ) <EOL> def testHistoricData ( con ) : <EOL> print '<STR_LIT>' <EOL> contractTuple = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> contract = makeStkContract ( contractTuple ) <EOL> con . reqHistoricalData ( <NUM_LIT:1> , contract , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> sleep ( <NUM_LIT:2> ) <EOL> def showMessageTypes ( ) : <EOL> m = message . registry . keys ( ) <EOL> m . sort ( ) <EOL> print '<STR_LIT>' <EOL> for msgType in m : <EOL> print msgType <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> showMessageTypes ( ) <EOL> con = ibConnection ( ) <EOL> con . registerAll ( watcher ) <EOL> con . register ( portfolioHandler , message . UpdatePortfolio ) <EOL> con . connect ( ) <EOL> testHistoricData ( con ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> con . disconnect ( ) <EOL> sleep ( <NUM_LIT:2> ) <EOL> print '<STR_LIT>' </s>
