/** * Pacifica 调试脚本 */ import 'dotenv/config' import { PacificaClient } from './src/exchanges/pacifica/PacificaClient' import { PacificaAdapter } from './src/exchanges/pacifica/PacificaAdapter' async function debugPacifica() { console.log('🔍 调试 Pacifica 连接...') // 1. 检查环境变量 console.log('📋 环境变量检查:') console.log(` PACIFICA_ACCOUNT: ${process.env.PACIFICA_ACCOUNT ? '设置了' : '未设置'}`) console.log(` PACIFICA_ACCOUNT_PRIVATE_KEY: ${process.env.PACIFICA_ACCOUNT_PRIVATE_KEY ? '设置了' : '未设置'}`) console.log(` PACIFICA_BASE_URL: ${process.env.PACIFICA_BASE_URL}`) console.log(` PACIFICA_WS_URL: ${process.env.PACIFICA_WS_URL}`) // 2. 创建 Pacifica Client console.log('\n🔧 创建 Pacifica Client...') const client = new PacificaClient({ baseUrl: process.env.PACIFICA_BASE_URL || 'https://api.pacifica.fi', wsUrl: process.env.PACIFICA_WS_URL || 'wss://ws.pacifica.fi/ws', account: process.env.PACIFICA_ACCOUNT, privateKey: process.env.PACIFICA_ACCOUNT_PRIVATE_KEY, agentWallet: process.env.PACIFICA_AGENT_WALLET, agentPrivateKey: process.env.PACIFICA_AGENT_PRIVATE_KEY, }) // 3. 测试基本 API 调用 try { console.log('\n🧪 测试 /api/v1/info 端点...') const info = await client.getPublic('/api/v1/info') console.log(`✅ 成功获取市场信息,共 ${info.length} 个交易对`) // 显示前5个交易对 console.log('📋 前5个交易对:') info.slice(0, 5).forEach((market: any) => { console.log(` ${market.symbol}: 价格精度=${market.tick_size}, 数量精度=${market.lot_size}`) }) } catch (error) { console.error('❌ API 调用失败:', error) return } // 4. 创建 Adapter 并测试 try { console.log('\n🔌 创建 Pacifica Adapter...') const adapter = new PacificaAdapter(client) console.log('🕐 测试时间同步...') const serverTime = await adapter.time() const localTime = Date.now() const skew = Math.abs(serverTime - localTime) console.log(`⏰ 服务器时间: ${new Date(serverTime).toISOString()}`) console.log(`⏰ 本地时间: ${new Date(localTime).toISOString()}`) console.log(`⏰ 时间偏差: ${skew}ms`) console.log('\n📊 测试符号列表...') const symbols = await adapter.symbols() console.log(`✅ 成功获取 ${symbols.length} 个交易符号`) console.log('\n💰 测试余额查询...') const balances = await adapter.balances() console.log(`✅ 成功获取余额信息,共 ${balances.length} 项`) balances.forEach(balance => { if (parseFloat(balance.total) > 0) { console.log(` ${balance.asset}: ${balance.total} (可用: ${balance.free})`) } }) } catch (error) { console.error('❌ Adapter 测试失败:', error) } } debugPacifica().catch(console.error)