Exemplo n.º 1
0
def main(options):
    basicConfig()
    logging.root.setLevel(verbose_levels.get(options.verbose, ERROR))
    options.port
    con = ibConnection(options.host, 7497, options.clientid)

    # con.registerAll(reply_handler)
    con.register(error_handler, 'Error')
    con.register(update_account_value, 'AccountSummary')
    con.register(my_BidAsk, message.tickPrice, message.tickSize)
    con.register(reply_handler, 'UpdateMktDepth')

    con.connect()
    short_sleep()

    request_account_summary(connection=con, options=options)
    request_market_data(connection=con, options=options, symbol='GOOG')
    request_market_data(connection=con, options=options, symbol='MSFT')
    request_market_depth(connection=con, options=options)

    #test_000(connection=con, options=options)
    #test_003(connection=con, options=options)
    #test_999(connection=con, options=options)

    sleep(2)
    con.eDisconnect()
Exemplo n.º 2
0
    def __init__(self):
        options = get_options()
        basicConfig()
        self.connection = ibConnection(options.host, options.port,
                                       options.clientid)
        self.clientid = options.clientid
        self.connection.register(self._reply_next_valid_order_id,
                                 'NextValidId')
        self.connection.register(self._update_account_value, 'AccountSummary')
        self.connection.register(self._reply_managed_accounts,
                                 'ManagedAccounts')
        self.connection.register(self._reply_current_time, 'CurrentTime')
        self.connection.register(self._reply_realtime_snapshot,
                                 message.tickPrice, message.tickSize)

        self.connection.register(self._reply_place_order, 'OrderStatus')
        self.connection.register(self._error_handler, 'Error')
        self.connection.register(self._reply_execution_details, 'ExecDetails')
        self.connection.registerAll(self._reply_all)

        self.ib_account_cash = dict()
        self.ib_account_list = list()
        self.market_data = dict()
        self._requested_tickers = dict()

        self.orders = dict()
        self._order_events = set()

        self._current_time = None

        self._time_received_next_valid_order_id = None
        self._next_valid_order_id = None
        self.messages = list()
        self.execution_allocation_msgs = list()
        self.execution_allocations = AccountAllocations()
Exemplo n.º 3
0
 def __init__(self):
     basicConfig()
     self._time_received_next_valid_order_id = datetime.min
     self._executions = {}
     self._account_info = {}
     self._requests_finished = {}
     self._errors = {}
     self._open_orders_end = {}
     self._max_request = False
Exemplo n.º 4
0
 def __init__(self):
     basicConfig()
     # These two variables are initialized in Connect method
     self._connection = None
     self._wrapper = None
     self._request_id = 0
Exemplo n.º 5
0
def main(options):
    basicConfig()
    logging.root.setLevel(verbose_levels.get(options.verbose, ERROR))

    rec_msgs = {}
    unrec_msgs = {}

    handler = make_msg_counter(rec_msgs, unrec_msgs)

    # make_msg_counter fills in the defaults for the rec_msgs dict; now we can
    # print those values and exit if the option is given
    if options.printmsgs:
        for name in sorted(k[0].typeName for k in list(rec_msgs.keys())):
            print(name)
        return

    # if we're still here, we should connect
    con = ibConnection(options.host, options.port, options.clientid)
    con.registerAll(handler)
    con.register(save_order_id, 'NextValidId')
    con.register(save_tick, 'TickSize', 'TickPrice')
    con.connect()
    short_sleep()

    # and if we've connected, we shoud execute all of the test functions in
    # the module namespace.
    calls = [v for k, v in list(globals().items()) if k.startswith('test_')]
    for call in sorted(calls, key=lambda f: f.__name__):
        call = maybe_verbose(catch_errors(call))
        errors = call(con, options)
        for err in errors:
            error_msgs[err] = call.__name__

    type_count = len(rec_msgs)
    seen_items = list(rec_msgs.items())
    seen = [(k, v) for k, v in seen_items if v]
    unseen = [(k, v) for k, v in seen_items if not v]

    # adjust the showmsgs option if given --show=all
    alls = [v for v in options.showmsgs if 'all' in v.lower()]
    if any(alls):
        all, count = name_count(alls[0])
        options.showmsgs = ['%s:%s' %
                            (k.typeName, count) for k in list(rec_msgs.keys())]

    # ready, set, print!
    for msg_typename in options.showmsgs:
        msg_typename, msg_showmax = name_count(msg_typename)
        formatter = msg_formatters.get(msg_typename, msg_formatters['default'])
        msgs = [v for k, v in seen_items if k.typeName == msg_typename]
        if msgs:
            msgs = msgs[0]
            if not msg_showmax or msg_showmax > len(msgs):
                msg_showmax = len(msgs)
            print('\n%s (%s of %s):' %
                  (msg_typename, msg_showmax, len(msgs), ))
            for msg in msgs[0:msg_showmax]:
                print(formatter(msg))
        else:
            if msg_typename in [k.typeName for k in list(rec_msgs.keys())]:
                print('\n%s (%s):' % (msg_typename, 0, ))
            else:
                print('\nMessage type %s not recognized' % (msg_typename, ))

    # but wait, there's more!  here we print a summary of seen message
    # types and associated counts.
    if seen:
        print('\nSeen Message Types (count):')
        for cls, seq in sorted(seen, key=lambda t: t[0].typeName):
            print('    %s (%s)' % (cls.__name__, len(seq), ))
    else:
        print('\nTotal failure; no messages received.')
    # but wait, there's more!  here we print a summary of unseen message
    # types and associated counts.
    if unseen:
        print('\nUnseen Message Types (help):')
        for cls, zero in sorted(unseen, key=lambda t: t[0].typeName):
            name = cls.__name__
            help = unseen_hints.get(name, '')
            print('    %s%s' % (name, ' (%s)' % help if help else '', ))
    else:
        print('\nAll Message types received.')
    # last but not least we print the seen and unseen totals, and their ratio
    print('\nSummary:')
    args = (type_count, len(seen), len(unseen),
            100 * len(seen) / float(type_count))
    print('   total:%s  seen:%s  unseen:%s  coverage:%2.2f%%' % args)
