feat: fix orphaned order detection and enhance automation UI

- Fixed Drift orders API to handle new object-based status format
- Updated cleanup API to properly detect orphaned TAKE PROFIT orders
- Changed status filtering from order.status === 0 to order.status.hasOwnProperty('open')

- Restored automation-v2 page with emergency stop functionality
- Added position monitor integration with real-time cleanup status
- Enhanced UI with emoji indicators and better status display
- Added emergency stop API endpoint for immediate trading halt

- Enhanced orphaned order detection for lingering SL/TP orders
- Added comprehensive debug logging for order processing
- Improved error handling and status reporting
- Real-time cleanup reporting in position monitor

 Verified working:
- Orders API correctly detects active orders with new Drift format
- Cleanup system successfully processes orphaned orders
- Position monitor shows accurate cleanup status
- Emergency stop functionality integrated
This commit is contained in:
mindesbunister
2025-07-26 20:07:40 +02:00
parent 11aec95d47
commit d38511f580
4 changed files with 380 additions and 46 deletions

View File

@@ -65,10 +65,30 @@ export async function POST() {
// Get current orders
const orders = userAccount.orders || []
const activeOrders = orders.filter(order =>
order.status === 0 && !order.baseAssetAmount.isZero()
)
// Filter for active orders - handle both numeric and object status formats
const activeOrders = orders.filter(order => {
if (order.baseAssetAmount.isZero()) return false
// Handle object-based status (new format)
if (typeof order.status === 'object') {
return order.status.hasOwnProperty('open')
}
// Handle numeric status (old format)
return order.status === 0
})
console.log(`📋 Raw orders in cleanup: ${orders.length}`);
orders.forEach((order, index) => {
if (!order.baseAssetAmount.isZero()) {
console.log(`📋 Cleanup Order ${index}:`, {
orderId: order.orderId,
status: order.status,
baseAssetAmount: order.baseAssetAmount.toString()
});
}
});
console.log(`📊 Analysis: ${activePositions.length} active positions, ${activeOrders.length} active orders`)
// Map positions by market index