- 1-minute data is pure market sampling, not trading signals - signalQualityVersion now null for timeframe='1' - Other timeframes still labeled with v9 - Prevents confusion in analytics/reporting
103 lines
3.5 KiB
TypeScript
103 lines
3.5 KiB
TypeScript
#!/usr/bin/env tsx
|
|
|
|
/**
|
|
* Test Drift v4 Integration
|
|
*
|
|
* Verifies connection to Drift Protocol and basic functionality
|
|
*/
|
|
|
|
import { initializeDriftService, getDriftService } from '../lib/drift/client'
|
|
import { getMergedConfig } from '../config/trading'
|
|
|
|
async function main() {
|
|
console.log('🧪 Testing Drift v4 Integration\n')
|
|
|
|
try {
|
|
// Test 1: Configuration
|
|
console.log('📋 Test 1: Configuration')
|
|
const config = getMergedConfig()
|
|
console.log('✅ Config loaded:')
|
|
console.log(` Position size: $${config.positionSize}`)
|
|
console.log(` Leverage: ${config.leverage}x`)
|
|
console.log(` Stop loss: ${config.stopLossPercent}%`)
|
|
console.log(` TP1: ${config.takeProfit1Percent}%`)
|
|
console.log(` TP2: ${config.takeProfit2Percent}%`)
|
|
console.log('')
|
|
|
|
// Test 2: Drift Connection
|
|
console.log('📡 Test 2: Drift Connection')
|
|
const drift = await initializeDriftService()
|
|
console.log('✅ Drift service initialized')
|
|
console.log(` Wallet: ${drift.getClient().wallet.publicKey.toString()}`)
|
|
console.log('')
|
|
|
|
// Test 3: Account Balance
|
|
console.log('💰 Test 3: USDC Balance')
|
|
const balance = await drift.getUSDCBalance()
|
|
console.log(`✅ USDC Balance: $${balance.toFixed(2)}`)
|
|
console.log('')
|
|
|
|
// Test 4: Account Health
|
|
console.log('💊 Test 4: Account Health')
|
|
const health = await drift.getAccountHealth()
|
|
console.log('✅ Account health:')
|
|
console.log(` Total collateral: $${health.totalCollateral.toFixed(2)}`)
|
|
console.log(` Total liability: $${health.totalLiability.toFixed(2)}`)
|
|
console.log(` Free collateral: $${health.freeCollateral.toFixed(2)}`)
|
|
console.log(` Margin ratio: ${health.marginRatio === Infinity ? '∞' : health.marginRatio.toFixed(2)}`)
|
|
console.log('')
|
|
|
|
// Test 5: Active Positions
|
|
console.log('📊 Test 5: Active Positions')
|
|
const positions = await drift.getAllPositions()
|
|
console.log(`✅ Active positions: ${positions.length}`)
|
|
|
|
if (positions.length > 0) {
|
|
for (const pos of positions) {
|
|
console.log(` ${pos.symbol}:`)
|
|
console.log(` Side: ${pos.side}`)
|
|
console.log(` Size: ${pos.size.toFixed(4)}`)
|
|
console.log(` Entry: $${pos.entryPrice.toFixed(4)}`)
|
|
console.log(` P&L: $${pos.unrealizedPnL.toFixed(2)}`)
|
|
}
|
|
} else {
|
|
console.log(' No active positions')
|
|
}
|
|
console.log('')
|
|
|
|
// Test 6: Oracle Prices
|
|
console.log('💹 Test 6: Oracle Prices')
|
|
const solPrice = await drift.getOraclePrice(0) // SOL-PERP
|
|
console.log(`✅ SOL/USD: $${solPrice.toFixed(4)}`)
|
|
console.log('')
|
|
|
|
// Test 7: Disconnect
|
|
console.log('🔌 Test 7: Disconnect')
|
|
await drift.disconnect()
|
|
console.log('✅ Disconnected from Drift')
|
|
console.log('')
|
|
|
|
console.log('✅ All tests passed!')
|
|
console.log('')
|
|
console.log('🎯 Ready to trade!')
|
|
console.log('')
|
|
console.log('Next steps:')
|
|
console.log('1. Set up n8n workflow (import n8n-workflow-v4.json)')
|
|
console.log('2. Configure TradingView alerts')
|
|
console.log('3. Test with a manual alert trigger')
|
|
console.log('4. Start trading!')
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Test failed:', error)
|
|
console.error('\nCommon issues:')
|
|
console.error('- DRIFT_WALLET_PRIVATE_KEY not set or invalid')
|
|
console.error('- Wallet not initialized on Drift')
|
|
console.error('- Insufficient SOL for gas fees')
|
|
console.error('- RPC connection issues')
|
|
console.error('\nCheck v4/SETUP.md for troubleshooting')
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
main()
|