NautilusTrader Docs · ภาษาไทย

PositionClosed

PositionClosed บันทึก snapshot สุดท้ายของ position โดย ExecutionEngine จะส่ง event นี้ออกมาเมื่อ fill ทำให้ position กลายเป็น flat หรือเมื่อการแก้ไข fill ทำให้ position ที่ถูกแก้ไขอยู่ในสถานะปิด ดู จาก fill ถึง position Handler: on_position_closed

ฟิลด์

ดูตารางฟิลด์ทั้งหมดได้ที่ ฟิลด์ของ position event ฟิลด์ที่อธิบาย การปิดและผลลัพธ์สุดท้ายมีดังนี้:

Fieldคำอธิบาย
closing_order_idclient order ID ที่ปิด position (ถ้ามี)
peak_quantityปริมาณตามทิศทางสูงสุดที่ position เคยไปถึง
peak_qtyalias เพื่อความเข้ากันได้ของ peak_quantity
avg_px_closeราคาปิดเฉลี่ย (ถ้ามี)
realized_returnrealized return สุดท้ายของ position
realized_pnlrealized PnL สุดท้าย (ถ้ามี)
unrealized_pnlengine ตั้งค่าเป็นศูนย์
durationระยะเวลาทั้งหมดที่ position เปิดอยู่ หน่วย nanoseconds
ts_openedUNIX timestamp (nanoseconds) ตอนที่ position เปิด
ts_closedUNIX timestamp (nanoseconds) ตอนที่ position ปิด

เมื่อปิด position แล้ว side จะเป็น FLAT และ unrealized_pnl จะเป็นศูนย์

ตัวอย่าง

หมายเหตุ: ต้นฉบับมีเฉพาะตัวอย่าง Python (การอ่าน event ใน handler ของ strategy) จึงตัดออก

  • Events - ประเภทของ event, การ dispatch และลำดับเหตุการณ์จาก fill ถึง position
  • Positions - วงจรชีวิตของ position, การรวม และ PnL
  • Orders - order ที่ fill แล้วเปิดและปิด position

แปลจาก เอกสาร NautilusTrader © Nautech Systems Pty Ltd และผู้ร่วมพัฒนา เผยแพร่ภายใต้ LGPL-3.0 ฉบับแปลนี้ตัดเนื้อหาเฉพาะ Python ออกและเน้น Rust