| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /**
- * Pacifica API 详细调试脚本
- */
- import 'dotenv/config'
- async function testPacificaAPI() {
- console.log('🔍 调试 Pacifica API 连接...')
- const baseUrl = process.env.PACIFICA_BASE_URL || 'https://api.pacifica.fi'
- const testEndpoint = '/api/v1/info'
- const fullUrl = `${baseUrl}${testEndpoint}`
- console.log(`📡 测试 URL: ${fullUrl}`)
- // 测试1: 使用 fetch 直接调用,不设任何头
- console.log('\n🧪 测试1: 直接 fetch 调用,无请求头')
- try {
- const response = await fetch(fullUrl, {
- method: 'GET',
- })
- console.log(`📊 状态码: ${response.status}`)
- console.log(`📋 响应头:`)
- response.headers.forEach((value, key) => {
- console.log(` ${key}: ${value}`)
- })
- if (response.ok) {
- const data = await response.json()
- console.log(`✅ 成功! 获取到 ${Array.isArray(data) ? data.length : '未知数量'} 项数据`)
- } else {
- const text = await response.text()
- console.log(`❌ 失败: ${text.slice(0, 200)}`)
- }
- } catch (error) {
- console.error('❌ 测试1失败:', error)
- }
- // 测试2: 添加标准 User-Agent
- console.log('\n🧪 测试2: 添加 User-Agent')
- try {
- const response = await fetch(fullUrl, {
- method: 'GET',
- headers: {
- 'User-Agent': 'Pacifica-API-Client/1.0',
- },
- })
- console.log(`📊 状态码: ${response.status}`)
- if (response.ok) {
- const data = await response.json()
- console.log(`✅ 成功! 获取到 ${Array.isArray(data) ? data.length : '未知数量'} 项数据`)
- } else {
- const text = await response.text()
- console.log(`❌ 失败: ${text.slice(0, 200)}`)
- }
- } catch (error) {
- console.error('❌ 测试2失败:', error)
- }
- // 测试3: 添加更多标准头
- console.log('\n🧪 测试3: 添加标准 HTTP 头')
- try {
- const response = await fetch(fullUrl, {
- method: 'GET',
- headers: {
- 'User-Agent': 'Pacifica-API-Client/1.0',
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- })
- console.log(`📊 状态码: ${response.status}`)
- if (response.ok) {
- const data = await response.json()
- console.log(`✅ 成功! 获取到 ${Array.isArray(data) ? data.length : '未知数量'} 项数据`)
- // 显示前3个项目
- if (Array.isArray(data) && data.length > 0) {
- console.log('📋 前3个市场:')
- data.slice(0, 3).forEach((item: any) => {
- console.log(` ${item.symbol}: tick_size=${item.tick_size}, lot_size=${item.lot_size}`)
- })
- }
- } else {
- const text = await response.text()
- console.log(`❌ 失败: ${text.slice(0, 200)}`)
- }
- } catch (error) {
- console.error('❌ 测试3失败:', error)
- }
- // 测试4: 测试其他可能的端点
- console.log('\n🧪 测试4: 尝试其他端点')
- const alternativeEndpoints = ['/api/v1/markets', '/api/v1/market-info', '/info', '/markets']
- for (const endpoint of alternativeEndpoints) {
- const testUrl = `${baseUrl}${endpoint}`
- console.log(`\n🔍 测试端点: ${testUrl}`)
- try {
- const response = await fetch(testUrl, {
- method: 'GET',
- headers: {
- 'User-Agent': 'Pacifica-API-Client/1.0',
- Accept: 'application/json',
- },
- })
- console.log(`📊 状态码: ${response.status}`)
- if (response.ok) {
- const data = await response.json()
- console.log(`✅ 端点 ${endpoint} 可用! 数据类型: ${Array.isArray(data) ? 'array' : typeof data}`)
- if (Array.isArray(data)) {
- console.log(` 数组长度: ${data.length}`)
- }
- }
- } catch (error) {
- console.log(`❌ 端点 ${endpoint} 不可用`)
- }
- }
- // 测试5: 使用我们现有的 PacificaClient
- console.log('\n🧪 测试5: 使用现有的 PacificaClient')
- try {
- const { PacificaClient } = await import('./src/exchanges/pacifica/PacificaClient')
- 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,
- })
- console.log('🔧 PacificaClient 创建成功')
- const data = await client.getPublic<any>('/api/v1/info')
- console.log(`✅ PacificaClient 调用成功! 获取到 ${Array.isArray(data) ? data.length : '未知数量'} 项数据`)
- if (Array.isArray(data) && data.length > 0) {
- console.log('📋 前3个市场信息:')
- data.slice(0, 3).forEach((market: any) => {
- console.log(` ${market.symbol}: tick_size=${market.tick_size}, lot_size=${market.lot_size}`)
- })
- } else {
- console.log('📄 返回的数据结构:', JSON.stringify(data, null, 2))
- }
- } catch (error) {
- console.error('❌ 测试5失败:', error)
- }
- }
- testPacificaAPI().catch(console.error)
|