class_docstr: TradingControl representing a limit on the maximum position size that can
  be held by an algo for a given asset.
class_docstr_tok: ["TradingControl","representing","a","limit","on","the","maximum","position","size","that","can","be","held","by","an","algo","for","a","given","asset","."]
docstr: Fail if the given order would cause the magnitude of our position to be
  greater in shares than self.max_shares or greater in dollar value than
  self.max_notional.
docstr_tok: ["Fail","if","the","given","order","would","cause","the","magnitude","of","our","position","to","be","greater","in","shares","than","self.max_shares","or","greater","in","dollar","value","than","self.max_notional","."]
code: def validate(
      self, asset, amount, portfolio, algo_datetime, algo_current_data
  ):
      """
      Fail if the given order would cause the magnitude of our position to be
      greater in shares than self.max_shares or greater in dollar value than
      self.max_notional.
      """
  
      if self.asset is not None and self.asset != asset:
          return
  
      current_share_count = portfolio.positions[asset].amount
      shares_post_order = current_share_count + amount
  
      too_many_shares = (
          self.max_shares is not None
          and abs(shares_post_order) > self.max_shares
      )
      if too_many_shares:
          self.handle_violation(asset, amount, algo_datetime)
  
      current_price = algo_current_data.current(asset, "price")
      value_post_order = shares_post_order * current_price
  
      too_much_value = (
          self.max_notional is not None
          and abs(value_post_order) > self.max_notional
      )
  
      if too_much_value:
          self.handle_violation(asset, amount, algo_datetime)
  
imports: import abc
  import logbook
  import pandas
  from six import with_metaclass
  from catalyst.errors import AccountControlViolation, TradingControlViolation
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 2 for calling the MaxPositionSize obj's underlying member method code with example usage: obj.validate(asset, amount, portfolio, algo_datetime, algo_current_data) without return types