123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**
- * 测试余额获取
- * 用于诊断余额数据结构
- */
- import { PacificaSigningClient } from '../src/services/PacificaSigningClient';
- import Logger from '../src/utils/Logger';
- const logger = Logger.getInstance();
- async function testBalance() {
- console.log('🧪 测试余额获取...\n');
- // 从配置文件加载账户
- const accountsConfig = require('../config/accounts.json');
- const account1 = accountsConfig[0];
- const client = new PacificaSigningClient(
- account1.privateKey,
- 'wss://ws.pacifica.fi/ws'
- );
- try {
- console.log('📡 正在获取账户信息...');
- const accountInfo = await client.getAccountInfo(client.publicKey);
- console.log('\n📊 原始账户数据:');
- console.log(JSON.stringify(accountInfo, null, 2));
- console.log('\n💰 余额字段分析:');
- console.log('- accountInfo 的所有字段:', Object.keys(accountInfo));
- // 检查各种可能的余额字段
- const possibleFields = [
- 'balance',
- 'available',
- 'total',
- 'equity',
- 'free',
- 'used',
- 'locked',
- 'margin',
- 'wallet_balance',
- 'available_balance',
- 'total_balance'
- ];
- console.log('\n🔍 检查可能的余额字段:');
- for (const field of possibleFields) {
- if (accountInfo.hasOwnProperty(field)) {
- console.log(` ✅ ${field}: ${accountInfo[field]}`);
- }
- }
- // 检查嵌套对象
- console.log('\n📦 检查嵌套对象:');
- for (const key of Object.keys(accountInfo)) {
- const value = accountInfo[key];
- if (typeof value === 'object' && value !== null) {
- console.log(` ${key}:`, JSON.stringify(value, null, 4));
- }
- }
- } catch (error: any) {
- console.error('❌ 测试失败:', error.message);
- if (error.response) {
- console.error('Response data:', error.response.data);
- }
- }
- }
- testBalance().catch(console.error);
|