"""
Phase 1 verification: confirm we can authenticate to Kalshi and read
our portfolio. NO orders are placed. Run this once before moving to Phase 2.
"""
import kalshi_trader as kt


def main():
    print("=" * 60)
    print("Kalshi auth test — Phase 1")
    print("=" * 60)

    # 1. Balance
    print("\n[1/3] GET /portfolio/balance")
    try:
        bal = kt.get_balance()
        cents = bal.get("balance", 0)
        print(f"  Balance: ${cents/100:,.2f}  (raw: {bal})")
    except Exception as e:
        print(f"  FAIL: {e}")
        return

    # 2. Positions
    print("\n[2/3] GET /portfolio/positions")
    try:
        pos = kt.get_positions()
        markets = pos.get("market_positions", [])
        print(f"  Open positions: {len(markets)}")
        for p in markets[:5]:
            print(f"    {p.get('ticker')}  pos={p.get('position')}  exposure=${p.get('total_traded',0)/100:.2f}")
    except Exception as e:
        print(f"  FAIL: {e}")

    # 3. Open orders
    print("\n[3/3] GET /portfolio/orders (resting)")
    try:
        orders = kt.get_open_orders()
        olist = orders.get("orders", [])
        print(f"  Resting orders: {len(olist)}")
        for o in olist[:5]:
            print(f"    {o.get('ticker')} {o.get('side')} {o.get('count')} @ {o.get('yes_price')}c")
    except Exception as e:
        print(f"  FAIL: {e}")

    print("\n" + "=" * 60)
    print("Phase 1 PASS — auth works, you can see your account state.")
    print("Compare the balance above to your Kalshi web UI.")
    print("=" * 60)


if __name__ == "__main__":
    main()
