Beispiel #1
0
    def update_strategy_position_table_with_instrument_order(
            self, original_instrument_order: instrumentOrder,
            new_fill: tradeQuantity):
        """
        Alter the strategy position table according to new_fill value

        :param original_instrument_order:
        :return:
        """

        instrument_strategy = original_instrument_order.instrument_strategy

        current_position_as_int = self.diag_positions.get_current_position_for_instrument_strategy(
            instrument_strategy)
        trade_done_as_int = new_fill.as_single_trade_qty_or_error()
        if trade_done_as_int is missing_order:
            self.log.critical("Instrument orders can't be spread orders!")
            return failure

        new_position_as_int = current_position_as_int + trade_done_as_int

        self.db_strategy_position_data.update_position_for_instrument_strategy_object(
            instrument_strategy, new_position_as_int)

        log = original_instrument_order.log_with_attributes(self.log)
        log.msg(
            "Updated position of %s from %d to %d because of trade %s %d fill %s"
            % (str(instrument_strategy), current_position_as_int,
               new_position_as_int, str(original_instrument_order),
               original_instrument_order.order_id, str(new_fill)))

        return success
Beispiel #2
0
    def what_trade_is_possible_for_strategy_instrument(
            self, instrument_strategy: instrumentStrategy,
            proposed_trade: tradeQuantity) -> int:

        proposed_trade_as_int = proposed_trade.total_abs_qty()
        return self.data.db_trade_limit.what_trade_is_possible(
            instrument_strategy, proposed_trade_as_int)