Add price/SL/TP validation for trade instructions

- Buy orders must satisfy: sl < price < tp
- Sell orders must satisfy: tp < price < sl
- Invalid instructions are rejected with message feedback
- Updated test suite with validation examples
- Updated documentation to clarify rules
This commit is contained in:
guaiwoluo2020
2026-03-04 23:14:41 +08:00
parent 2470283c22
commit 0c9cf048d2
6 changed files with 95 additions and 12 deletions
+7 -2
View File
@@ -58,10 +58,15 @@ def create_trader_routes(server: TradingServer) -> APIRouter:
}
```
"""
count = server.add_trade_instruction(instructions)
result = server.add_trade_instruction(instructions)
added = result.get("added", 0)
rejected = result.get("rejected", 0)
msg = f"已添加 {added} 条交易指令"
if rejected > 0:
msg += f"{rejected} 条因价格不合法被拒绝"
return {
"status": "ok",
"message": f"已添加 {count} 条交易指令"
"message": msg
}
@router.get("/query_pending_trades")