def say_hello(socket, strategy_id_bytes): socket.send_multipart([hello_tag, strategy_id_bytes]) message_parts = poll_single_socket(socket, 1) if message_parts: [tag, venue_id] = message_parts tag = int_from_bytes(tag) venue_id = int_from_bytes(venue_id) assert tag == order_engine_constants.STRATEGY_HELO_ACK, \ 'Unexpected response to HELO: %d' % tag return venue_id else: raise RuntimeError("Didn't get response to HELO from order engine" )
def run(self, md_update, place_orders, order_first=False): self._synchronize_market_data(md_update) poller = zmq.Poller() md_socket = self.md_socket poller.register(md_socket, zmq.POLLIN) print 'ORDER SOCKETS:', self.order_sockets print 'ORDER SOCKET VALUES: ', self.order_sockets.values() for order_socket in self.order_sockets.values(): poller.register(order_socket, zmq.POLLIN) while True: if order_first == True: place_orders() ready_sockets = poller.poll() for (socket, state) in ready_sockets: # ignore errors for now if state == zmq.POLLERR: print 'POLLERR on socket', socket, 'md socket = ', \ self.md_socket, 'order sockets = ', \ self.order_sockets elif state == zmq.POLLIN: if socket == md_socket: msg = md_socket.recv() bbo = spot_fx_md_1_pb2.instrument_bbo() msg = md_socket.recv() bbo.ParseFromString(msg) md_update(bbo) else: [tag, msg] = socket.recv_multipart() tag = int_from_bytes(tag) self.order_manager.received_message_from_order_engine(tag, msg) place_orders()
def ping(socket, name=None): t0 = time.time() socket.send(int_to_bytes(order_engine_constants.PING)) message_parts = poll_single_socket(socket, 0.25) if message_parts: tag = int_from_bytes(message_parts[0]) tag == order_engine_constants.PING_ACK return time.time() - t0 else: if not name: name = '<not given>' raise RuntimeError('Timed out waiting for ping ack from %s' % name)