Add TP1/SL consistency check on trade restore

This commit is contained in:
mindesbunister
2025-11-06 12:18:31 +01:00
parent 7c888282ec
commit 6c7eaf5f04
7 changed files with 265 additions and 26 deletions

View File

@@ -0,0 +1,32 @@
import { getPrismaClient } from '../lib/database/trades'
async function main() {
const prisma = getPrismaClient()
const openTrades = await prisma.trade.findMany({
where: { status: { not: 'closed' } },
orderBy: { entryTime: 'desc' },
take: 10,
})
console.log(
openTrades.map(t => ({
id: t.id,
symbol: t.symbol,
direction: t.direction,
status: t.status,
entryPrice: t.entryPrice,
exitPrice: t.exitPrice,
realizedPnL: t.realizedPnL,
exitReason: t.exitReason,
entryTime: t.entryTime,
exitTime: t.exitTime,
}))
)
process.exit(0)
}
main().catch(err => {
console.error(err)
process.exit(1)
})

View File

@@ -0,0 +1,30 @@
import { getPrismaClient } from '../lib/database/trades'
async function main() {
const prisma = getPrismaClient()
const openTrades = await prisma.trade.findMany({
where: { status: { not: 'closed' } },
orderBy: { entryTime: 'desc' },
take: 10,
})
console.log('Open trades:', openTrades.map(t => ({
id: t.id,
symbol: t.symbol,
direction: t.direction,
status: t.status,
entryPrice: t.entryPrice,
exitPrice: t.exitPrice,
exitReason: t.exitReason,
realizedPnL: t.realizedPnL,
createdAt: t.entryTime,
exitTime: t.exitTime,
})))
process.exit(0)
}
main().catch(err => {
console.error(err)
process.exit(1)
})

15
scripts/show-position.ts Normal file
View File

@@ -0,0 +1,15 @@
import { initializeDriftService, getDriftService } from '../lib/drift/client'
import { getMarketConfig } from '../config/trading'
async function main() {
await initializeDriftService()
const service = getDriftService()
const market = getMarketConfig('SOL-PERP')
const position = await service.getPosition(market.driftMarketIndex)
console.log('Position:', position)
}
main().catch(err => {
console.error(err)
process.exit(1)
})