Skip to content

Commit 21683c7

Browse files
committed
feat: replace REST API with market data service
1 parent 8c83ef6 commit 21683c7

16 files changed

Lines changed: 1856 additions & 1317 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ packages/raindex/cjs.d.ts
1414
packages/raindex/esm.js
1515
packages/raindex/esm.d.ts
1616
.direnv/
17+
.raindex/
1718

1819
# Audit proposed fixes
1920
.fixes/

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rest_api/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ path = "src/main.rs"
1313

1414
[dependencies]
1515
raindex_common = { workspace = true }
16+
async-trait = "0.1"
17+
moka = { version = "0.12", features = ["future"] }
1618
rocket = { version = "0.5.1", features = ["json"] }
1719
rocket_cors = "0.6"
1820
serde = { workspace = true, features = ["derive"] }
1921
serde_json = { workspace = true }
2022
thiserror = { workspace = true }
23+
tracing = { workspace = true }
24+
tracing-subscriber = { workspace = true, features = ["env-filter"] }
2125
utoipa = { version = "5", features = ["rocket_extras"] }
2226
utoipa-swagger-ui = { version = "9", features = ["rocket"] }
27+
uuid = { version = "1", features = ["v4"] }
2328

2429
[target.'cfg(not(target_family = "wasm"))'.dependencies]
2530
tokio = { workspace = true, features = ["full"] }

crates/rest_api/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Raindex Market Data API
2+
3+
Public market data service backed by the Raindex Rust SDK and its persistent
4+
local indexer. It does not require API keys.
5+
6+
## Run locally
7+
8+
```sh
9+
cargo run -p raindex_rest_api
10+
```
11+
12+
The first startup creates `.raindex/market-data.sqlite`, synchronizes the
13+
configured orderbook, and warms the market cache before accepting requests.
14+
Swagger UI is served at `http://127.0.0.1:8000/swagger/`.
15+
16+
## Routes
17+
18+
- `GET /tickers` — CoinGecko 24-hour ticker data for every listed registry
19+
market.
20+
- `GET /orderbook?ticker_id=...&depth=100` — executable bids and asks for one
21+
market.
22+
- `GET /v1/markets` — complete registry-driven market overview for the Raindex
23+
UI.
24+
- `GET /v1/markets?ticker_id=...` — one market with statistics, trades, and its
25+
executable book.
26+
- `GET /health` and `GET /health/detailed` — service and local-indexer health.
27+
28+
## Configuration
29+
30+
All settings are optional environment variables:
31+
32+
| Variable | Default |
33+
| -------------------------------------- | ---------------------------------------- |
34+
| `RAINDEX_REGISTRY_URL` | Pinned `rain.strategies` registry commit |
35+
| `RAINDEX_LOCAL_DB_PATH` | `.raindex/market-data.sqlite` |
36+
| `RAINDEX_CACHE_TTL_SECONDS` | `60` |
37+
| `RAINDEX_RATE_LIMIT_GLOBAL_RPM` | `6000` |
38+
| `RAINDEX_RATE_LIMIT_PER_IP_RPM` | `120` |
39+
| `RAINDEX_SNAPSHOT_RECENT_TRADES_LIMIT` | `1000` |
40+
| `RAINDEX_TRUSTED_PROXY_IP_HEADER` | unset; direct socket IP is used |
41+
42+
The all-market overview is refreshed in the background. Executable orderbooks
43+
are cached per ticker so an orderbook request quotes only the requested market.
44+
Orderbooks use a fixed 1000-level SDK snapshot. A `depth` of `0` returns that
45+
entire snapshot; positive values return at most that many levels split evenly
46+
between bids and asks. CoinGecko's optional historical-trades endpoint is
47+
intentionally deferred until the SDK can serve arbitrary indexed time ranges
48+
without truncating to a cached 24-hour window.
49+
50+
Set `RAINDEX_TRUSTED_PROXY_IP_HEADER` only when a trusted ingress overwrites
51+
that header before forwarding requests. Client-provided forwarding headers are
52+
ignored by default so public rate limits cannot be bypassed by spoofing them.

0 commit comments

Comments
 (0)