Add ratio-to-move-points mode for hub perpetual-options calculator.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+34
-13
@@ -1270,15 +1270,18 @@ class RollCalculatorBody(BaseModel):
|
||||
|
||||
|
||||
class PerpOptionsCalculatorBody(BaseModel):
|
||||
calc_mode: str = "size"
|
||||
base: str = "ETH"
|
||||
spot: float = Field(gt=0)
|
||||
capital_usdt: float = Field(gt=0)
|
||||
target_profit_u: float = Field(ge=0)
|
||||
move_mode: str = "points"
|
||||
move_value: float = Field(gt=0)
|
||||
move_value: float | None = None
|
||||
perp_leverage: float = Field(gt=0)
|
||||
option_leverage: float = Field(gt=0)
|
||||
ct_mult: float = Field(default=0.01, gt=0)
|
||||
ratio_perp: float = Field(default=1.0, gt=0)
|
||||
ratio_opt: float = Field(default=2.0, gt=0)
|
||||
|
||||
|
||||
class CompareOptionLegBody(BaseModel):
|
||||
@@ -1364,19 +1367,37 @@ def api_calculator_roll(body: RollCalculatorBody):
|
||||
|
||||
@app.post("/api/calculator/perp-options")
|
||||
def api_calculator_perp_options(body: PerpOptionsCalculatorBody):
|
||||
from lib.hub.hub_perp_options_calc_lib import calc_perp_options_hedge
|
||||
from lib.hub.hub_perp_options_calc_lib import calc_perp_options
|
||||
|
||||
data, err = calc_perp_options_hedge(
|
||||
base=body.base,
|
||||
spot=body.spot,
|
||||
capital_usdt=body.capital_usdt,
|
||||
target_profit_u=body.target_profit_u,
|
||||
move_mode=body.move_mode,
|
||||
move_value=body.move_value,
|
||||
perp_leverage=body.perp_leverage,
|
||||
option_leverage=body.option_leverage,
|
||||
ct_mult=body.ct_mult,
|
||||
)
|
||||
mode = (body.calc_mode or "size").strip().lower()
|
||||
if mode in ("points", "ratio", "move"):
|
||||
data, err = calc_perp_options(
|
||||
calc_mode="points",
|
||||
base=body.base,
|
||||
spot=body.spot,
|
||||
capital_usdt=body.capital_usdt,
|
||||
target_profit_u=body.target_profit_u,
|
||||
perp_leverage=body.perp_leverage,
|
||||
option_leverage=body.option_leverage,
|
||||
ct_mult=body.ct_mult,
|
||||
ratio_perp=body.ratio_perp,
|
||||
ratio_opt=body.ratio_opt,
|
||||
)
|
||||
else:
|
||||
if body.move_value is None or body.move_value <= 0:
|
||||
return JSONResponse({"ok": False, "msg": "请填写波动数值"}, status_code=400)
|
||||
data, err = calc_perp_options(
|
||||
calc_mode="size",
|
||||
base=body.base,
|
||||
spot=body.spot,
|
||||
capital_usdt=body.capital_usdt,
|
||||
target_profit_u=body.target_profit_u,
|
||||
move_mode=body.move_mode,
|
||||
move_value=body.move_value,
|
||||
perp_leverage=body.perp_leverage,
|
||||
option_leverage=body.option_leverage,
|
||||
ct_mult=body.ct_mult,
|
||||
)
|
||||
if err:
|
||||
return JSONResponse({"ok": False, "msg": err}, status_code=400)
|
||||
return {"ok": True, "data": data}
|
||||
|
||||
Reference in New Issue
Block a user