fmp-rust-sdk 0.1.1

Async Rust SDK for Financial Modeling Prep with typed data, subscription awareness, and WebSocket feeds
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
//! Stable endpoint methods grouped behind the public query options.

use super::*;

symbol_endpoint!(
    profile,
    "profile",
    Profile,
    "Company information from Stable `profile`."
);
symbol_endpoint!(
    stock_peers,
    "stock-peers",
    Peer,
    "Comparable companies from Stable `stock-peers`."
);
symbol_endpoint!(
    quote,
    "quote",
    Quote,
    "A full quote from Stable `quote` for any supported stock, ETF, index, crypto, forex, or commodity symbol."
);
symbol_endpoint!(
    quote_short,
    "quote-short",
    ShortQuote,
    "A compact quote from Stable `quote-short`."
);
symbol_endpoint!(
    aftermarket_trade,
    "aftermarket-trade",
    AftermarketTrade,
    "The latest after-hours trade from Stable `aftermarket-trade`."
);
symbol_endpoint!(
    aftermarket_quote,
    "aftermarket-quote",
    AftermarketQuote,
    "After-hours bid and ask data from Stable `aftermarket-quote`."
);
symbol_endpoint!(
    stock_price_change,
    "stock-price-change",
    PriceChange,
    "Changes across multiple time horizons from Stable `stock-price-change`."
);
symbol_endpoint!(
    market_capitalization,
    "market-capitalization",
    MarketCapitalization,
    "Current market capitalization from Stable `market-capitalization`."
);
symbol_endpoint!(
    shares_float,
    "shares-float",
    ShareFloat,
    "Available share float from Stable `shares-float`."
);
symbol_endpoint!(
    income_statement_ttm,
    "income-statement-ttm",
    IncomeStatement,
    "Trailing twelve-month income statements from Stable `income-statement-ttm`."
);
symbol_endpoint!(
    balance_sheet_statement_ttm,
    "balance-sheet-statement-ttm",
    BalanceSheetStatement,
    "Trailing twelve-month balance sheets from Stable `balance-sheet-statement-ttm`."
);
symbol_endpoint!(
    cash_flow_statement_ttm,
    "cash-flow-statement-ttm",
    CashFlowStatement,
    "Trailing twelve-month cash flow statements from Stable `cash-flow-statement-ttm`."
);
symbol_endpoint!(
    key_metrics_ttm,
    "key-metrics-ttm",
    KeyMetricsTtm,
    "Trailing twelve-month metrics from Stable `key-metrics-ttm`."
);
symbol_endpoint!(
    ratios_ttm,
    "ratios-ttm",
    FinancialRatiosTtm,
    "Trailing twelve-month ratios from Stable `ratios-ttm`."
);
symbol_endpoint!(
    earnings,
    "earnings",
    Earnings,
    "Company earnings history and scheduled reports from Stable `earnings`."
);
symbol_endpoint!(
    dividends,
    "dividends",
    Dividend,
    "Company dividend events from Stable `dividends`."
);
symbol_endpoint!(
    splits,
    "splits",
    StockSplit,
    "Company split events from Stable `splits`."
);
symbol_endpoint!(
    price_target_consensus,
    "price-target-consensus",
    PriceTargetConsensus,
    "Consensus analyst price targets from Stable `price-target-consensus`."
);
symbol_endpoint!(
    ratings_snapshot,
    "ratings-snapshot",
    RatingSnapshot,
    "Fundamental ratings from Stable `ratings-snapshot`."
);
symbol_endpoint!(
    discounted_cash_flow,
    "discounted-cash-flow",
    DiscountedCashFlow,
    "Company DCF valuation from Stable `discounted-cash-flow`."
);
symbol_endpoint!(
    levered_discounted_cash_flow,
    "levered-discounted-cash-flow",
    DiscountedCashFlow,
    "Levered company DCF valuation from Stable `levered-discounted-cash-flow`."
);
symbol_endpoint!(
    etf_holdings,
    "etf/holdings",
    EtfHolding,
    "Underlying securities and weights from Stable `etf/holdings`."
);

