test-balance.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * 测试余额获取
  3. * 用于诊断余额数据结构
  4. */
  5. import { PacificaSigningClient } from '../src/services/PacificaSigningClient';
  6. import Logger from '../src/utils/Logger';
  7. const logger = Logger.getInstance();
  8. async function testBalance() {
  9. console.log('🧪 测试余额获取...\n');
  10. // 从配置文件加载账户
  11. const accountsConfig = require('../config/accounts.json');
  12. const account1 = accountsConfig[0];
  13. const client = new PacificaSigningClient(
  14. account1.privateKey,
  15. 'wss://ws.pacifica.fi/ws'
  16. );
  17. try {
  18. console.log('📡 正在获取账户信息...');
  19. const accountInfo = await client.getAccountInfo(client.publicKey);
  20. console.log('\n📊 原始账户数据:');
  21. console.log(JSON.stringify(accountInfo, null, 2));
  22. console.log('\n💰 余额字段分析:');
  23. console.log('- accountInfo 的所有字段:', Object.keys(accountInfo));
  24. // 检查各种可能的余额字段
  25. const possibleFields = [
  26. 'balance',
  27. 'available',
  28. 'total',
  29. 'equity',
  30. 'free',
  31. 'used',
  32. 'locked',
  33. 'margin',
  34. 'wallet_balance',
  35. 'available_balance',
  36. 'total_balance'
  37. ];
  38. console.log('\n🔍 检查可能的余额字段:');
  39. for (const field of possibleFields) {
  40. if (accountInfo.hasOwnProperty(field)) {
  41. console.log(` ✅ ${field}: ${accountInfo[field]}`);
  42. }
  43. }
  44. // 检查嵌套对象
  45. console.log('\n📦 检查嵌套对象:');
  46. for (const key of Object.keys(accountInfo)) {
  47. const value = accountInfo[key];
  48. if (typeof value === 'object' && value !== null) {
  49. console.log(` ${key}:`, JSON.stringify(value, null, 4));
  50. }
  51. }
  52. } catch (error: any) {
  53. console.error('❌ 测试失败:', error.message);
  54. if (error.response) {
  55. console.error('Response data:', error.response.data);
  56. }
  57. }
  58. }
  59. testBalance().catch(console.error);