Skip to content

update函数,更新持仓状态,没有新的开仓event,也会更新 last_event #139

@PingFeng233

Description

@PingFeng233

czsc/objects.py

 # 当有新的开仓 event 发生,更新 last_event
  if op in [Operate.LO, Operate.SO]:
      self.last_event = {'dt': dt, 'bid': bid, 'price': price, 'op': op, 'op_desc': op_desc}

这段代码是否应该判断一下有无持仓,只要开仓之后last_event会一直更新,会导致下面判断止损的代码price 和 self.last_event['price']的值是一样的

# 多头止损
  if price / self.last_event['price'] - 1 < -self.stop_loss / 10000:
      self.pos = 0
      self.operates.append(__create_operate(Operate.LE, f"平多@{self.stop_loss}BP止损"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions