code: def test_on_fill_with_complex_order(
      mock_trade_class, mock_exchange_class
  ):
      exchange = mock_exchange_class.return_value
      exchange.options.max_trade_size = 1e6
      exchange.id = "fake_exchange_id"
      exchange.name = "bitfinex"
      exchange.quote_price = lambda pair: Decimal(7000.00)
  
      broker = Broker()
      broker.exchanges = [exchange]
  
      wallets = [
          Wallet(exchange, 10000 * USD),
          Wallet(exchange, 0 * BTC),
      ]
      portfolio = Portfolio(USD, wallets)
  
      side = TradeSide.BUY
  
      order = Order(
          step=0,
          exchange_pair=ExchangePair(exchange, USD / BTC),
          side=TradeSide.BUY,
          trade_type=TradeType.MARKET,
          quantity=5200.00 * USD,
          portfolio=portfolio,
          price=Decimal(7000.00),
      )
  
      risk_criteria = Stop("down", 0.03) ^ Stop("up", 0.02)
  
      risk_management = OrderSpec(
          side=TradeSide.SELL
          if side == TradeSide.BUY
          else TradeSide.BUY,
          trade_type=TradeType.MARKET,
          exchange_pair=ExchangePair(exchange, USD / BTC),
          criteria=risk_criteria,
      )
  
      order.add_order_spec(risk_management)
  
      order.attach(broker)
      order.execute()
  
      broker.executed[order.id] = order
  
      # Execute fake trade
      price = Decimal(7000.00)
      scale = order.price / price
      commission = 3.00 * USD
  
      base_size = scale * order.size - commission.size
  
      trade = mock_trade_class.return_value
      trade.order_id = order.id
      trade.size = base_size
      trade.quantity = base_size * USD
      trade.price = price
      trade.commission = commission
  
      base_wallet = portfolio.get_wallet(exchange.id, USD)
      quote_wallet = portfolio.get_wallet(exchange.id, BTC)
  
      base_size = trade.size + trade.commission.size
      quote_size = (order.price / trade.price) * (
          trade.size / trade.price
      )
  
      base_wallet.withdraw(
          quantity=Quantity(USD, size=base_size, path_id=order.path_id),
          reason="test",
      )
      quote_wallet.deposit(
          quantity=Quantity(
              BTC, size=quote_size, path_id=order.path_id
          ),
          reason="test",
      )
  
      assert trade.order_id in broker.executed.keys()
      assert trade not in broker.trades
      assert broker.unexecuted == []
  
      order.fill(trade)
  
      assert order.remaining == 0
      assert trade in broker.trades[order.id]
      assert broker.unexecuted != []
  
file_path: tensortrade/tests/tensortrade/unit/oms/orders/test_broker.py
imports: import pytest
  import unittest.mock
  from decimal import Decimal
  from tensortrade.oms.orders import Broker, OrderStatus, Order, OrderSpec, TradeSide, TradeType
  from tensortrade.oms.orders.criteria import Stop
  from tensortrade.oms.wallets import Wallet, Portfolio
  from tensortrade.oms.instruments import USD, BTC, Quantity, ExchangePair
label_desc: Use image node_id 7 for calling a global function with example usage: test_on_fill_with_complex_order(mock_trade_class, mock_exchange_class) without return types