code: def handle_data(context, data):
      context.i += 1
  
      starting_cash = context.portfolio.starting_cash
      target_hodl_value = context.TARGET_HODL_RATIO * starting_cash
      reserve_value = context.RESERVE_RATIO * starting_cash
  
      # Cancel any outstanding orders
      orders = get_open_orders(context.asset) or []
      for order in orders:
          cancel_order(order)
  
      # Stop buying after passing the reserve threshold
      cash = context.portfolio.cash
      if cash <= reserve_value:
          context.is_buying = False
  
      # Retrieve current asset price from pricing data
      price = data.current(context.asset, "price")
  
      # Check if still buying and could (approximately) afford another purchase
      if context.is_buying and cash > price:
          print("buying")
          # Place order to make position in asset equal to target_hodl_value
          order_target_value(
              context.asset,
              target_hodl_value,
              limit_price=price * 1.1,
          )
  
      record(
          price=price,
          volume=data.current(context.asset, "volume"),
          cash=cash,
          starting_cash=context.portfolio.starting_cash,
          leverage=context.account.leverage,
      )
  
imports: import pandas
  import matplotlib.pyplot
  from catalyst import run_algorithm
  from catalyst.api import order_target_value, symbol, record, cancel_order, get_open_orders
label_desc: Use image node_id 2 for calling a global function with example usage: handle_data(context, data) without return types