learning_ai_invt_trdg/backend/src/scripts
2026-04-04 11:18:21 -07:00
..
backfillTradeIds.ts feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
cleanupStaleOrders.ts feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
README.md feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
reconcileTradeLifecycle.ts feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
revertExpiredOrders.ts feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00
verifyWebsocketContract.ts feat: scaffold trading monorepo foundation 2026-04-04 11:18:21 -07:00

Utility Scripts

This directory contains utility scripts for maintenance and troubleshooting.

Available Scripts

cleanupStaleOrders.ts

Purpose: Manually clean up very old stale orders (>24 hours) by marking them as 'unknown'.

When to use:

  • After a prolonged bot outage
  • When you have many old pending_new orders
  • As part of database maintenance

How to run:

npm run cleanup-stale-orders

What it does:

  1. Queries database for orders in pending_new status older than 24 hours
  2. Marks each order as unknown status
  3. Logs summary of how many orders were updated

Example output:

[Cleanup] Starting stale order cleanup...
[Cleanup] Found 15 orders older than 24 hours in pending_new status
[Cleanup] Marking order abc123 as 'unknown' (age: 48h, symbol: BTC/USDT)
[Cleanup] Marking order def456 as 'unknown' (age: 36h, symbol: ETH/USDT)
...
[Cleanup] ✅ Cleanup complete! Updated 15 stale orders to 'unknown' status

Note: This is a one-time operation. For ongoing sync, use the automatic OrderStatusSyncService (runs every 5 minutes).

Adding New Scripts

To add a new utility script:

  1. Create a new .ts file in this directory
  2. Add the script entry to package.json:
    "scripts": {
      "your-script": "tsx src/scripts/yourScript.ts"
    }
    
  3. Document it in this README