Module Expr Str Import alias Import alias identifier Import alias Import alias Import alias ImportFrom alias ImportFrom alias alias Assign NameStore Dict Num Num Num Num Num Num Num Str Str Str Str Str Str Str Assign NameStore Dict Num Num Num Num Str Str Str Str ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr If UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr Str body Expr Call AttributeLoad NameLoad attr Str Assign NameStore BinOpMod Str Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr attr Str Print Str NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore ListLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr attr Str SubscriptLoad NameLoad Index AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore ListLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr attr Str SubscriptLoad NameLoad Index AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore BinOpMod Str BinOpSub Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore BinOpAdd Call AttributeLoad Str attr GeneratorExp Call NameLoad NameLoad comprehension NameStore BinOpAdd ListLoad NameLoad NameLoad Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Print Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list decorator_list FunctionDef arguments args NameParam defaults body Expr Str Print Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Str Assign AttributeStore NameLoad attr Str Assign AttributeStore NameLoad attr Str Return NameLoad decorator_list If CompareEq NameLoad Str body Assign NameStore Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr attr Str Print Str NameLoad Assign NameStore Dict For TupleStore NameStore NameStore Call NameLoad NameLoad body Assign SubscriptStore NameLoad Index BinOpAdd NameLoad Num Call NameLoad NameLoad Assign NameStore Call NameLoad Assign NameStore Call NameLoad NameLoad NameLoad If AttributeLoad NameLoad attr body Print Str Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Str NameLoad Print Str TryExcept body While NameLoad body Expr Call AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str handlers ExceptHandler type NameLoad body Print Str Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Print Str
N/A N/A 
Created on May 5, 2013
Copyright: Jev Kuznetsov
License: BSD

Program to log tick events to a file

example usage:
    > python ib_logQuotes.py SPY,VXX,XLE     
    
    start with -v option to show all incoming events


 N/A argparse N/A datetime dt N/A time N/A os N/A sys ib.ext.Contract Contract ib.opt ibConnection message N/A priceTicks N/A 1 2 4 6 7 9 14 bid ask last high low close open N/A sizeTicks N/A 0 3 5 8 bid ask last volume TickLogger N/A object N/A N/A  class for handling incoming ticks and saving them to file 
        will create a subdirectory 'tickLogs' if needed and start logging
        to a file with current timestamp in its name.
        All timestamps in the file are in seconds relative to start of logging
    
     __init__ N/A N/A self tws subscriptions N/A N/A N/A  init class, register handlers  N/A N/A N/A tws register N/A self _priceHandler N/A message TickPrice N/A N/A N/A tws register N/A self _sizeHandler N/A message TickSize N/A N/A self subscriptions subscriptions N/A N/A self _startTime N/A N/A time time N/A N/A N/A N/A N/A os path exists tickLogs N/A N/A N/A N/A os mkdir tickLogs N/A fileName N/A tickLogs\tickLog_%s.csv N/A N/A N/A N/A N/A dt datetime now strftime %H_%M_%S N/A Logging ticks to  fileName N/A N/A self dataFile N/A open fileName w N/A _priceHandler N/A N/A self msg N/A N/A N/A  price tick handler  N/A data N/A N/A N/A N/A self subscriptions N/A N/A msg tickerId m_symbol price N/A priceTicks N/A N/A msg field N/A msg price N/A N/A N/A self _writeData data N/A _sizeHandler N/A N/A self msg N/A N/A N/A  size tick handler  N/A data N/A N/A N/A N/A self subscriptions N/A N/A msg tickerId m_symbol size N/A sizeTicks N/A N/A msg field N/A msg size N/A N/A N/A self _writeData data N/A _writeData N/A N/A self data N/A N/A N/A  write data to log file while adding a timestamp  N/A timestamp N/A %.3f N/A N/A N/A time time N/A self _startTime N/A dataLine N/A N/A N/A , join N/A N/A str bit N/A bit N/A N/A timestamp data N/A N/A N/A N/A self dataFile write dataLine N/A flush N/A N/A self N/A N/A N/A  commits data to file N/A N/A N/A N/A self dataFile flush N/A close N/A N/A self N/A N/A N/A close file in a neat manner  N/A Closing data file N/A N/A N/A N/A self dataFile close N/A N/A printMessage N/A N/A msg N/A N/A N/A  function to print all incoming messages from TWS  N/A [msg]: msg N/A createContract N/A N/A symbol N/A N/A N/A  create contract object  N/A c N/A Contract N/A N/A c m_symbol symbol N/A N/A c m_secType STK N/A N/A c m_exchange SMART N/A N/A c m_currency USD N/A c N/A N/A N/A __name__ __main__ N/A N/A parser N/A N/A argparse ArgumentParser description Log ticks for a set of stocks N/A N/A N/A parser add_argument symbols help symbols separated by coma: SPY,VXX N/A N/A N/A parser add_argument -v --verbose help show all incoming messages action store_true N/A args N/A N/A parser parse_args N/A symbols N/A N/A N/A N/A N/A args symbols strip split , N/A Logging ticks for: symbols N/A subscriptions N/A N/A N/A idx symbol N/A enumerate symbols N/A N/A N/A subscriptions N/A N/A idx 1 N/A createContract symbol N/A tws N/A ibConnection N/A logger N/A TickLogger tws subscriptions N/A N/A args verbose N/A N/A Starting in verbose mode N/A N/A N/A tws registerAll printMessage N/A N/A N/A tws connect N/A N/A subId c N/A N/A subscriptions iteritems N/A N/A N/A N/A tws reqMktData subId c False N/A Press Ctr-C to stop loop N/A N/A N/A True N/A N/A N/A N/A time sleep 2 N/A N/A N/A logger flush N/A N/A N/A N/A sys stdout write . N/A N/A N/A KeyboardInterrupt N/A N/A Interrupted with Ctrl-c N/A N/A N/A logger close N/A N/A N/A tws disconnect N/A All done