Use hub exchange instances for calculator contract precision.
Load enabled instances from settings, fetch market info via /api/hub/market, and apply exchange-specific amount and price precision in trend and roll calculators. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -831,7 +831,8 @@ class TrendCalculatorBody(BaseModel):
|
||||
add_upper: float = Field(gt=0)
|
||||
take_profit: float = Field(gt=0)
|
||||
dca_legs: int = Field(default=5, ge=1, le=20)
|
||||
contract_size: float = Field(default=1.0, gt=0)
|
||||
exchange_id: str = "0"
|
||||
base: str = "ETH"
|
||||
|
||||
|
||||
class RollAddLegBody(BaseModel):
|
||||
@@ -848,6 +849,25 @@ class RollCalculatorBody(BaseModel):
|
||||
take_profit: float = Field(gt=0)
|
||||
add_legs: list[RollAddLegBody] = Field(default_factory=list, max_length=3)
|
||||
legs_done: int = Field(default=0, ge=0, le=3)
|
||||
exchange_id: str = "0"
|
||||
base: str = "ETH"
|
||||
|
||||
|
||||
@app.get("/api/calculator/exchanges")
|
||||
def api_calculator_exchanges():
|
||||
from hub_calculator_market_lib import list_calculator_exchanges
|
||||
|
||||
return {"ok": True, "data": list_calculator_exchanges()}
|
||||
|
||||
|
||||
@app.get("/api/calculator/market")
|
||||
def api_calculator_market(exchange_id: str = "0", base: str = "ETH"):
|
||||
from hub_calculator_market_lib import get_calculator_market
|
||||
|
||||
data, err = get_calculator_market(exchange_id, base)
|
||||
if err:
|
||||
return JSONResponse({"ok": False, "msg": err}, status_code=400)
|
||||
return {"ok": True, "data": data}
|
||||
|
||||
|
||||
@app.post("/api/calculator/trend")
|
||||
@@ -864,7 +884,8 @@ def api_calculator_trend(body: TrendCalculatorBody):
|
||||
add_upper=body.add_upper,
|
||||
take_profit=body.take_profit,
|
||||
dca_legs=body.dca_legs,
|
||||
contract_size=body.contract_size,
|
||||
exchange_id=body.exchange_id,
|
||||
base=body.base,
|
||||
)
|
||||
if err:
|
||||
return JSONResponse({"ok": False, "msg": err}, status_code=400)
|
||||
@@ -884,6 +905,8 @@ def api_calculator_roll(body: RollCalculatorBody):
|
||||
take_profit=body.take_profit,
|
||||
add_legs=[leg.model_dump() for leg in body.add_legs],
|
||||
legs_done=body.legs_done,
|
||||
exchange_id=body.exchange_id,
|
||||
base=body.base,
|
||||
)
|
||||
if err:
|
||||
return JSONResponse({"ok": False, "msg": err}, status_code=400)
|
||||
|
||||
Reference in New Issue
Block a user