Closed codermichele closed 7 months ago
Postion类的初始化方法
def __init__(self, order_book_id, direction, init_quantity=0, init_price=None): self._env = Environment.get_instance() self._order_book_id = order_book_id self._instrument = self._env.data_proxy.instrument(order_book_id) # type: Instrument self._direction = direction self._quantity = init_quantity self._old_quantity = init_quantity self._logical_old_quantity = 0 self._avg_price: float = init_price or 0 self._trade_cost: float = 0 self._transaction_cost: float = 0 self._prev_close: Optional[float] = init_price self._last_price: Optional[float] = init_price self._direction_factor = 1 if direction == POSITION_DIRECTION.LONG else -1
在Account中的
def get_position(self, order_book_id: str, direction: POSITION_DIRECTION = POSITION_DIRECTION.LONG) -> Position: """ 获取某个标的的持仓对象 :param order_book_id: 标的编号 :param direction: 持仓方向 """ try: return self._positions[order_book_id][direction] except KeyError: return Position(order_book_id, direction)
方法中实例化Position时“return Position(order_book_id, direction)”,并没有传入init_price,self._prev_close和self._last_price:应该都是None才对,可在调试时发现这两个变量都有实际的值,我想了解下这个值是怎么赋值进去的?
在 last_price 和 prev_close 两个 property 中第一次赋值。
Postion类的初始化方法
在Account中的
方法中实例化Position时“return Position(order_book_id, direction)”,并没有传入init_price,self._prev_close和self._last_price:应该都是None才对,可在调试时发现这两个变量都有实际的值,我想了解下这个值是怎么赋值进去的?