def process_internal(self, current_time, elapsed):
        # If already emitted output => get next order!
        self.debug("next_wakeup = %f, curr = %f, elapsed = %f" %
                   (self.next_wakeup_time, current_time, elapsed))
        if not eq_rounded(current_time + elapsed, self.next_wakeup_time):
            self.debug(
                "self.next_wakeup_time != self.get_current_time() + elapsed")
            assert (current_time + elapsed < self.next_wakeup_time)
            return self.next_wakeup_time - current_time - elapsed
        else:
            assert (current_time + elapsed == self.next_wakeup_time)
            if self.n_order_to_send <= self.n_orders:
                assert (self.prepared_to_send_next_order)
                self.debug("Prepared to send next order == True")

                self.next_order = self.prepare_order()
                self.prepared_to_send_next_order = False

                waiting_time = self.next_order.creation_time - current_time - elapsed
                self.next_wakeup_time = self.next_order.creation_time

                self.debug('waiting time=%f, next_wakeup_time=%f' %
                           (waiting_time, self.next_wakeup_time))
                return waiting_time
            else:
                self.debug('wait = inf')
                self.next_wakeup_time = float('inf')
                return float('inf')
 def output_function(self, current_time, elapsed):
     output = {}
     for contract in self.contracts:
         pending_orders = self.next_orders_delivery[contract]
         if len(pending_orders) > 0:
             next_pending_order = heapq.heappop(pending_orders)
             assert (current_time + elapsed <=
                     next_pending_order.wakeup_time)
             self.debug(
                 'Check pending order: %f %f %f' %
                 (current_time, elapsed, next_pending_order.wakeup_time))
             if eq_rounded(current_time + elapsed,
                           next_pending_order.wakeup_time):
                 next_order = next_pending_order.order
                 self.debug("Order ready: %s" % str(next_order))
                 self.orders_sent.append(next_order.m_orderId)
                 output['out_order'] = MessageForOrderbook(
                     self.identifier, current_time + elapsed, next_order)
                 break
             else:
                 self.debug("Pending Order not ready: %f %f %f" %
                            (current_time, elapsed,
                             next_pending_order.wakeup_time))
                 heapq.heappush(self.next_orders_delivery[contract],
                                next_pending_order)
     # Emit output
     return output
Пример #3
0
    def output_function(self, current_time, elapsed):
        output = {}
        for out_port in ['out_journal']:
            # Look for a notification for each LOB table
            messages = self.next_notification_delivery[self.contract]
            if len(messages) > 0:
                next_message = heapq.heappop(messages)
                assert (current_time + elapsed <= next_message.wakeup_time)
                self.debug('Check notification: %f %f %f' %
                           (current_time, elapsed, next_message.wakeup_time))
                self.debug(str(next_message))
                if eq_rounded(current_time + elapsed,
                              next_message.wakeup_time):
                    self.debug("Notification ready")
                    bat_notification = next_message.notification
                    ob_information = OBInformation(
                        contract=self.contract,
                        best_ask=self.bid_ask_table.queue_observer.best_ask(),
                        best_bid=self.bid_ask_table.queue_observer.best_bid())
                    ob_notification = OBNotificationCreator.create_from_batable_notification(
                        bat_notification, ob_information)
                    output[out_port] = MessageForJournal(
                        current_time + elapsed, ob_notification)
                else:
                    self.debug(
                        "Notification not ready: %f %f %f" %
                        (current_time, elapsed, next_message.wakeup_time))
                    heapq.heappush(
                        self.next_notification_delivery[self.contract],
                        next_message)

        self.debug("Emit output = %s" % str(output))
        return output
 def output_function(self, current_time, elapsed):
     output = {}
     for output_port in self.output_ports_map.keys():
         self.debug("Seach port %s" % output_port)
         self.debug("%s" % str(self.next_messages_delivery))
         messages = self.next_messages_delivery[output_port]
         if len(messages) > 0:
             next_message = heapq.heappop(messages)
             assert_leq_rounded(current_time + elapsed, next_message.wakeup_time)
             self.debug("Check current_time + elapsed == next_message.wakup_time")
             if eq_rounded(current_time + elapsed, next_message.wakeup_time):
                 # self.debug("current_time + elapsed == next_message.wakeup_time")
                 external_message = next_message.message
                 external_message.set_time_sent(current_time + elapsed)
                 # Output through right port
                 output[self.output_ports_map[output_port]] = external_message
             else:
                 self.debug("%f %f %f" % (current_time, elapsed, next_message.wakeup_time))
     self.debug("Emit output = %s" % str(output))
     return output
    def output_function(self, current_time, elapsed):
        output = {}
        for output_port in ['out_next', 'out_notify_order']:
            self.debug("Seach port %s" % output_port)
            self.debug("%s" % str(self.next_messages_delivery))
            messages = self.next_messages_delivery[output_port]
            if len(messages) > 0:
                next_message = heapq.heappop(messages)
                assert (current_time + elapsed <= next_message.wakeup_time)
                if eq_rounded(current_time + elapsed,
                              next_message.wakeup_time):
                    self.debug(
                        "current_time + elapsed == next_message.wakeup_time")
                    external_message = next_message.message
                    external_message.set_time_sent(current_time + elapsed)
                    output[output_port] = external_message

                else:
                    self.debug(
                        "%f %f %f" %
                        (current_time, elapsed, next_message.wakeup_time))
        self.debug("Emit output = %s" % str(output))
        return output