code: def handle_violation(self, asset, amount, datetime, metadata=None):
          
          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)
docs: 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`.