Prefer open direction from ATM vs spot (below=Call/short, above=Put/long).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-25 12:39:23 +08:00
parent ee0ec57f89
commit 79c074ec6c
6 changed files with 110 additions and 25 deletions
+24 -5
View File
@@ -76,19 +76,38 @@ class MarketSnapshot:
"ask_compare": {
"call_ask": self.call.ask if self.call else None,
"put_ask": self.put.ask if self.put else None,
"bias": _ask_bias(self.call, self.put),
"bias": _open_bias(self.pair, self.index_px, self.perp, self.call, self.put),
},
}
def _ask_bias(call: Quote | None, put: Quote | None) -> str:
"""卖一比价仅用于选向展示;相等则 wait。"""
def _open_bias(
pair: OptionPair | None,
index_px: float | None,
perp: Quote | None,
call: Quote | None,
put: Quote | None,
) -> str:
"""与开仓 decide 一致:先按 ATM 相对现价,贴平时再卖一比价。"""
mark = None
if index_px is not None and index_px > 0:
mark = float(index_px)
elif perp and perp.mark_px and perp.mark_px > 0:
mark = float(perp.mark_px)
elif perp and perp.bid and perp.ask:
mark = (float(perp.bid) + float(perp.ask)) / 2
if pair is not None and mark is not None:
diff = float(pair.strike) - mark
if diff < -1e-9:
return "strike_below_spot"
if diff > 1e-9:
return "strike_above_spot"
ca = call.ask if call else None
pa = put.ask if put else None
if ca is None or pa is None:
return "unknown"
if ca > pa:
return "call_ask_gt_put" # 永续多 + 期权空(腿待拍板)
return "call_ask_gt_put"
if ca < pa:
return "put_ask_gt_call" # 永续空 + 期权多(腿待拍板)
return "put_ask_gt_call"
return "equal"