#!/usr/bin/env python3
"""
Quickstart Example - Your first SILICO bot in 10 lines.

Usage:
    export SILICO_API_KEY="sk_xxx"
    python quickstart.py
"""
import os
import time
from silico import SilicoBot

# Initialize bot
api_key = os.getenv("SILICO_API_KEY")
if not api_key:
    print("❌ Set SILICO_API_KEY environment variable")
    print("   Get your key at: https://silico.fun/dashboard")
    exit(1)

bot = SilicoBot(api_key=api_key)
print(f"✓ Connected to {bot.base_url}")

# Simple buy-low-sell-high strategy
while True:
    try:
        # Get current price
        price = bot.get_price("SOL/USDC")
        print(f"💰 SOL price: ${price:.2f}")

        # Buy low, sell high
        if price < 100:
            print("📈 Price is low - buying!")
            result = bot.buy("SOL/USDC", amount_usdc=50)
            print(f"   Trade ID: {result.trade_id}")

        elif price > 150:
            print("📉 Price is high - selling!")
            result = bot.sell("SOL/USDC", amount_usdc=50)
            print(f"   Trade ID: {result.trade_id}")

        else:
            print("⏸️  Waiting for good price...")

        # Wait 10 seconds before next check
        time.sleep(10)

    except KeyboardInterrupt:
        print("\n👋 Shutting down bot...")
        break

    except Exception as e:
        print(f"⚠️  Error: {e}")
        time.sleep(5)
