Пример #1
0
 def fail(self, sid, amount):
     """
     Raise a TradingControlViolation with information about the failure.
     """
     raise TradingControlViolation(sid=sid,
                                   amount=amount,
                                   constraint=repr(self))
Пример #2
0
 def fail(self, asset, amount, datetime):
     """
     Raise a TradingControlViolation with information about the failure.
     """
     raise TradingControlViolation(asset=asset,
                                   amount=amount,
                                   datetime=datetime,
                                   constraint=repr(self))
Пример #3
0
    def fail(self, asset, amount, datetime, metadata=None):
        """
        Raise a TradingControlViolation with information about the failure.

        If dynamic information should be displayed as well, pass it in via
        `metadata`.
        """
        constraint = repr(self)
        if metadata:
            constraint = "{constraint} (Metadata: {metadata})".format(
                constraint=constraint, metadata=metadata)
        raise TradingControlViolation(asset=asset,
                                      amount=amount,
                                      datetime=datetime,
                                      constraint=constraint)
Пример #4
0
    def handle_violation(self, asset, amount, datetime, metadata=None):
        """
        Handle a TradingControlViolation, either by raising or logging and
        error with information about the failure.

        If dynamic information should be displayed as well, pass it in via
        `metadata`.
        """
        constraint = self._constraint_msg(metadata)

        if self.on_error == 'fail':
            raise TradingControlViolation(
                asset=asset,
                amount=amount,
                datetime=datetime,
                constraint=constraint)
        elif self.on_error == 'log':
            log.error("Order for {amount} shares of {asset} at {dt} "
                      "violates trading constraint {constraint}",
                      amount=amount, asset=asset, dt=datetime,
                      constraint=constraint)