示例#1
0
    def get_configs(self):
        self.config_socket.send('C')
        response = poll_single_socket(self.config_socket)
        if response is None:
            raise RuntimeError('Config server is down')
        [tag, msg] = response
        assert tag == 'CONFIG'
        config = venue_configuration_pb2.configuration()
        config.ParseFromString(msg)

        for venue_config in config.configs:
            venue_id = int(venue_config.venue_id)
            mic_name = str(venue_config.mic_name)
            print
            print 'Reading config for mic = %s, venue_id = %s' \
                % (mic_name, venue_id)

            ping_addr = str(venue_config.order_ping_addr)
            order_addr = str(venue_config.order_interface_addr)
            md_addr = str(venue_config.market_data_broadcast_addr)
            log_addr = str(venue_config.logging_broadcast_addr)

            vc = venue_capabilities(venue_id)
            venue_attrs.venue_specifics[venue_id] = vc
            if venue_config.use_synthetic_cancel_replace is True:
                print 'Setting synthetic_cancel_replace for: %d' % venue_id
                venue_attrs.venue_specifics[venue_id].use_synthetic_cancel_replace = True

        return config
示例#2
0
    def connect(self, config_server_addr, verbose=True):
        """Talk to the config server and get addresses for 
       all available order engines and market data feeds, 
       return an order manager which is connected to all order sockets
    """

        config_socket = self.config_socket
        print 'Requesting configuation from', config_server_addr
        config_socket.connect(config_server_addr)
        config_socket.send('C')
        response = poll_single_socket(config_socket)
        if response is None:
            raise RuntimeError('Config server is down')
        [tag, msg] = response
        assert tag == 'CONFIG'
        config = venue_configuration_pb2.configuration()
        config.ParseFromString(msg)

        for venue_config in config.configs:
            venue_id = int(venue_config.venue_id)
            mic_name = str(venue_config.mic_name)
            print
            print 'Reading config for mic = %s, venue_id = %s' \
                % (mic_name, venue_id)

            ping_addr = str(venue_config.order_ping_addr)
            order_addr = str(venue_config.order_interface_addr)
            md_addr = str(venue_config.market_data_broadcast_addr)
            log_addr = str(venue_config.logging_broadcast_addr)

            vc = venue_capabilities(venue_id)
            venue_attrs.venue_specifics[venue_id] = vc
            if venue_config.use_synthetic_cancel_replace is True:
                print 'Setting synthetic_cancel_replace for: %d' % venue_id
                venue_attrs.venue_specifics[venue_id].use_synthetic_cancel_replace = True

            problem_with_addr = False
            for addr in [ping_addr, order_addr, md_addr]:
                if not address_ok(addr):
                    print 'Malformed address', addr
                    problem_with_addr = True
            if problem_with_addr:
                print 'Skipping', mic_name
                continue
            order_control_socket = \
                connect_to_order_engine_controller(ping_addr)
            if order_control_socket:
                print 'Ping succeeded, adding sockets...'
                (order_socket, venue_id2) = \
                    connect_to_order_engine(order_addr,
                        self.strategy_id_bytes, mic_name)
                assert venue_id == venue_id2
                self.order_sockets[venue_id] = order_socket
                self.mic_names[venue_id] = mic_name
                self.order_control_sockets[venue_id] = \
                    order_control_socket
                self.md_socket.connect(md_addr)
        if self.symbols is None:
            self.md_socket.setsockopt(zmq.SUBSCRIBE, '')
        else:
            for s in self.symbols:
                self.md_socket.setsockopt(zmq.SUBSCRIBE, s)
        names = self.mic_names.values()
        if len(names) > 0:
            print
            print '----------------------------'
            print 'Succeeded in connecting to: ', ', '.join(names)
            print '----------------------------'
            print
        else:
            raise RuntimeError("Couldn't find any active venues")

    # return the set of valid venue_ids

        self.order_manager = OrderManager(self.strategy_id_bytes,
                self.order_sockets)
        return self.order_manager