"""Quickstart example for OpenClaw Trading.

This example demonstrates basic usage of the trading system.
"""

from openclaw.core.economy import TradingEconomicTracker


def main():
    """Run the quickstart example."""
    print("=" * 60)
    print("OpenClaw Trading - Quickstart Example")
    print("=" * 60)

    # 1. Create an economic tracker
    print("\n1. Creating economic tracker...")
    tracker = TradingEconomicTracker(
        agent_id="quickstart_001",
        initial_capital=1000.0
    )
    print(f"   Agent ID: quickstart_001")
    print(f"   Initial Capital: $1,000.00")

    # 2. Check economic status
    print("\n2. Checking economic status...")
    status = tracker.get_survival_status()
    print(f"   Status: {status.value}")
    print(f"   Balance: ${tracker.balance:,.2f}")

    # 3. Simulate decision costs
    print("\n3. Simulating decision costs...")
    cost = tracker.calculate_decision_cost(
        tokens_input=1000,
        tokens_output=500,
        market_data_calls=2
    )
    print(f"   Decision cost: ${cost:.4f}")
    print(f"   New Balance: ${tracker.balance:,.2f}")

    # 4. Simulate a winning trade
    print("\n4. Simulating a winning trade...")
    trade_result = tracker.calculate_trade_cost(
        trade_value=500.0,
        is_win=True,
        win_amount=50.0
    )
    print(f"   Trade fee: ${trade_result.fee:.4f}")
    print(f"   Trade PnL: ${trade_result.pnl:.2f}")
    print(f"   New Balance: ${tracker.balance:,.2f}")

    # 5. Check updated status
    print("\n5. Checking updated status...")
    new_status = tracker.get_survival_status()
    print(f"   Status: {new_status.value}")

    # 6. Show cost summary
    print("\n6. Cost Summary:")
    print(f"   Token Costs: ${tracker.token_costs:.4f}")
    print(f"   Trade Costs: ${tracker.trade_costs:.4f}")
    print(f"   Total Costs: ${tracker.total_costs:.4f}")
    print(f"   Net Profit: ${tracker.net_profit:.2f}")

    # 7. Get balance history
    print("\n7. Balance History:")
    history = tracker.get_balance_history()
    for entry in history:
        print(f"   {entry.timestamp}: ${entry.balance:,.2f} ({entry.change:+.4f})")

    print("\n" + "=" * 60)
    print("Quickstart complete!")
    print("=" * 60)


if __name__ == "__main__":
    main()
