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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user