# GekkoTrader setup — Testnet, TradingView, Paper 200

## 1. Dashboard

After deploy: **https://gekkotrader.fly.dev/**

| Action | What it does |
|--------|----------------|
| **Run cycle** | One live market scan + optional entry |
| **Accumulate 50 paper trades** | Backtest batch → journal + bandit learning (toward 200) |
| **Kill switch** | Freeze new entries immediately |

Optional UI protection (set on Fly):

```powershell
flyctl secrets set DASHBOARD_TOKEN=your-long-secret -a gekkotrader
```

Then in browser console on the dashboard:

```js
localStorage.setItem("gekko_dashboard_token", "your-long-secret")
```

---

## 2. Binance Futures Testnet keys

1. Open [Binance Futures Testnet](https://testnet.binancefuture.com/)
2. Log in / create API key (**trade enabled**, **no withdraw**)
3. Set secrets on Fly:

```powershell
flyctl secrets set `
  BINANCE_API_KEY="your_testnet_key" `
  BINANCE_API_SECRET="your_testnet_secret" `
  BINANCE_TESTNET="true" `
  TRADING_MODE="paper" `
  -a gekkotrader
```

Keep `TRADING_MODE=paper` until you have **200+ closed paper trades** and a profit factor you’re happy with.

When ready for **testnet live orders** (still fake money):

```powershell
flyctl secrets set TRADING_MODE="live" BINANCE_TESTNET="true" -a gekkotrader
```

Real money later (only after testnet proof):

```powershell
flyctl secrets set TRADING_MODE="live" BINANCE_TESTNET="false" -a gekkotrader
```

Use production Binance Futures keys with **IP allowlist** and **no withdraw**.

---

## 3. TradingView webhook

### Webhook URL

```
https://gekkotrader.fly.dev/webhooks/tradingview
```

### Secret

```powershell
flyctl secrets set TRADINGVIEW_WEBHOOK_SECRET="pick-a-long-random-string" -a gekkotrader
```

### Pine script

1. TradingView → chart **BTCUSDT.P** (or ETH) · **15m**
2. Pine Editor → paste `tradingview/strategy_regime_pullback.pine`
3. Add to chart → create alerts on **Gekko Long** / **Gekko Short**
4. Alert webhook body (JSON):

```json
{
  "secret": "pick-a-long-random-string",
  "symbol": "{{ticker}}",
  "action": "ENTER_LONG",
  "price": {{close}}
}
```

Use `ENTER_SHORT` for shorts. The bot sizes the trade via the risk engine and respects the kill switch.

---

## 4. Paper 200 gate

Goal: **200 closed paper trades** before real capital.

Fastest path from the dashboard:

1. Click **Accumulate 50 paper trades** a few times (BTC then ETH via API if needed)
2. Watch progress bar hit 200
3. Check win rate / lifetime PnL on the dashboard
4. Only then switch `TRADING_MODE=live` on **testnet**

Manual accumulate from PowerShell:

```powershell
Invoke-RestMethod -Method POST -Uri "https://gekkotrader.fly.dev/api/paper/accumulate?symbol=BTCUSDT&batch=50"
Invoke-RestMethod -Method POST -Uri "https://gekkotrader.fly.dev/api/paper/accumulate?symbol=ETHUSDT&batch=50"
```

---

## 5. Useful URLs

| URL | Purpose |
|-----|---------|
| `/` | Dashboard UI |
| `/health` | Liveness |
| `/status` | Compact JSON status |
| `/latency` | Singapore → Binance RTT |
| `/api/dashboard` | Full dashboard JSON |
| `/cycle` | POST — one cycle |
| `/webhooks/tradingview` | POST — TV alerts |