batch_endpoint!(
    batch_quote,
    "batch-quote",
    Quote,
    "Full quotes for multiple symbols from Stable `batch-quote`."
);
batch_endpoint!(
    batch_quote_short,
    "batch-quote-short",
    ShortQuote,
    "Compact quotes for multiple symbols from Stable `batch-quote-short`."
);
batch_endpoint!(
    batch_aftermarket_trade,
    "batch-aftermarket-trade",
    AftermarketTrade,
    "After-hours trades for multiple symbols from Stable `batch-aftermarket-trade`."
);
batch_endpoint!(
    batch_aftermarket_quote,
    "batch-aftermarket-quote",
    AftermarketQuote,
    "After-hours quotes for multiple symbols from Stable `batch-aftermarket-quote`."
);
batch_endpoint!(
    batch_market_capitalization,
    "market-capitalization-batch",
    MarketCapitalization,
    "Market capitalizations for multiple symbols from Stable `market-capitalization-batch`."
);

directory_endpoint!(
    stock_list,
    "stock-list",
    DirectorySymbol,
    "Company symbols from Stable `stock-list`."
);
directory_endpoint!(
    etf_list,
    "etf-list",
    DirectorySymbol,
    "ETF symbols from Stable `etf-list`."
);
directory_endpoint!(
    actively_trading_list,
    "actively-trading-list",
    DirectorySymbol,
    "Actively traded symbols from Stable `actively-trading-list`."
);
directory_endpoint!(
    biggest_gainers,
    "biggest-gainers",
    MarketMover,
    "Top gaining stocks from Stable `biggest-gainers`."
);
directory_endpoint!(
    biggest_losers,
    "biggest-losers",
    MarketMover,
    "Top losing stocks from Stable `biggest-losers`."
);
directory_endpoint!(
    most_actives,
    "most-actives",
    MarketMover,
    "Most active stocks from Stable `most-actives`."
);
directory_endpoint!(
    etf_quotes,
    "batch-etf-quotes",
    Quote,
    "ETF quotes from Stable `batch-etf-quotes`."
);
directory_endpoint!(
    crypto_quotes,
    "batch-crypto-quotes",
    Quote,
    "Cryptocurrency quotes from Stable `batch-crypto-quotes`."
);
directory_endpoint!(
    forex_quotes,
    "batch-forex-quotes",
    Quote,
    "Forex quotes from Stable `batch-forex-quotes`."
);
directory_endpoint!(
    commodity_quotes,
    "batch-commodity-quotes",
    Quote,
    "Commodity quotes from Stable `batch-commodity-quotes`."
);
directory_endpoint!(
    index_quotes,
    "batch-index-quotes",
    Quote,
    "Index quotes from Stable `batch-index-quotes`."
);

statement_endpoint!(
    income_statement,
    "income-statement",
    IncomeStatement,
    "Historical income statements from Stable `income-statement`."
);
statement_endpoint!(
    balance_sheet_statement,
    "balance-sheet-statement",
    BalanceSheetStatement,
    "Historical balance sheets from Stable `balance-sheet-statement`."
);
statement_endpoint!(
    cash_flow_statement,
    "cash-flow-statement",
    CashFlowStatement,
    "Historical cash flow statements from Stable `cash-flow-statement`."
);
statement_endpoint!(
    key_metrics,
    "key-metrics",
    KeyMetrics,
    "Historical key metrics from Stable `key-metrics`."
);
statement_endpoint!(
    ratios,
    "ratios",
    FinancialRatios,
    "Historical financial ratios from Stable `ratios`."
);
statement_endpoint!(
    financial_growth,
    "financial-growth",
    FinancialGrowth,
    "Growth rates from Stable `financial-growth`."
);

impl Client {
    /// Find symbols through Stable `search-symbol`.
    pub async fn search_symbol(
        &self,
        query: &str,
        options: SearchOptions<'_>,
    ) -> Result<Vec<SearchResult>> {
        required_value("query", query)?;
        if let Some(limit) = options.limit {
            positive_limit(limit)?;
        }
        self.get(
            "search-symbol",
            &SearchQuery {
                query,
                options: &options,
            },
        )
        .await
    }

    /// Find company names through Stable `search-name`.
    pub async fn search_name(
        &self,
        query: &str,
        options: SearchOptions<'_>,
    ) -> Result<Vec<SearchResult>> {
        required_value("query", query)?;
        if let Some(limit) = options.limit {
            positive_limit(limit)?;
        }
        self.get(
            "search-name",
            &SearchQuery {
                query,
                options: &options,
            },
        )
        .await
    }

