class_docstr: Base executor for trading
docstr: Parameters
  ----------
  time_per_step : str
      trade time per trading step, used for generate the trade calendar
  show_indicator: bool, optional
      whether to show indicators, :
      - 'pa', the price advantage
      - 'pos', the positive rate
      - 'ffr', the fulfill rate
  indicator_config: dict, optional
      config for calculating trade indicator, including the following fields:
      - 'show_indicator': whether to show indicators, optional, default by False. The indicators includes
          - 'pa', the price advantage
          - 'pos', the positive rate
          - 'ffr', the fulfill rate
      - 'pa_config': config for calculating price advantage(pa), optional
          - 'base_price': the based price than which the trading price is advanced, Optional, default by 'twap'
              - If 'base_price' is 'twap', the based price is the time weighted average price
              - If 'base_price' is 'vwap', the based price is the volume weighted average price
          - 'weight_method': weighted method when calculating total trading pa by different orders' pa in each
              step, optional, default by 'mean'
              - If 'weight_method' is 'mean', calculating mean value of different orders' pa
              - If 'weight_method' is 'amount_weighted', calculating amount weighted average value of different
                  orders' pa
              - If 'weight_method' is 'value_weighted', calculating value weighted average value of different
                  orders' pa
      - 'ffr_config': config for calculating fulfill rate(ffr), optional
          - 'weight_method': weighted method when calculating total trading ffr by different orders' ffr in each
              step, optional, default by 'mean'
              - If 'weight_method' is 'mean', calculating mean value of different orders' ffr
              - If 'weight_method' is 'amount_weighted', calculating amount weighted average value of different
                  orders' ffr
              - If 'weight_method' is 'value_weighted', calculating value weighted average value of different
                  orders' ffr
      Example:
          {
              'show_indicator': True,
              'pa_config': {
                  "agg": "twap",  # "vwap"
                  "price": "$close", # default to use deal price of the exchange
              },
              'ffr_config':{
                  'weight_method': 'value_weighted',
              }
          }
  generate_portfolio_metrics : bool, optional
      whether to generate portfolio_metrics, by default False
  verbose : bool, optional
      whether to print trading info, by default False
  track_data : bool, optional
      whether to generate trade_decision, will be used when training rl agent
      - If `self.track_data` is true, when making data for training, the input `trade_decision` of `execute` will
          be generated by `collect_data`
      - Else,  `trade_decision` will not be generated
  
  trade_exchange : Exchange
      exchange that provides market info, used to generate portfolio_metrics
      - If generate_portfolio_metrics is None, trade_exchange will be ignored
      - Else If `trade_exchange` is None, self.trade_exchange will be set with common_infra
  
  common_infra : CommonInfrastructure, optional:
      common infrastructure for backtesting, may including:
      - trade_account : Account, optional
          trade account for trading
      - trade_exchange : Exchange, optional
          exchange that provides market info
  
  settle_type : str
      Please refer to the docs of BasePosition.settle_start