Exemplo n.º 6
0
def main(options):
    basicConfig()
    logging.root.setLevel(verbose_levels.get(options.verbose, ERROR))

    rec_msgs = {}
    unrec_msgs = {}

    handler = make_msg_counter(rec_msgs, unrec_msgs)

    ## make_msg_counter fills in the defaults for the rec_msgs dict; now we can
    ## print those values and exit if the option is given
    if options.printmsgs:
        for name in sorted(k[0].typeName for k in list(rec_msgs.keys())):
            print(name)
        return

    ## if we're still here, we should connect
    con = ibConnection(options.host, options.port, options.clientid)
    con.registerAll(handler)
    con.register(save_order_id, 'NextValidId')
    con.register(save_tick, 'TickSize', 'TickPrice')
    con.connect()
    short_sleep()

    ## and if we've connected, we shoud execute all of the test functions in
    ## the module namespace.
    calls = [v for k, v in list(globals().items()) if k.startswith('test_')]
    for call in sorted(calls, key=lambda f: f.__name__):
        call = maybe_verbose(catch_errors(call))
        errors = call(con, options)
        for err in errors:
            error_msgs[err] = call.__name__

    type_count = len(rec_msgs)
    seen_items = list(rec_msgs.items())
    seen = [(k, v) for k, v in seen_items if v]
    unseen = [(k, v) for k, v in seen_items if not v]

    ## adjust the showmsgs option if given --show=all
    alls = [v for v in options.showmsgs if 'all' in v.lower()]
    if any(alls):
        all, count = name_count(alls[0])
        options.showmsgs = [
            '%s:%s' % (k.typeName, count) for k in list(rec_msgs.keys())
        ]

    ## ready, set, print!
    for msg_typename in options.showmsgs:
        msg_typename, msg_showmax = name_count(msg_typename)
        formatter = msg_formatters.get(msg_typename, msg_formatters['default'])
        msgs = [v for k, v in seen_items if k.typeName == msg_typename]
        if msgs:
            msgs = msgs[0]
            if not msg_showmax or msg_showmax > len(msgs):
                msg_showmax = len(msgs)
            print('\n%s (%s of %s):' % (
                msg_typename,
                msg_showmax,
                len(msgs),
            ))
            for msg in msgs[0:msg_showmax]:
                print(formatter(msg))
        else:
            if msg_typename in [k.typeName for k in list(rec_msgs.keys())]:
                print('\n%s (%s):' % (
                    msg_typename,
                    0,
                ))
            else:
                print('\nMessage type %s not recognized' % (msg_typename, ))

    ## but wait, there's more!  here we print a summary of seen message
    ## types and associated counts.
    if seen:
        print('\nSeen Message Types (count):')
        for cls, seq in sorted(seen, key=lambda t: t[0].typeName):
            print('    %s (%s)' % (
                cls.__name__,
                len(seq),
            ))
    else:
        print('\nTotal failure; no messages received.')
    ## but wait, there's more!  here we print a summary of unseen message
    ## types and associated counts.
    if unseen:
        print('\nUnseen Message Types (help):')
        for cls, zero in sorted(unseen, key=lambda t: t[0].typeName):
            name = cls.__name__
            help = unseen_hints.get(name, '')
            print('    %s%s' % (
                name,
                ' (%s)' % help if help else '',
            ))
    else:
        print('\nAll Message types received.')
    ## last but not least we print the seen and unseen totals, and their ratio
    print('\nSummary:')
    args = (type_count, len(seen), len(unseen),
            100 * len(seen) / float(type_count))
    print('   total:%s  seen:%s  unseen:%s  coverage:%2.2f%%' % args)
Exemplo n.º 7
0
 def __init__(self):
     basicConfig()
     self._market_depth_L1 = {}
     self._requests_finished = {}
     self._errors = {}