    /// Get company profiles through Stable `profile-cik`.
    pub async fn profile_by_cik(&self, cik: &str) -> Result<Vec<Profile>> {
        required_value("cik", cik)?;
        self.get("profile-cik", &[("cik", cik)]).await
    }

    /// Get all quotes for an exchange through Stable `batch-exchange-quote`.
    pub async fn exchange_quotes(&self, exchange: &str) -> Result<Vec<Quote>> {
        required_value("exchange", exchange)?;
        self.get("batch-exchange-quote", &[("exchange", exchange)])
            .await
    }

    /// Daily split-adjusted OHLCV bars from Stable `historical-price-eod/full`.
    pub async fn historical_prices(
        &self,
        symbol: &str,
        dates: DateRange,
    ) -> Result<Vec<HistoricalPrice>> {
        required_value("symbol", symbol)?;
        valid_dates(dates)?;
        self.get(
            "historical-price-eod/full",
            &HistoricalQuery { symbol, dates },
        )
        .await
    }

    /// Daily closes from Stable `historical-price-eod/light`.
    pub async fn historical_prices_light(
        &self,
        symbol: &str,
        dates: DateRange,
    ) -> Result<Vec<HistoricalPriceLight>> {
        required_value("symbol", symbol)?;
        valid_dates(dates)?;
        self.get(
            "historical-price-eod/light",
            &HistoricalQuery { symbol, dates },
        )
        .await
    }

    /// Intraday OHLCV bars at the chosen documented Stable chart interval.
    pub async fn intraday_prices(
        &self,
        symbol: &str,
        interval: IntradayInterval,
        dates: DateRange,
    ) -> Result<Vec<IntradayPrice>> {
        required_value("symbol", symbol)?;
        valid_dates(dates)?;
        self.get(interval.path(), &HistoricalQuery { symbol, dates })
            .await
    }

    /// Market cap history through Stable `historical-market-capitalization`.
    pub async fn historical_market_capitalization(
        &self,
        symbol: &str,
        dates: DateRange,
        limit: u32,
    ) -> Result<Vec<MarketCapitalization>> {
        required_value("symbol", symbol)?;
        valid_dates(dates)?;
        positive_limit(limit)?;
        self.get(
            "historical-market-capitalization",
            &HistoricalMarketCapQuery {
                symbol,
                dates,
                limit,
            },
        )
        .await
    }

    /// Analyst projections through Stable `analyst-estimates`.
    pub async fn analyst_estimates(
        &self,
        symbol: &str,
        period: EstimatePeriod,
        pagination: Pagination,
    ) -> Result<Vec<AnalystEstimate>> {
        required_value("symbol", symbol)?;
        positive_limit(pagination.limit)?;
        self.get(
            "analyst-estimates",
            &AnalystQuery {
                symbol,
                period,
                pagination,
            },
        )
        .await
    }

    /// Full earnings call content through Stable `earning-call-transcript`.
    pub async fn earnings_transcript(
        &self,
        symbol: &str,
        year: u16,
        quarter: u8,
    ) -> Result<Vec<EarningsTranscript>> {
        required_value("symbol", symbol)?;
        if year == 0 || !(1..=4).contains(&quarter) {
            return Err(Error::Configuration {
                reason: format!(
                    "earnings transcript requires a positive year and quarter 1..=4, received year={year}, quarter={quarter}"
                ),
            });
        }
        self.get(
            "earning-call-transcript",
            &TranscriptQuery {
                symbol,
                year,
                quarter,
            },
        )
        .await
    }

    /// Earnings calendar through Stable `earnings-calendar`.
    pub async fn earnings_calendar(&self, dates: DateRange) -> Result<Vec<Earnings>> {
        valid_dates(dates)?;
        self.get("earnings-calendar", &dates).await
    }

    /// Dividend calendar through Stable `dividends-calendar`.
    pub async fn dividends_calendar(&self, dates: DateRange) -> Result<Vec<Dividend>> {
        valid_dates(dates)?;
        self.get("dividends-calendar", &dates).await
    }

