Skip to main content

Crate finlight

Crate finlight 

Source
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§

AdmittedInfo
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).
ArticlePage
One page of articles().search().
ArticleSource
Source of an article.
Articles
Article endpoints: client.articles().
CacheInfo
ETag data of a record from companies().get() or get_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 the entityAccess entitlement (without it: Error::Api with api_kind forbidden).
Company
A company tagged in an article.
CompanyList
Result of companies().search() and companies().get_many(): the records plus skipped().
CompanyRecord
Company master data from companies().
CompanySearchParams
Parameters of companies().search().
Config
Configuration of a Client. Build it with Config::builder.
ConfigBuilder
Builder of Config.
DecodeError
A response could not be decoded.
EventTag
An event tagged in an article.
FieldIssue
One entry of ApiError::errors.
FinlightStream
A live stream of StreamEvents.
GetArticleOptions
Options of articles().get() and articles().get_by_link().
Listing
A listing of a company.
Media
An image of an article.
NetworkError
The network failed.
Pagination
Pagination of a search page.
PreemptedError
The server preempted the stream (connection.preempted).
QuotaWaitInfo
Sent each time a stream waits for the WebSocket quota of the next period.
RawStreamParams
Subscribe parameters of the raw stream (client.raw_stream()). Raw has no include: it delivers the article skeleton only.
ReconnectInfo
Sent after every new connection except the first one.
SearchAllOptions
Options of articles().search_all().
SearchAllResult
Result of articles().search_all(): iterate articles with SearchAllResult::next (or as a Stream), or pages with SearchAllResult::next_page. The first call decides; the other way then returns Error::Validation. It can be iterated once.
SearchParams
Parameters of articles().search() and articles().search_all().
Sentiment
Sentiment of an article.
SkippedEntry
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().
SourceList
Result of sources().list(): the sources plus skipped().
Sources
Source catalog: client.sources().
StreamEvent
One element of a stream.
StreamOptions
Options of a stream: takeover and hooks. Hooks run on the stream’s task; a panic in a hook is caught and logged and never ends the stream.
StreamParams
Subscribe parameters of the enriched stream (client.stream()).
TimeoutError
An attempt (timeout, connect_timeout) or the whole call (total_timeout) ran out of time.
ValidationError
A local check failed before any request or dial.
WebhookVerificationError
A webhook did not pass verification. Answer the request with 400 (never 410).

Enums§

ApiErrorKind
Kind of an API error, from the problem code or, without one, from the status.
CompanyRole
Position of a company in the story (not price impact).
ConnectionErrorCode
code of a connection.error frame.
DateInput
A from or to value.
Error
Every error of this SDK. Cancelling a call is not an error: drop its future.
EventDirection
Direction of a tagged event.
EventType
Type of a tagged event.
Field
A key with three states: absent, null or a value.
Importance
Importance of a tagged event. Ordered: low < medium < high < critical.
IncludeBlock
A block of include: extra data a request asks for (content, companies, events).
OrderBy
Timestamp articles.search sorts by; from and to apply to the same timestamp.
PreemptReason
reason of a connection.preempted frame.
ProblemCode
code of an API error (problem+json).
RateLimitType
Which limit a 429 hit. unknown when the server did not say and the detail text did not tell.
ReconnectReason
Why a stream opened a new connection (see ReconnectInfo).
RetryOnBurst
What the SDK does on a 429 burst.
SentimentLabel
Sentiment label.
SortOrder
Sort direction.
SourceType
Type of a source: source.type of an article, type of sources().list(), and the values of the source_types / exclude_source_types search and stream filters.
StreamEventKind
Kind of a stream element.
StreamEventName
event of a WebSocket frame.
WebhookEventName
event of a webhook delivery.
WebhookVerificationReason
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 + AsyncWrite tokio stream fits.

Type Aliases§

Result
Result type of this crate.
WsConnectFuture
Future returned by WsConnector::connect.