> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aioka.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord Integration Guide

> Connect AIOKA signals to your Discord server — verdict updates, Ghost Trader trades, and regime change alerts via webhooks.

## Overview

AIOKA can broadcast trading signals, Ghost Trader trade events, and market
regime changes directly to your Discord server using **Discord webhooks** — no
bot token or Discord application required.

Two channels are supported:

* **Main signals channel** — verdict changes, regime changes
* **Ghost Trader trades channel** *(optional)* — trade entries, exits, TP1 fires

If you only configure one webhook, all messages go to the main channel.

***

## Quick Start

<Steps>
  <Step title="Create a Discord webhook">
    1. Open your Discord server.
    2. Right-click the channel where you want AIOKA signals to appear.
    3. Click **Edit Channel** → **Integrations** → **Webhooks** → **New Webhook**.
    4. Name the webhook (e.g. `AIOKA Signals`) and click **Copy Webhook URL**.
  </Step>

  <Step title="Add the webhook URL to your environment">
    In your Railway service `aioka` (or local `.env`):

    ```bash theme={null}
    DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/123456789/abcdef...
    ```

    Restart the service. AIOKA will detect the webhook on next boot and start
    posting verdict + regime changes within 60 seconds.
  </Step>

  <Step title="(Optional) Separate Ghost Trader trades">
    Create a second webhook in your trades channel and set:

    ```bash theme={null}
    DISCORD_GHOST_WEBHOOK_URL=https://discord.com/api/webhooks/987654321/ghi...
    ```

    Trade entries, TP1 fires, and exits will route to this channel instead. If
    this variable is unset, all messages go to the main webhook.
  </Step>

  <Step title="Verify it works">
    In Telegram, send `/discord_test` to your AIOKA bot. A test message should
    appear in your Discord channel within a few seconds. Use `/discord_status`
    to check current configuration.
  </Step>
</Steps>

***

## Message Types

### Verdict Update

Posted to the **main channel** when the AIOKA Judiciary ruling changes. The
verdict poller checks the latest verdict every 60 seconds.

```
👻 AIOKA SIGNAL UPDATE
━━━━━━━━━━━━━━━━━━━━━━━━━
⚡ ACCUMULATE (was: REDUCE)
📊 Confidence: 76.8%
💰 BTC: $77,882
🎯 Regime: 🐋 WHALE_ACCUMULATION
📉 RSI: 49.5
🌑 Dark Pool: 65/100
👻 Ghost: WAITING
━━━━━━━━━━━━━━━━━━━━━━━━━
View Live Dashboard: https://aioka.io/live
🕐 25 Apr 2026, 21:00 CEST
```

### Ghost Trader — Trade Entered

Posted to the **trades channel** the moment a Ghost Trader entry is committed
to the database (parallel to the existing Telegram entry alert).

```
🚀 GHOST TRADER — TRADE ENTERED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Entry: $77,598
TP1: $78,374 🎯
TP2: $79,538 🎯
SL: $76,325
Mode: A (RSI Auto-Pilot)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Track Record: https://aioka.io/track-record
🕐 25 Apr 2026, 05:32 CEST
```

### Ghost Trader — Trade Closed

Posted to the **trades channel** on every full close path: TP2, TSL, Stop
Loss, Score Sell, Regime Exit, Conviction Exit, and Flash Crash Emergency
Exit.

```
✅ GHOST TRADER — TRADE CLOSED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Exit: $77,931 | Result: WIN 🎯
P&L: +$261.00 (+1.04%)
Hold: 13h 53m
TP1 fired: ✅
Exit: TSL (Trailing Stop)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Track Record: https://aioka.io/track-record
🕐 25 Apr 2026, 19:26 CEST
```

### TP1 Fired

Posted to the **trades channel** when the partial 50% sell at TP1 executes
and the Break-Even Shield activates.

```
🎯 GHOST TRADER — TP1 FIRED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Price: $78,500.00
P&L locked: +$330.00 (+0.85%)
Remaining: 0.005000 BTC
Shield: Break-Even ACTIVE ✅
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🕐 25 Apr 2026, 16:00 CEST
```

### Regime Change

Posted to the **main channel** when the HMM market regime classifier flips.
The regime poller checks every 60 seconds.

```
🔄 REGIME CHANGE
━━━━━━━━━━━━━━━━━━━
Previous: RANGING
New: 🐋 WHALE_ACCUMULATION
Confidence: 94.2%
━━━━━━━━━━━━━━━━━━━
Live Dashboard: https://aioka.io/live
🕐 25 Apr 2026, 15:30 CEST
```

***

## Configuration Reference

| Env var                     | Required    | Default | Description                                                                          |
| --------------------------- | ----------- | ------- | ------------------------------------------------------------------------------------ |
| `DISCORD_WEBHOOK_URL`       | Recommended | empty   | Main signals channel webhook. If unset, Discord notifications are disabled.          |
| `DISCORD_GHOST_WEBHOOK_URL` | Optional    | empty   | Ghost Trader trades channel webhook. Falls back to `DISCORD_WEBHOOK_URL` when unset. |

Both variables are **optional**. If neither is set, Discord notifications are
silently disabled — no error, no log spam, no impact on trading.

***

## Telegram Diagnostic Commands

If you also have the AIOKA Telegram bot configured, you can manage Discord
from there:

| Command           | Purpose                                                                  |
| ----------------- | ------------------------------------------------------------------------ |
| `/discord_status` | Check whether webhooks are configured + last successful send timestamp   |
| `/discord_test`   | Send a test message to the Discord channel to verify the webhook is live |

Both commands are admin-only (`_require_auth`).

***

## Rate Limits & Reliability

* **Rate limit:** AIOKA enforces a global **5-second minimum interval** between
  any two Discord posts to stay well within Discord's webhook rate limit.
* **Truncation:** Messages exceeding Discord's 2,000-character hard limit are
  automatically truncated with a `... (truncated)` marker.
* **Graceful degradation:** Every Discord call is fire-and-forget and wrapped in
  try/except. Discord outages, DNS failures, or invalid webhooks **never block
  trading logic** — they're logged as `WARNING` and silently dropped.
* **Restart safety:** Verdict + regime polling state is intentionally
  ephemeral. After a Railway restart, AIOKA establishes a new baseline on the
  first poll cycle (\~60s) — no duplicate alerts and no missed transitions.

***

## Troubleshooting

| Symptom                                | Likely cause                   | Fix                                                                                                        |
| -------------------------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| `/discord_status` says "DISABLED"      | `DISCORD_WEBHOOK_URL` not set  | Set the variable in Railway env and redeploy.                                                              |
| `/discord_test` returns ❌              | Webhook deleted or invalid URL | Re-create the Discord webhook and update the env var.                                                      |
| No verdict updates after deploy        | Less than 60s since restart    | Wait one poll cycle. The first observed verdict establishes the baseline; the next change fires the alert. |
| Messages truncated mid-line            | Message exceeded 2000 chars    | Expected — Discord enforces a hard 2000-char limit per webhook payload.                                    |
| Trading not affected by Discord outage | Working as designed            | Discord failures are silent. Check Railway logs for `discord_send_failed` warnings if needed.              |

***

## Related Endpoints

* [`/v1/tradingview/signal`](/api-reference/tradingview/signal) — same data, polled by Pine Script
* [`/v1/integrations/zapier/signal`](/api-reference/integrations/zapier) — same data, polled by Zapier / n8n
* [Webhooks API](/webhooks) — programmatic event subscriptions for Basic+ tiers
