Add hub perpetual-options hedge calculator tab and sizing formula.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1269,6 +1269,18 @@ class RollCalculatorBody(BaseModel):
|
||||
base: str = "ETH"
|
||||
|
||||
|
||||
class PerpOptionsCalculatorBody(BaseModel):
|
||||
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)
|
||||
perp_leverage: float = Field(gt=0)
|
||||
option_leverage: float = Field(gt=0)
|
||||
ct_mult: float = Field(default=0.01, gt=0)
|
||||
|
||||
|
||||
class CompareOptionLegBody(BaseModel):
|
||||
opt_type: str = "C"
|
||||
strike: float | None = None
|
||||
@@ -1350,6 +1362,26 @@ def api_calculator_roll(body: RollCalculatorBody):
|
||||
return {"ok": True, "data": data}
|
||||
|
||||
|
||||
@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
|
||||
|
||||
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,
|
||||
)
|
||||
if err:
|
||||
return JSONResponse({"ok": False, "msg": err}, status_code=400)
|
||||
return {"ok": True, "data": data}
|
||||
|
||||
|
||||
@app.post("/api/compare/calc")
|
||||
def api_compare_calc(body: CompareBody):
|
||||
from lib.hub.hub_compare_lib import run_compare
|
||||
|
||||
Reference in New Issue
Block a user