From c3b0055572c28e7a67d2df0c7084b6a89b46b256 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Thu, 19 Mar 2026 18:38:15 -0400 Subject: [PATCH] zombie alerts --- src/app/positions/page.tsx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/positions/page.tsx b/src/app/positions/page.tsx index dc19305..afa7586 100644 --- a/src/app/positions/page.tsx +++ b/src/app/positions/page.tsx @@ -4,7 +4,11 @@ import { authOptions } from '@/lib/auth' import { redirect } from 'next/navigation' import { formatCurrency, formatNumber, formatPnl, pnlColor } from '@/lib/utils' import Link from 'next/link' -import { Coins } from 'lucide-react' +import { Coins, AlertTriangle } from 'lucide-react' +import { formatDistanceToNow } from 'date-fns' + +const ZOMBIE_ZERO_COUNT = parseInt(process.env.ZOMBIE_ZERO_COUNT ?? '1000', 10) +const PRICE_UPDATE_INTERVAL_MINUTES = parseInt(process.env.PRICE_UPDATE_INTERVAL_MINUTES ?? '60', 10) export const dynamic = 'force-dynamic' @@ -50,6 +54,7 @@ export default async function PositionsPage() { tag: true, displayTag: true, currentPrice: true, + zeroCount: true, priceHistory: { orderBy: { recordedAt: 'asc' }, take: 20, @@ -98,6 +103,18 @@ export default async function PositionsPage() { const currentValue = pos.hashtag.currentPrice * pos.shares const pnlPct = costBasis > 0 ? (pnl / costBasis) * 100 : 0 const sparkPrices = pos.hashtag.priceHistory.map((h) => h.price) + const isZombieWarning = pos.hashtag.zeroCount >= ZOMBIE_ZERO_COUNT * 0.9 + const zombieSince = isZombieWarning + ? formatDistanceToNow( + new Date(Date.now() - pos.hashtag.zeroCount * PRICE_UPDATE_INTERVAL_MINUTES * 60 * 1000), + ) + : null + const zombieEta = isZombieWarning + ? formatDistanceToNow( + new Date(Date.now() + (ZOMBIE_ZERO_COUNT - pos.hashtag.zeroCount) * PRICE_UPDATE_INTERVAL_MINUTES * 60 * 1000), + { addSuffix: true }, + ) + : null return (
#{pos.hashtag.displayTag} + {isZombieWarning && zombieSince && zombieEta && ( + + + No activity for {zombieSince} ยท Liquidates {zombieEta} + + )}