CRITICAL FIX: Add transaction confirmation to detect failed orders

- Added getConnection() method to DriftService
- Added proper transaction confirmation in openPosition()
- Check confirmation.value.err to detect on-chain failures
- Return error if transaction fails instead of assuming success
- Prevents phantom trades that never actually execute

This fixes the issue where bot was recording trades with transaction
signatures that don't exist on-chain (like 2gqrPxnvGzdRp56...).
This commit is contained in:
mindesbunister
2025-11-01 02:26:47 +01:00
parent a6005b6a5b
commit c82da51bdc
3 changed files with 36 additions and 3 deletions

3
.env
View File

@@ -351,4 +351,5 @@ NEW_RELIC_LICENSE_KEY=
USE_TRAILING_STOP=true USE_TRAILING_STOP=true
TRAILING_STOP_PERCENT=0.3 TRAILING_STOP_PERCENT=0.3
TRAILING_STOP_ACTIVATION=0.5 TRAILING_STOP_ACTIVATION=0.5
MIN_QUALITY_SCORE=40

View File

@@ -299,6 +299,13 @@ export class DriftService {
return this.driftClient! return this.driftClient!
} }
/**
* Get Solana connection instance
*/
getConnection(): Connection {
return this.connection
}
/** /**
* Get user instance * Get user instance
*/ */

View File

@@ -141,13 +141,38 @@ export async function openPosition(
console.log('🚀 Placing REAL market order...') console.log('🚀 Placing REAL market order...')
const txSig = await driftClient.placePerpOrder(orderParams) const txSig = await driftClient.placePerpOrder(orderParams)
console.log(`✅ Order placed! Transaction: ${txSig}`) console.log(`📝 Transaction submitted: ${txSig}`)
// CRITICAL: Confirm transaction actually executed on-chain
console.log('⏳ Confirming transaction on-chain...')
const connection = driftService.getConnection()
try {
const confirmation = await connection.confirmTransaction(txSig, 'confirmed')
if (confirmation.value.err) {
console.error(`❌ Transaction failed on-chain:`, confirmation.value.err)
return {
success: false,
error: `Transaction failed: ${JSON.stringify(confirmation.value.err)}`,
}
}
console.log(`✅ Transaction confirmed on-chain: ${txSig}`)
} catch (confirmError) {
console.error(`❌ Failed to confirm transaction:`, confirmError)
return {
success: false,
error: `Transaction confirmation failed: ${confirmError instanceof Error ? confirmError.message : 'Unknown error'}`,
}
}
// Wait a moment for position to update // Wait a moment for position to update
console.log('⏳ Waiting for position to update...') console.log('⏳ Waiting for position to update...')
await new Promise(resolve => setTimeout(resolve, 2000)) await new Promise(resolve => setTimeout(resolve, 2000))
// Get actual fill price from position (optional - may not be immediate in DRY_RUN) // Get actual fill price from position
const position = await driftService.getPosition(marketConfig.driftMarketIndex) const position = await driftService.getPosition(marketConfig.driftMarketIndex)
if (position && position.side !== 'none') { if (position && position.side !== 'none') {