Redesign roll calculator with auto first entry and chained add legs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-23 17:44:27 +08:00
parent 253d353206
commit d938bc6c59
6 changed files with 482 additions and 112 deletions
+12 -9
View File
@@ -834,16 +834,20 @@ class TrendCalculatorBody(BaseModel):
contract_size: float = Field(default=1.0, gt=0)
class RollAddLegBody(BaseModel):
add_price: float = Field(gt=0)
new_stop_loss: float = Field(gt=0)
class RollCalculatorBody(BaseModel):
direction: str = "long"
capital_usdt: float = Field(gt=0)
risk_percent: float = Field(gt=0, le=100)
qty_existing: float = Field(gt=0)
entry_existing: float = Field(gt=0)
entry_price: float = Field(gt=0)
stop_loss: float = Field(gt=0)
take_profit: float = Field(gt=0)
add_price: float = Field(gt=0)
new_stop_loss: float = Field(gt=0)
legs_done: int = Field(default=0, ge=0, le=10)
add_legs: list[RollAddLegBody] = Field(default_factory=list, max_length=3)
legs_done: int = Field(default=0, ge=0, le=3)
@app.post("/api/calculator/trend")
@@ -875,11 +879,10 @@ def api_calculator_roll(body: RollCalculatorBody):
direction=body.direction,
capital_usdt=body.capital_usdt,
risk_percent=body.risk_percent,
qty_existing=body.qty_existing,
entry_existing=body.entry_existing,
entry_price=body.entry_price,
stop_loss=body.stop_loss,
take_profit=body.take_profit,
add_price=body.add_price,
new_stop_loss=body.new_stop_loss,
add_legs=[leg.model_dump() for leg in body.add_legs],
legs_done=body.legs_done,
)
if err: