# Signal Consumption

A live policy produces a cryptographically signed event stream that any execution stack can ingest with minimal glue code.

## Transport Options

<table><thead><tr><th width="170.2073974609375">Channel</th><th>Endpoint or topic</th><th>Typical latency</th></tr></thead><tbody><tr><td>WebSocket</td><td><code>wss://api.slinkylayer.ai/v1/stream/{modelId}</code></td><td>sub-second</td></tr><tr><td>HTTPS Webhook</td><td>User-supplied URL, set per model</td><td>push, near-RT</td></tr><tr><td>Kafka / NATS</td><td><code>slinky.signals.{modelId}</code></td><td>≤ 5 ms in-VPC</td></tr><tr><td>Historical API</td><td><code>GET /v1/signals/{modelId}?start=…&#x26;end=…</code></td><td>batch pull</td></tr></tbody></table>

All transports emit the exact same payload and support cursor replay.

## Canonical Message Schema (JSON)

```jsonc
{
  "ts":        "2025-09-03T14:00:00Z",   // candle close ISO-8601
  "symbol":    "BTCUSDT",
  "action":    "LONG_100",               // LONG_100 | FLAT_0 | SHORT_100 | HOLD
  "price_ref": 27251.34,                 // close price used by the model
  "model_id":  "0x3af1…9c14",
  "sig_hash":  "0x28da…ab9e",            // SHA-256(ts,symbol,action,price_ref)
  "signature": "0x5dbe…21cf"             // Ed25519 over raw payload
}
```

Verification routine:

1. Fetch creator public key from the Registry.
2. Check `signature` against the raw JSON bytes.
3. Compare `sig_hash` with your own SHA-256 result.

## Timing Rules

* Gateway publishes no later than 2s after candle close.
* Auditor nodes mark signals stale if received > 5s after close.
* Heartbeat frames every 30s keep idle WebSocket connections alive.

## Action Semantics

| Action     | Target allocation | Idempotence (default ON) |
| ---------- | ----------------- | ------------------------ |
| LONG\_100  | +1.0              | Skip trade if already +1 |
| FLAT\_0    | 0.0               | Skip if 0                |
| SHORT\_100 | −1.0              | Skip if −1               |

Clients should mirror the same guard logic before submitting orders.

## Integration Patterns

| Pattern             | Consumer example                    | Connection type       |
| ------------------- | ----------------------------------- | --------------------- |
| Low-latency bot     | Python + ccxt on a VPS              | WebSocket             |
| Vault connector     | Hyperliquid or GMX strategy vault   | HTTPS Webhook         |
| LLM agent tool      | LangChain or Autogen module         | Historical API + WS   |
| Chat plug-in        | Discord or Telegram trade alert bot | Webhook               |
| No-code automation  | Zapier or n8n flow                  | Webhook               |
| Spreadsheet tracker | Google Sheets IMPORTDATA            | Historical API hourly |

## &#x20;Reference Listener (Python, ccxt)

```python
import asyncio, json, websockets, ccxt

EX   = ccxt.binance({'apiKey': '...', 'secret': '...'})
WS   = "wss://api.slinkylayer.ai/v1/stream/0x3af1…9c14"
HEAD = [("Authorization", "Bearer sk_live_…")]

async def main():
    async with websockets.connect(WS, extra_headers=HEAD) as sock:
        async for raw in sock:
            msg = json.loads(raw)
            if msg["action"] == "LONG_100":
                EX.create_market_buy_order('BTC/USDT', 1)
            elif msg["action"] == "SHORT_100":
                EX.create_market_sell_order('BTC/USDT', 1)

asyncio.run(main())
```

## Operational Safeguards

* **Debounce flips** – require two identical signals before reversing a live position.
* **Min notional** – ignore actions that translate to < 10 USDT.
* **Circuit breaker** – halt trading if cumulative drawdown exceeds 20 percent in a rolling 24h window.

## Historical Back-fill

```
GET /v1/signals/{modelId}?start=2025-08-01T00:00:00Z&end=2025-08-31T23:59:00Z
```

Returns JSON identical to the live stream, suitable for equity-curve plotting or database back-fill.