docstr_tok: ["Parameters","--","--","--","--","--","time_per_step",":","str","trade","time","per","trading","step",",","used","for","generate","the","trade","calendar","show_indicator",":","bool",",","optional","whether","to","show","indicators",",",":","-","'pa","'",",","the","price","advantage","-","'pos","'",",","the","positive","rate","-","'ffr","'",",","the","fulfill","rate","indicator_config",":","dict",",","optional","config","for","calculating","trade","indicator",",","including","the","following","fields",":","-","'show_indicator","'",":","whether","to","show","indicators",",","optional",",","default","by","False",".","The","indicators","includes","-","'pa","'",",","the","price","advantage","-","'pos","'",",","the","positive","rate","-","'ffr","'",",","the","fulfill","rate","-","'pa_config","'",":","config","for","calculating","price","advantage","(","pa",")",",","optional","-","'base_price","'",":","the","based","price","than","which","the","trading","price","is","advanced",",","Optional",",","default","by","'twap'","-","If","'base_price","'","is","'twap","'",",","the","based","price","is","the","time","weighted","average","price","-","If","'base_price","'","is","'vwap","'",",","the","based","price","is","the","volume","weighted","average","price","-","'weight_method","'",":","weighted","method","when","calculating","total","trading","pa","by","different","orders","'","pa","in","each","step",",","optional",",","default","by","'mean'","-","If","'weight_method","'","is","'mean","'",",","calculating","mean","value","of","different","orders","'","pa","-","If","'weight_method","'","is","'amount_weighted","'",",","calculating","amount","weighted","average","value","of","different","orders","'","pa","-","If","'weight_method","'","is","'value_weighted","'",",","calculating","value","weighted","average","value","of","different","orders","'","pa","-","'ffr_config","'",":","config","for","calculating","fulfill","rate","(","ffr",")",",","optional","-","'weight_method","'",":","weighted","method","when","calculating","total","trading","ffr","by","different","orders","'","ffr","in","each","step",",","optional",",","default","by","'mean'","-","If","'weight_method","'","is","'mean","'",",","calculating","mean","value","of","different","orders","'","ffr","-","If","'weight_method","'","is","'amount_weighted","'",",","calculating","amount","weighted","average","value","of","different","orders","'","ffr","-","If","'weight_method","'","is","'value_weighted","'",",","calculating","value","weighted","average","value","of","different","orders","'","ffr","Example",":","{","'show_indicator","'",":","True",",","'pa_config","'",":","{","``","agg","''",":","``","twap","''",",","#","``","vwap","''","``","price","''",":","``","$","close","''",",","#","default","to","use","deal","price","of","the","exchange","}",",","'ffr_config","'",":","{","'weight_method","'",":","'value_weighted","'",",","}","}","generate_portfolio_metrics",":","bool",",","optional","whether","to","generate","portfolio_metrics",",","by","default","False","verbose",":","bool",",","optional","whether","to","print","trading","info",",","by","default","False","track_data",":","bool",",","optional","whether","to","generate","trade_decision",",","will","be","used","when","training","rl","agent","-","If","`","self.track_data","`","is","true",",","when","making","data","for","training",",","the","input","`","trade_decision","`","of","`","execute","`","will","be","generated","by","`","collect_data","`","-","Else",",","`","trade_decision","`","will","not","be","generated","trade_exchange",":","Exchange","exchange","that","provides","market","info",",","used","to","generate","portfolio_metrics","-","If","generate_portfolio_metrics","is","None",",","trade_exchange","will","be","ignored","-","Else","If","`","trade_exchange","`","is","None",",","self.trade_exchange","will","be","set","with","common_infra","common_infra",":","CommonInfrastructure",",","optional",":","common","infrastructure","for","backtesting",",","may","including",":","-","trade_account",":","Account",",","optional","trade","account","for","trading","-","trade_exchange",":","Exchange",",","optional","exchange","that","provides","market","info","settle_type",":","str","Please","refer","to","the","docs","of","BasePosition.settle_start"]
code: def __init__(
      self,
      time_per_step: str,
      start_time: Union[str, pd.Timestamp] = None,
      end_time: Union[str, pd.Timestamp] = None,
      indicator_config: dict = {},
      generate_portfolio_metrics: bool = False,
      verbose: bool = False,
      track_data: bool = False,
      trade_exchange: Exchange | None = None,
      common_infra: CommonInfrastructure | None = None,
      settle_type: str = BasePosition.ST_NO,
      **kwargs: Any,
  ) -> None:
      """
      Parameters
      ----------
      time_per_step : str
          trade time per trading step, used for generate the trade calendar
      show_indicator: bool, optional
          whether to show indicators, :
          - 'pa', the price advantage
          - 'pos', the positive rate
          - 'ffr', the fulfill rate
      indicator_config: dict, optional
          config for calculating trade indicator, including the following fields:
          - 'show_indicator': whether to show indicators, optional, default by False. The indicators includes
              - 'pa', the price advantage
              - 'pos', the positive rate
              - 'ffr', the fulfill rate
          - 'pa_config': config for calculating price advantage(pa), optional
              - 'base_price': the based price than which the trading price is advanced, Optional, default by 'twap'
                  - If 'base_price' is 'twap', the based price is the time weighted average price
                  - If 'base_price' is 'vwap', the based price is the volume weighted average price
              - 'weight_method': weighted method when calculating total trading pa by different orders' pa in each
                  step, optional, default by 'mean'
                  - If 'weight_method' is 'mean', calculating mean value of different orders' pa
                  - If 'weight_method' is 'amount_weighted', calculating amount weighted average value of different
                      orders' pa
                  - If 'weight_method' is 'value_weighted', calculating value weighted average value of different
                      orders' pa
          - 'ffr_config': config for calculating fulfill rate(ffr), optional
              - 'weight_method': weighted method when calculating total trading ffr by different orders' ffr in each
                  step, optional, default by 'mean'
                  - If 'weight_method' is 'mean', calculating mean value of different orders' ffr
                  - If 'weight_method' is 'amount_weighted', calculating amount weighted average value of different
                      orders' ffr
                  - If 'weight_method' is 'value_weighted', calculating value weighted average value of different
                      orders' ffr
          Example:
              {
                  'show_indicator': True,
                  'pa_config': {
                      "agg": "twap",  # "vwap"
                      "price": "$close", # default to use deal price of the exchange
                  },
                  'ffr_config':{
                      'weight_method': 'value_weighted',
                  }
              }
      generate_portfolio_metrics : bool, optional
          whether to generate portfolio_metrics, by default False
      verbose : bool, optional
          whether to print trading info, by default False
      track_data : bool, optional
          whether to generate trade_decision, will be used when training rl agent
          - If `self.track_data` is true, when making data for training, the input `trade_decision` of `execute` will
              be generated by `collect_data`
          - Else,  `trade_decision` will not be generated
  
      trade_exchange : Exchange
          exchange that provides market info, used to generate portfolio_metrics
          - If generate_portfolio_metrics is None, trade_exchange will be ignored
          - Else If `trade_exchange` is None, self.trade_exchange will be set with common_infra
  
      common_infra : CommonInfrastructure, optional:
          common infrastructure for backtesting, may including:
          - trade_account : Account, optional
              trade account for trading
          - trade_exchange : Exchange, optional
              exchange that provides market info
  
      settle_type : str
          Please refer to the docs of BasePosition.settle_start
      """
      self.time_per_step = time_per_step
      self.indicator_config = indicator_config
      self.generate_portfolio_metrics = generate_portfolio_metrics
      self.verbose = verbose
      self.track_data = track_data
      self._trade_exchange = trade_exchange
      self.level_infra = LevelInfrastructure()
      self.level_infra.reset_infra(
          common_infra=common_infra, executor=self
      )
      self._settle_type = settle_type
      self.reset(
          start_time=start_time,
          end_time=end_time,
          common_infra=common_infra,
      )
      if common_infra is None:
          get_module_logger("BaseExecutor").warning(
              f"`common_infra` is not set for {self}"
          )
  
      # record deal order amount in one day
      self.dealt_order_amount: Dict[str, float] = defaultdict(float)
      self.deal_day = None
  
imports: from __future__ import annotations
  import copy
  from abc import abstractmethod
  from collections import defaultdict
  from types import GeneratorType
  from typing import Any, Dict, Generator, List, Tuple, Union, cast
  import pandas
  from qlib.backtest.account import Account
  from qlib.backtest.position import BasePosition
  from qlib.log import get_module_logger
  from ..strategy.base import BaseStrategy
  from ..utils import init_instance_by_config
  from .decision import BaseTradeDecision, Order
  from .exchange import Exchange
  from .utils import CommonInfrastructure, LevelInfrastructure, TradeCalendarManager, get_start_end_idx
label_desc: Use image node_id 1 to create a new BaseExecutor object  with example: obj = BaseExecutor(time_per_step, start_time, end_time, indicator_config, generate_portfolio_metrics, verbose, track_data, trade_exchange, common_infra, settle_type)