    /// Split calendar through Stable `splits-calendar`.
    pub async fn splits_calendar(&self, dates: DateRange) -> Result<Vec<StockSplit>> {
        valid_dates(dates)?;
        self.get("splits-calendar", &dates).await
    }

    /// Latest company news through Stable `news/stock-latest`.
    pub async fn latest_stock_news(&self, options: NewsOptions) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        self.get("news/stock-latest", &options).await
    }

    /// General news through Stable `news/general-latest`.
    pub async fn general_news(&self, options: NewsOptions) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        self.get("news/general-latest", &options).await
    }

    /// Latest press releases through Stable `news/press-releases-latest`.
    pub async fn latest_press_releases(&self, options: NewsOptions) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        self.get("news/press-releases-latest", &options).await
    }

    /// Company news selected by symbol through Stable `news/stock`.
    pub async fn stock_news(
        &self,
        symbols: &[&str],
        options: NewsOptions,
    ) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        let symbols = joined_symbols(symbols)?;
        self.get(
            "news/stock",
            &NewsQuery {
                symbols: &symbols,
                options,
            },
        )
        .await
    }

    /// Press releases selected by symbol through Stable `news/press-releases`.
    pub async fn press_releases(
        &self,
        symbols: &[&str],
        options: NewsOptions,
    ) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        let symbols = joined_symbols(symbols)?;
        self.get(
            "news/press-releases",
            &NewsQuery {
                symbols: &symbols,
                options,
            },
        )
        .await
    }

    /// Cryptocurrency news through Stable `news/crypto`.
    pub async fn crypto_news(
        &self,
        symbols: &[&str],
        options: NewsOptions,
    ) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        let symbols = joined_symbols(symbols)?;
        self.get(
            "news/crypto",
            &NewsQuery {
                symbols: &symbols,
                options,
            },
        )
        .await
    }

    /// Foreign exchange news through Stable `news/forex`.
    pub async fn forex_news(
        &self,
        symbols: &[&str],
        options: NewsOptions,
    ) -> Result<Vec<NewsArticle>> {
        valid_dates(options.dates)?;
        positive_limit(options.pagination.limit)?;
        let symbols = joined_symbols(symbols)?;
        self.get(
            "news/forex",
            &NewsQuery {
                symbols: &symbols,
                options,
            },
        )
        .await
    }

    /// Historical Treasury yields through Stable `treasury-rates`.
    pub async fn treasury_rates(&self, dates: DateRange) -> Result<Vec<TreasuryRate>> {
        valid_dates(dates)?;
        self.get("treasury-rates", &dates).await
    }

    /// A named economic series through Stable `economic-indicators`.
    /// Indicator names are supplied explicitly as documented by FMP.
    pub async fn economic_indicators(
        &self,
        name: &str,
        dates: DateRange,
    ) -> Result<Vec<EconomicIndicator>> {
        #[derive(Serialize)]
        struct Query<'a> {
            name: &'a str,
            #[serde(flatten)]
            dates: DateRange,
        }
        required_value("name", name)?;
        valid_dates(dates)?;
        self.get("economic-indicators", &Query { name, dates })
            .await
    }

    /// Scheduled economic releases through Stable `economic-calendar`.
    pub async fn economic_calendar(&self, dates: DateRange) -> Result<Vec<EconomicEvent>> {
        valid_dates(dates)?;
        self.get("economic-calendar", &dates).await
    }

    /// Sector performance for a date through Stable `sector-performance-snapshot`.
    pub async fn sector_performance(
        &self,
        date: NaiveDate,
        exchange: Option<&str>,
        sector: Option<&str>,
    ) -> Result<Vec<SectorPerformance>> {
        self.get(
            "sector-performance-snapshot",
            &SectorSnapshotQuery {
                date,
                exchange,
                sector,
            },
        )
        .await
    }

    /// Industry performance for a date through Stable `industry-performance-snapshot`.
    pub async fn industry_performance(
        &self,
        date: NaiveDate,
        exchange: Option<&str>,
        industry: Option<&str>,
    ) -> Result<Vec<IndustryPerformance>> {
        self.get(
            "industry-performance-snapshot",
            &IndustrySnapshotQuery {
                date,
                exchange,
                industry,
            },
        )
        .await
    }
}