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: Locks funds for specified order.
  
  Parameters
  ----------
  quantity : `Quantity`
      The amount of funds to lock for the order.
  order : `Order`
      The order funds will be locked for.
  reason : str
      The reason for locking funds.
  
  Returns
  -------
  `Quantity`
      The locked quantity for `order`.
  
  Raises
  ------
  DoubleLockedQuantity
      Raised if the given amount is already a locked quantity.
  InsufficientFunds
      Raised if amount is greater the current balance.
docstr_tok: ["Locks","funds","for","specified","order",".","Parameters","--","--","--","--","--","quantity",":","`","Quantity","`","The","amount","of","funds","to","lock","for","the","order",".","order",":","`","Order","`","The","order","funds","will","be","locked","for",".","reason",":","str","The","reason","for","locking","funds",".","Returns","--","--","--","-","`","Quantity","`","The","locked","quantity","for","`","order","`",".","Raises","--","--","--","DoubleLockedQuantity","Raised","if","the","given","amount","is","already","a","locked","quantity",".","InsufficientFunds","Raised","if","amount","is","greater","the","current","balance","."]
code: def lock(self, quantity, order: "Order", reason: str) -> "Quantity":
      """Locks funds for specified order.
  
      Parameters
      ----------
      quantity : `Quantity`
          The amount of funds to lock for the order.
      order : `Order`
          The order funds will be locked for.
      reason : str
          The reason for locking funds.
  
      Returns
      -------
      `Quantity`
          The locked quantity for `order`.
  
      Raises
      ------
      DoubleLockedQuantity
          Raised if the given amount is already a locked quantity.
      InsufficientFunds
          Raised if amount is greater the current balance.
      """
      if quantity.is_locked:
          raise DoubleLockedQuantity(quantity)
  
      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
  
      quantity = quantity.lock_for(order.path_id)
  
      if quantity.path_id not in self._locked:
          self._locked[quantity.path_id] = quantity
      else:
          self._locked[quantity.path_id] += quantity
  
      self._locked[quantity.path_id] = self._locked[
          quantity.path_id
      ].quantize()
      self.balance = self.balance.quantize()
  
      self.ledger.commit(
          wallet=self,
          quantity=quantity,
          source="{}:{}/free".format(
              self.exchange.name, self.instrument
          ),
          target="{}:{}/locked".format(
              self.exchange.name, self.instrument
          ),
          memo="LOCK ({})".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 5 for calling the Wallet obj's underlying member method code with example usage: obj.lock(quantity, order, reason) and returns: quantity