siftingio-ai-rules / rules
Cursor rule0 starsChanged 6 months agoMITView on GitHub
SiftingIO live market data, REST last-trade/quote/snapshot/TVL plus the full WebSocket protocol (auth, subscribe, products, frames, snapshot-on-subscribe, keepalive, error codes).
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/siftingio-core.mdcCursor rule
- .cursor/rules/siftingio-fundamentals.mdcCursor rule
- .cursor/rules/siftingio-historical.mdcCursor rule
- .cursor/rules/siftingio-methodology.mdcCursor rule
- .cursor/rules/siftingio-sdks.mdcCursor rule
The file
We split this siftingio-live.mdc into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 54
If you connect without ?key=, send { "op": "auth", "key": "sft_..." } as your first frame within ~5s (else auth_timeout).
- Very specific: line 98
No client frames for 90 seconds → server closes with code 1000, reason "idle timeout".
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: SiftingIO live market data, REST last-trade/quote/snapshot/TVL plus the full WebSocket protocol (auth, subscribe, products, frames, snapshot-on-subscribe, keepalive, error codes).
globs: ["**/*.py", "**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.go", "**/*.rb", "**/*.java"]
alwaysApply: false
---
# SiftingIO Live market data
Live prices over REST (poll) or WebSocket (stream). One fair price per symbol (see `siftingio-methodology`). See `siftingio-core` for auth and errors.
## Symbol format
6-12 uppercase alphanumeric, **no separators**: `BTCUSD`, `ETHUSD`, `EURUSD`, `XAUUSD`. Not `BTC-USD` or `BTC/USD`. DEX/TVL symbols are chain-prefixed: `eth:WETH-USDC` (chains: `eth`, `base`, `arbitrum`, `bsc`, `polygon`).
## REST live endpoints
- `GET /v1/last/trade/:venue/:symbol`: last trade (`p` price, `P` size, `t` ms). `:venue` ∈ `stocks | crypto | forex | commodities | dex`.
- `GET /v1/last/quote/:venue/:symbol`: last top-of-book quote.
- `GET /v1/snapshot/:venue`: **gzip-required** full-market or watchlist snapshot. `:venue` ∈ `crypto | forex | stocks | dex`. Optional `symbols` = comma-separated (up to 250); omit for the full market. A single malformed symbol rejects the whole request with `400`.
- `GET /v1/last/tvl/:chain/:pair`: last DEX pool TVL.
- `GET /v1/convert/:from/:to`: FX/crypto conversion at live rates.
Snapshot entry fields: `s` symbol, `p` last price, `P` last size, `b`/`B` best bid price/size, `a`/`A` best ask price/size, `t` timestamp (ms). For forex/stocks (no top-of-book size), `P`/`B`/`A` come back as `0` (expected, not an error). Stale snapshot → `503 stale_snapshot` (body carries `last_t`, `server_now`).
```bash
# curl, market snapshot for two symbols (gzip required)
curl -H "X-API-Key: $KEY" -H "Accept-Encoding: gzip" --compressed \
"https://api.sifting.io/v1/snapshot/crypto?symbols=BTCUSD,ETHUSD"
```
```json
{
"data": [
{ "s": "BTCUSD", "p": "68250.5", "P": "0.0143", "b": "68249.9", "B": "0.21", "a": "68251.2", "A": "0.18", "t": 1716800000000 }
],
"meta": { "as_of": "2026-05-21T14:23:11Z", "venue": "crypto", "count": 1 }
}
```
## WebSocket protocol
**One connection, many subscriptions.** Connect with the key in the query string; every server frame carries an `f` discriminator, **branch on `f` first**, the other keys depend on it.
```text
wss://stream.sifting.io/ws/v1?key=sft_•••
```
The server replies immediately with an ack echoing your tier and limits:
```json
{ "f": "ack", "op": "auth", "tier": "free", "max_conn": 1, "max_subs": 5, "active_conn": 1 }
```
If you connect without `?key=`, send `{ "op": "auth", "key": "sft_..." }` as your first frame within ~5s (else `auth_timeout`).
### Client → server ops
| op | Frame | Purpose |
| --- | --- | --- |
| `auth` | `{ "op": "auth", "key": "sft_..." }` | First message; skip if you used `?key=`. |
| `subscribe` | `{ "op": "subscribe", "product": "cex", "symbols": ["BTCUSD","ETHUSD"] }` | Add channels. Multiple subscribes per connection are fine. |
| `unsubscribe` | `{ "op": "unsubscribe", "product": "cex", "symbols": ["BTCUSD"] }` | Stop the listed symbols. |
| `ping` | `{ "op": "ping" }` | Keepalive. Server replies `{ "f": "pong" }`. |
### Products
`cex` (centralised crypto) · `dex` (on-chain swaps, `chain:PAIR`) · `fx` (forex) · `us` (US equities) · `com` (commodities) · `tvl` (pool TVL deltas, `chain:PAIR`).
### Server → client frames (`f`)
- `ack`: your op succeeded; echoes the op and relevant fields.
- `pong`: reply to your ping.
- `tick`: price stream for `cex`/`dex`/`fx`/`us`/`com`:
```json
{ "f": "tick", "class": "fx", "s": "EURUSD",
"p": 1.16934, "P": 85790, "b": 1.16925, "B": 510300,
"a": 1.16943, "A": 585025, "t": 1778019852426 }
```
Fields: `s` symbol; `p`/`P` last price/size; `b`/`B` best bid; `a`/`A` best ask; `t` ms; `class` venue type; `chain` (DEX only).
- `tvl`: `{ "f": "tvl", "chain": "eth", "s": "WETH-USDC", "usd": 12345678.9, "r0": 1234.5, "r1": 5678.9, "n": 42, "t": ... }` (`usd` total locked, `r0`/`r1` reserves, `n` pools).
- `error`: `{ "f": "error", "code": "max_subscriptions", "message": "...", "limit": 1000 }`. Connection stays open; fix the op and retry. **Switch on `code`.**
### Snapshot on subscribe
On subscribe, the server emits **one snapshot `tick`/`tvl` per channel** (last cached value) **before** the live stream. Same shape as live frames, so your handler needn't distinguish:
```text
→ { "op":"subscribe", "product":"fx", "symbols":["EURUSD"] }
← { "f":"tick", ...EURUSD snapshot from cache... }
← { "f":"ack", "op":"subscribe", "product":"fx", "symbols":["EURUSD"] }
← { "f":"tick", ...live... }
```
### Keepalive
No client frames for **90 seconds** → server closes with code `1000`, reason `"idle timeout"`. Send `{ "op": "ping" }` at least every 60s. **Inbound traffic does not reset the idle timer, only client → server frames do.**
### WebSocket error codes
`bad_op` (unknown op / malformed JSON) · `auth_required` (subscribed before auth) · `auth_timeout` · `auth_failed` (key invalid/revoked/not entitled) · `unknown_product` · `max_connections` · `max_subscriptions` · `internal` (reconnect with backoff).
### Example client
```python
# Python, websockets
import asyncio, json, os, websockets
async def main():
url = f"wss://stream.sifting.io/ws/v1?key={os.environ['SIFTING_API_KEY']}"
async with websockets.connect(url) as ws:
print(json.loads(await ws.recv())) # ack op:auth
await ws.send(json.dumps({"op": "subscribe", "product": "cex", "symbols": ["BTCUSD", "ETHUSD"]}))
async for raw in ws:
msg = json.loads(raw)
if msg["f"] == "tick":
print(msg["s"], msg["p"], msg["t"])
elif msg["f"] == "error":
print("error:", msg["code"])
asyncio.run(main())
```
```typescript
// JavaScript / TypeScript, ws (Node) or browser WebSocket
import WebSocket from "ws";
const ws = new WebSocket(`wss://stream.sifting.io/ws/v1?key=${process.env.SIFTING_API_KEY}`);
ws.on("open", () =>
ws.send(JSON.stringify({ op: "subscribe", product: "cex", symbols: ["BTCUSD", "ETHUSD"] })));
ws.on("message", (raw) => {
const m = JSON.parse(raw.toString());
if (m.f === "tick") console.log(m.s, m.p, m.t);
else if (m.f === "error") console.error("error:", m.code);
});
setInterval(() => ws.send(JSON.stringify({ op: "ping" })), 30_000); // keepalive < 90s
```
## Gotchas
- Symbols have **no separators** (`BTCUSD`, not `BTC-USD`); DEX/TVL use `chain:PAIR`.
- `/v1/snapshot/:venue` is **gzip-required**.
- WS: branch on `f` for frames and on `code` for `error` frames.
- WS idle timer resets only on **client → server** frames, ping every ≤ 60s even while receiving ticks.
- `P`/`B`/`A` are `0` for forex/stocks snapshots by design.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

