#!/bin/bash
# Quick P&L status report for Polymarket paper trading

echo "════════════════════════════════════════════════════════════════════════════════"
echo "POLYMARKET PAPER TRADING STATUS REPORT"
echo "════════════════════════════════════════════════════════════════════════════════"
echo ""

# Extract data from positions file
POS_FILE="/opt/dyeverse/crypto_agency/data/polymarket_positions.json"

if [ -f "$POS_FILE" ]; then
    OPEN_COUNT=$(jq '.positions | length' $POS_FILE)
    REALIZED_PNL=$(jq -r '.realized_pnl' $POS_FILE)
    CLOSED_COUNT=$(jq '.closed_trades | length' $POS_FILE)
    
    echo "📊 POSITION SUMMARY"
    echo "   Open positions: $OPEN_COUNT"
    echo "   Closed trades: $CLOSED_COUNT"
    echo "   Realized P&L: \$$REALIZED_PNL"
    echo ""
    
    echo "🔓 OPEN POSITIONS:"
    jq -r '.positions | to_entries[] | "   \(.value.side | ascii_upcase)  \(.value.market_question[0:50])  |  Entry: \(.value.entry_price)  |  Size: $\(.value.size_usd)"' $POS_FILE
    echo ""
    
    if [ $CLOSED_COUNT -gt 0 ]; then
        echo "🔒 CLOSED TRADES:"
        jq -r '.closed_trades[] | "   \(.side | ascii_upcase)  \(.market_question[0:50])  |  P&L: $\(.realized_pnl | tostring)  |  \(.exit_reason)"' $POS_FILE
        echo ""
    fi
else
    echo "⚠️  No positions file found"
fi

echo "════════════════════════════════════════════════════════════════════════════════"
echo "EXIT RULES:"
echo "   🎯 Profit target: 25% gain"
echo "   ⏱️  Time stop: 3 days"
echo "   🔍 Check frequency: Every 5 minutes (30 poll cycles)"
echo "════════════════════════════════════════════════════════════════════════════════"
