#!/usr/bin/env npx tsx import { PacificaProxyClient } from './src/exchanges/pacifica/PacificaProxyClient.js' import { logger } from './src/utils/logger.js' async function debugOpenOrders() { logger.info('🔍 调试 Pacifica Open Orders API 响应格式') try { // 创建 Pacifica 客户端 const client = new PacificaProxyClient({ privateKey: process.env.PACIFICA_PRIVATE_KEY_1 || '', account: process.env.PACIFICA_ACCOUNT_1 || '3v2fE8y6uPVu5pmNCpmygpGNgdP3kGL3SMoVa86uvLLu', }) // 禁用WebSocket,使用HTTP client.setWebSocketEnabled(false) logger.info('📞 调用 getOpenOrders API...') const result = await client.getOpenOrders() console.log('📊 API 原始响应:') console.log(' type:', typeof result) console.log(' isArray:', Array.isArray(result)) console.log(' keys:', result && typeof result === 'object' ? Object.keys(result) : 'not an object') console.log(' resultLength:', Array.isArray(result) ? result.length : 'not an array') // 深度分析响应结构 if (result && typeof result === 'object') { logger.info('🔬 响应结构详细分析:') // 检查是否有 data 字段 if (result.data) { console.log('✅ 响应包含 data 字段:') console.log(' dataType:', typeof result.data) console.log(' isDataArray:', Array.isArray(result.data)) console.log(' dataKeys:', result.data && typeof result.data === 'object' ? Object.keys(result.data) : 'not an object') console.log(' dataLength:', Array.isArray(result.data) ? result.data.length : 'not an array') // 如果 data 是数组,显示第一个元素结构 if (Array.isArray(result.data) && result.data.length > 0) { console.log('📋 第一个订单的结构:') console.log(' firstOrderKeys:', Object.keys(result.data[0])) console.log(' firstOrderSample:', JSON.stringify(result.data[0]).substring(0, 300)) } } // 检查是否直接是订单数组 if (Array.isArray(result)) { logger.info('✅ 响应直接是数组:', { length: result.length, firstOrderKeys: result.length > 0 ? Object.keys(result[0]) : 'empty array', }) } // 检查其他可能的字段 const possibleOrderFields = ['orders', 'openOrders', 'open_orders', 'order', 'result'] for (const field of possibleOrderFields) { if (result[field]) { logger.info(`✅ 发现可能的订单字段 "${field}":`, { type: typeof result[field], isArray: Array.isArray(result[field]), length: Array.isArray(result[field]) ? result[field].length : 'not an array', }) } } // 打印完整响应(前1000字符) console.log('📝 完整响应预览:') console.log(JSON.stringify(result, null, 2).substring(0, 1000) + '...') } } catch (error: any) { logger.error('❌ 调试失败:', { error: error.message, stack: error.stack, }) } } // 立即执行 debugOpenOrders().then(() => { logger.info('🎯 调试完成') process.exit(0) }).catch(error => { logger.error('🚨 调试脚本执行失败:', error) process.exit(1) })