finlight-client (Rust)
The official Rust client for the finlight.me API — financial news with sentiment analysis, entity recognition, and real-time streaming.
📚 Full API documentation: docs.finlight.me
Features
- REST API: search articles, fetch single articles by link, list sources
- Real-time streaming: enhanced and raw article streams over WebSocket, exposed as async
Streams - Resilient by default: request retries with exponential backoff; WebSocket auto-reconnect, keepalive with pong watchdog, proactive connection rotation, and rate-limit handling
- Webhook support: HMAC-SHA256 signature verification with replay protection
- Async: built on tokio, reqwest, and tokio-tungstenite (rustls, no OpenSSL)
Requires Rust 1.85+.
Installation
Quick Start
use ;
async
REST API
Search articles
See the query language reference for the full query syntax.
use ;
let resp = client
.articles
.fetch_articles
.await?;
Fetch an article by link
use GetArticleByLinkParams;
let article = client
.articles
.fetch_article_by_link
.await?;
List sources
let sources = client.sources.get_sources.await?;
WebSocket Streaming
Streams implement futures::Stream: consume them with StreamExt::next, drop them to disconnect. Reconnects, keepalive, and rate-limit waits are handled internally. An Err item is terminal — the stream ends after yielding it.
Enhanced stream (sentiment, entities, deduplicated)
use GetArticlesWebSocketParams;
use StreamExt;
let mut stream = client.websocket.stream;
while let Some = stream.next.await
Raw stream (lowest latency, no enrichment)
use GetRawArticlesWebSocketParams;
let mut stream = client.raw_websocket.stream;
while let Some = stream.next.await
Custom WebSocket options
use Arc;
use Duration;
use ;
let ws = new;
Webhooks
Verify incoming webhooks with your endpoint secret from the finlight dashboard:
use construct_webhook_event;
// raw_body: unmodified request body bytes
// signature: X-Webhook-Signature header (with or without "sha256=" prefix)
// timestamp: X-Webhook-Timestamp header, None if absent
let article = construct_webhook_event?;
println!;
Configuration
| Field | Default | Description |
|---|---|---|
api_key |
— (required) | Your finlight API key |
base_url |
https://api.finlight.me |
REST base URL |
wss_url |
wss://wss.finlight.me |
WebSocket URL (/raw appended for raw) |
timeout |
5s |
Per-request timeout |
retry_count |
3 |
Total request attempts |
WebSocket option defaults: ping every 25s, pong timeout 60s, reconnect backoff 500ms → 10s, proactive rotation after 115min.
Logging
The client logs through tracing and is silent unless you install a subscriber:
fmt
.with_env_filter
.init;
Error Handling
- REST: retryable statuses (429, 500, 502, 503, 504) are retried with exponential backoff; other failures return
Error::Api { status, body }. - Streaming: the stream ends silently when you drop it or the server preempts the connection. An
Erritem is terminal —Error::Blockedmeans the server permanently rejected the connection. - Webhooks: verification failures return
WebhookVerificationError.
Testing
FINLIGHT_API_KEY=sk_... FINLIGHT_API_KEY=sk_...
License
MIT — see LICENSE.
Support
- Documentation: https://docs.finlight.me
- Website: https://finlight.me