Expand description
Official Rust client for the finlight.me API v3: financial news search, article, company and source lookups, real-time streams and webhook verification.
This crate (0.2) speaks API v3 only. Stay on finlight-client = "0.1" for API v2.
Full API documentation: https://docs.finlight.me
use finlight::{Client, Config, SearchParams};
let client = Client::new(Config::new(std::env::var("FINLIGHT_API_KEY").unwrap_or_default()))?;
let page = client
.articles()
.search(&SearchParams::new().query("ticker:NVDA").limit(10))
.await?;
for article in &page.articles {
println!("{} {}", article.source.domain, article.title);
}Logging goes through tracing with the target finlight; nothing is printed without a
subscriber. The API key, webhook secrets, signatures and full bodies are never logged.
Re-exports§
pub use webhooks::WebhookEvent;pub use webhooks::WebhookPayload;pub use webhooks::WrongPayloadVersion;
Modules§
- webhooks
- Verifies and reads incoming finlight webhooks on your server.
Structs§
- Admitted
Info - Sent with every
connection.admitted. It arrives before the subscribe is validated, so it does not mean the subscribe was accepted. - ApiError
- An error answered by the API.
- Article
- A news article (REST, streams and webhooks share this shape).
- Article
Page - One page of
articles().search(). - Article
Source - Source of an article.
- Articles
- Article endpoints:
client.articles(). - Cache
Info - ETag data of a record from
companies().get()orget_if_none_match(), for callers who keep records themselves. The SDK keeps no cache of company records. - Client
- Client of the finlight API v3. Cheap to clone; clones share the HTTP client. Safe to use from many tasks, with many streams at the same time.
- Companies
- Company endpoints:
client.companies(). They need theentityAccessentitlement (without it:Error::Apiwithapi_kindforbidden). - Company
- A company tagged in an article.
- Company
List - Result of
companies().search()andcompanies().get_many(): the records plusskipped(). - Company
Record - Company master data from
companies(). - Company
Search Params - Parameters of
companies().search(). - Config
- Configuration of a
Client. Build it withConfig::builder. - Config
Builder - Builder of
Config. - Decode
Error - A response could not be decoded.
- Event
Tag - An event tagged in an article.
- Field
Issue - One entry of
ApiError::errors. - Finlight
Stream - A live stream of
StreamEvents. - GetArticle
Options - Options of
articles().get()andarticles().get_by_link(). - Listing
- A listing of a company.
- Media
- An image of an article.
- Network
Error - The network failed.
- Pagination
- Pagination of a search page.
- Preempted
Error - The server preempted the stream (
connection.preempted). - Quota
Wait Info - Sent each time a stream waits for the WebSocket quota of the next period.
- RawStream
Params - Subscribe parameters of the raw stream (
client.raw_stream()). Raw has noinclude: it delivers the article skeleton only. - Reconnect
Info - Sent after every new connection except the first one.
- Search
AllOptions - Options of
articles().search_all(). - Search
AllResult - Result of
articles().search_all(): iterate articles withSearchAllResult::next(or as aStream), or pages withSearchAllResult::next_page. The first call decides; the other way then returnsError::Validation. It can be iterated once. - Search
Params - Parameters of
articles().search()andarticles().search_all(). - Sentiment
- Sentiment of an article.
- Skipped
Entry - An entry of a list that could not be decoded. It is left out of the list, logged as a warning and kept here.
- Source
- A source from
sources().list(). - Source
List - Result of
sources().list(): the sources plusskipped(). - Sources
- Source catalog:
client.sources(). - Stream
Event - One element of a stream.
- Stream
Options - Options of a stream:
takeoverand hooks. Hooks run on the stream’s task; a panic in a hook is caught and logged and never ends the stream. - Stream
Params - Subscribe parameters of the enriched stream (
client.stream()). - Timeout
Error - An attempt (
timeout,connect_timeout) or the whole call (total_timeout) ran out of time. - Validation
Error - A local check failed before any request or dial.
- Webhook
Verification Error - A webhook did not pass verification. Answer the request with 400 (never 410).
Enums§
- ApiError
Kind - Kind of an API error, from the problem
codeor, without one, from the status. - Company
Role - Position of a company in the story (not price impact).
- Connection
Error Code codeof aconnection.errorframe.- Date
Input - A
fromortovalue. - Error
- Every error of this SDK. Cancelling a call is not an error: drop its future.
- Event
Direction - Direction of a tagged event.
- Event
Type - Type of a tagged event.
- Field
- A key with three states: absent,
nullor a value. - Importance
- Importance of a tagged event. Ordered:
low<medium<high<critical. - Include
Block - A block of
include: extra data a request asks for (content,companies,events). - OrderBy
- Timestamp
articles.searchsorts by;fromandtoapply to the same timestamp. - Preempt
Reason reasonof aconnection.preemptedframe.- Problem
Code codeof an API error (problem+json).- Rate
Limit Type - Which limit a 429 hit.
unknownwhen the server did not say and the detail text did not tell. - Reconnect
Reason - Why a stream opened a new connection (see
ReconnectInfo). - Retry
OnBurst - What the SDK does on a 429
burst. - Sentiment
Label - Sentiment label.
- Sort
Order - Sort direction.
- Source
Type - Type of a source:
source.typeof an article,typeofsources().list(), and the values of thesource_types/exclude_source_typessearch and stream filters. - Stream
Event Kind - Kind of a stream element.
- Stream
Event Name eventof a WebSocket frame.- Webhook
Event Name eventof a webhook delivery.- Webhook
Verification Reason - Why webhook verification failed.
Constants§
- PAYLOAD_
VERSION - The payload version this SDK speaks. Every WebSocket subscribe carries it as the JSON number 3.
- VERSION
- Version of this SDK, without a leading
v. Single source:Cargo.toml.
Traits§
- WsConnector
- Your own transport for stream dials, e.g. a tunnel through a proxy.
- WsIo
- A byte stream for a WebSocket connection. Any
AsyncRead + AsyncWritetokio stream fits.
Type Aliases§
- Result
- Result type of this crate.
- WsConnect
Future - Future returned by
WsConnector::connect.