feat: implement per-symbol cooldown period

CRITICAL: Cooldown was global across ALL symbols, causing missed opportunities
Example: ETH trade at 10:00 blocked SOL trade at 10:04 (5min cooldown)

Changes:
- Added getLastTradeTimeForSymbol() function to query last trade per symbol
- Updated check-risk endpoint to use symbol-specific cooldown
- Each coin (SOL/ETH/BTC) now has independent cooldown timer
- Cooldown message shows symbol: 'Must wait X min before next SOL-PERP trade'

Result: Can trade ETH and SOL simultaneously without interference
Example: ETH LONG at 10:00, SOL SHORT at 10:01 = both allowed
This commit is contained in:
mindesbunister
2025-11-03 08:01:30 +01:00
parent 0ea8773bdc
commit 0ed2e89c7e
2 changed files with 30 additions and 10 deletions

View File

@@ -276,6 +276,26 @@ export async function getLastTradeTime(): Promise<Date | null> {
}
}
/**
* Get the most recent trade time for a specific symbol
*/
export async function getLastTradeTimeForSymbol(symbol: string): Promise<Date | null> {
const prisma = getPrismaClient()
try {
const lastTrade = await prisma.trade.findFirst({
where: { symbol },
orderBy: { entryTime: 'desc' },
select: { entryTime: true },
})
return lastTrade?.entryTime || null
} catch (error) {
console.error(`❌ Failed to get last trade time for ${symbol}:`, error)
return null
}
}
/**
* Get the most recent trade with full details
*/