code: def test_run(main=False):
      tr = trade.Trade(data=FakeData())
  
      order = bt.BuyOrder(
          data=FakeData(),
          size=0,
          price=1.0,
          exectype=bt.Order.Market,
          simulated=True,
      )
  
      commrate = 0.025
      size = 10
      price = 10.0
      value = size * price
      commission = value * commrate
  
      tr.update(
          order=order,
          size=size,
          price=price,
          value=value,
          commission=commission,
          pnl=0.0,
          comminfo=FakeCommInfo(),
      )
  
      assert not tr.isclosed
      assert tr.size == size
      assert tr.price == price
      # assert tr.value == value
      assert tr.commission == commission
      assert not tr.pnl
      assert tr.pnlcomm == tr.pnl - tr.commission
  
      upsize = -5
      upprice = 12.5
      upvalue = upsize * upprice
      upcomm = abs(value) * commrate
  
      tr.update(
          order=order,
          size=upsize,
          price=upprice,
          value=upvalue,
          commission=upcomm,
          pnl=0.0,
          comminfo=FakeCommInfo(),
      )
  
      assert not tr.isclosed
      assert tr.size == size + upsize
      assert (
          tr.price == price
      )  # size is being reduced, price must not change
      # assert tr.value == upvalue
      assert tr.commission == commission + upcomm
  
      size = tr.size
      price = tr.price
      commission = tr.commission
  
      upsize = 7
      upprice = 14.5
      upvalue = upsize * upprice
      upcomm = abs(value) * commrate
  
      tr.update(
          order=order,
          size=upsize,
          price=upprice,
          value=upvalue,
          commission=upcomm,
          pnl=0.0,
          comminfo=FakeCommInfo(),
      )
  
      assert not tr.isclosed
      assert tr.size == size + upsize
      assert tr.price == ((size * price) + (upsize * upprice)) / (
          size + upsize
      )
      # assert tr.value == upvalue
      assert tr.commission == commission + upcomm
  
      size = tr.size
      price = tr.price
      commission = tr.commission
  
      upsize = -size
      upprice = 12.5
      upvalue = upsize * upprice
      upcomm = abs(value) * commrate
  
      tr.update(
          order=order,
          size=upsize,
          price=upprice,
          value=upvalue,
          commission=upcomm,
          pnl=0.0,
          comminfo=FakeCommInfo(),
      )
  
      assert tr.isclosed
      assert tr.size == size + upsize
      assert (
          tr.price == price
      )  # no change ... we simple closed the operation
      # assert tr.value == upvalue
      assert tr.commission == commission + upcomm
  
file_path: backtrader/tests/test_trade.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import testcommon
  import backtrader
  from backtrader import trade
label_desc: Use image node_id 1 for calling a global function with example usage: test_run(main) without return types