class_docstr: A wallet stores the balance of a specific instrument on a specific exchange.
  
  Parameters
  ----------
  exchange : `Exchange`
      The exchange associated with this wallet.
  balance : `Quantity`
      The initial balance quantity for the wallet.
docstr: Withdraws funds from the wallet.
  
  Parameters
  ----------
  quantity : `Quantity`
      The amount to withdraw from this wallet.
  reason : str
      The reason for withdrawing the amount.
  
  Returns
  -------
  `Quantity`
      The withdrawn amount.
docstr_tok: ["Withdraws","funds","from","the","wallet",".","Parameters","--","--","--","--","--","quantity",":","`","Quantity","`","The","amount","to","withdraw","from","this","wallet",".","reason",":","str","The","reason","for","withdrawing","the","amount",".","Returns","--","--","--","-","`","Quantity","`","The","withdrawn","amount","."]
code: def withdraw(self, quantity: "Quantity", reason: str) -> "Quantity":
      """Withdraws funds from the wallet.
  
      Parameters
      ----------
      quantity : `Quantity`
          The amount to withdraw from this wallet.
      reason : str
          The reason for withdrawing the amount.
  
      Returns
      -------
      `Quantity`
          The withdrawn amount.
      """
      if quantity.is_locked and self._locked.get(
          quantity.path_id, False
      ):
          locked_quantity = self._locked[quantity.path_id]
          if quantity > locked_quantity:
              if (quantity - locked_quantity) > Decimal(10) ** (
                  -self.instrument.precision + 2
              ):
                  raise InsufficientFunds(locked_quantity, quantity)
              else:
                  quantity = locked_quantity
          self._locked[quantity.path_id] -= quantity
  
      elif not quantity.is_locked:
          if quantity > self.balance:
              if (quantity - self.balance) > Decimal(10) ** (
                  -self.instrument.precision + 2
              ):
                  raise InsufficientFunds(self.balance, quantity)
              else:
                  quantity = self.balance
          self.balance -= quantity
  
      self.balance = self.balance.quantize()
  
      self.ledger.commit(
          wallet=self,
          quantity=quantity,
          source="{}:{}/locked".format(
              self.exchange.name, self.instrument
          ),
          target=self.exchange.name,
          memo="WITHDRAWAL ({})".format(reason),
      )
  
      return quantity
  
imports: from typing import Dict, Tuple
  from collections import namedtuple
  from decimal import Decimal
  import numpy
  from tensortrade.core import Identifiable
  from tensortrade.core.exceptions import InsufficientFunds, DoubleLockedQuantity, DoubleUnlockedQuantity, QuantityNotLocked
  from tensortrade.oms.instruments import Instrument, Quantity, ExchangePair
  from tensortrade.oms.orders import Order
  from tensortrade.oms.exchanges import Exchange
  from tensortrade.oms.wallets.ledger import Ledger
label_desc: Use image node_id 8 for calling the Wallet obj's underlying member method code with example usage: obj.withdraw(quantity, reason) and returns: quantity