การเทรด
วงจรชีวิตออร์เดอร์
ออร์เดอร์เคลื่อนผ่านชุดสถานะที่กำหนดตั้งแต่ส่งจนกว่าจะ fill ยกเลิก หรือหมดอายุ ทุกสถานะสามารถสังเกตได้ผ่าน API
Endpoint ในบทนี้
สี่ endpoint ครอบคลุมวงจรชีวิตออร์เดอร์ทั้งหมด ทุก trading endpoint ต้องยืนยันตัวตนและมี scope ที่เหมาะสม
| Verb | Path | วัตถุประสงค์ |
|---|---|---|
| POST | /orders | ส่งออร์เดอร์ใหม่ |
| GET | /orders/:id | อ่านออร์เดอร์เดียวตาม ID |
| GET | /orders | แสดงออร์เดอร์ที่เปิดอยู่และปิดล่าสุด |
| POST | /orders/:id/cancel | ยกเลิกออร์เดอร์ที่เปิดอยู่ |
สถานะออร์เดอร์
ทุกออร์เดอร์มีค่าสถานะหนึ่งในนี้ การเปลี่ยนสถานะเป็นทางเดียว ยกเว้น partial-then-cancelled
| สถานะ | ความหมาย |
|---|---|
| pending | รอดำเนินการในสมุดคำสั่งซื้อขายรอออร์เดอร์ตรงข้าม |
| open | คำสั่งพักรอในสมุดคำสั่งซื้อขาย รอคำสั่งตรงข้าม |
| partial | Fill บางส่วน ส่วนที่เหลือยังรอดำเนินการ |
| filled | จับคู่ครบ หุ้นอยู่ในตำแหน่งของคุณ |
| cancelled | Cancelled by the user or by an admin action. The circuit breaker halts the market on a 30%+ price move but does not automatically cancel resting orders — they are paused until trading resumes (or you cancel them yourself). |
เหตุผลการปฏิเสธที่พบบ่อย
เมื่อออร์เดอร์ถูกปฏิเสธ response จะมี error code ที่คงที่เพื่อให้ client ตัดสินใจ
| Code | Symbol | ความหมาย |
|---|---|---|
| 3001 | ErrInsufficientBalance | ยอด USDC ของคุณต่ำเกินไปสำหรับออร์เดอร์ที่ราคาที่เสนอ |
| 5002 | ErrInvalidPrice | ราคาอยู่นอกช่วง tick ที่ตลาดรับหรือต่ำกว่า 0 / เกิน 1 |
| 5004 | ErrInvalidSide | side must be 1 (buy) or 2 (sell) — any other value is rejected. |
| 5007 | ErrMarketNotTrading | ตลาดหยุดชั่วคราว (circuit breaker, การตัดสิน หรือการบำรุงรักษา) |
| 5008 | ErrInsufficientPosition | you do not hold enough shares of this outcome to place this sell order. |
| 2025 | ErrTwoFactorRequired | 2FA is required for trading — enable it in Security settings before placing orders. |
แยกสาขาบนฟิลด์ `code` แบบตัวเลข ไม่ใช่บนข้อความ — ข้อความหันหน้าสู่ผู้ใช้และเปลี่ยนตาม locale และ copy ของแพลตฟอร์ม
Subscribe กับ order event แทนการ poll
WebSocket order channel ส่ง state transition แบบ real time ใช้กับ bot ที่ต้องตอบสนองต่อ fill — การ poll เหมาะสำหรับ dashboard แต่สิ้นเปลืองสำหรับ trading loop