rusty-fmp 0.3.0

JSON CLI and client library for Financial Modeling Prep
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
//! Clap command and argument definitions.

use clap::{Args, Parser, Subcommand};

const DEFAULT_BASE_URL: &str = "https://financialmodelingprep.com/stable/";

/// Financial Modeling Prep CLI optimized for predictable JSON output.
#[derive(Debug, Parser)]
#[command(version, about)]
pub struct Cli {
    /// FMP API key. Prefer `FMP_API_KEY` in `.env` or the environment so shells do not record it.
    #[arg(long, env = "FMP_API_KEY", hide_env_values = true)]
    pub api_key: Option<String>,

    /// FMP stable API base URL. Override for tests or proxies.
    #[arg(long, env = "FMP_BASE_URL", default_value = DEFAULT_BASE_URL)]
    pub base_url: String,

    /// Command to execute.
    #[command(subcommand)]
    pub command: Command,
}

/// Supported FMP endpoint command groups.
#[derive(Debug, Subcommand)]
pub enum Command {
    /// Search for a tradable symbol by ticker or company name.
    Search {
        /// Ticker or company name query.
        query: String,
    },

    /// Company profile, peers, executives, and scores.
    #[command(subcommand)]
    Company(CompanyCommand),

    /// Quotes, price history, distributions, and price changes.
    #[command(subcommand)]
    Market(MarketCommand),

    /// Annual statements, ratios, metrics, growth, and estimates.
    #[command(subcommand)]
    Fundamentals(FundamentalsCommand),

    /// Analyst ratings and price target endpoints.
    #[command(subcommand)]
    Analyst(AnalystCommand),

    /// Date-based market calendars.
    #[command(subcommand)]
    Calendar(CalendarCommand),

    /// Macro rates and yield data.
    #[command(subcommand)]
    Rates(RatesCommand),

    /// Technical indicators.
    #[command(subcommand)]
    Technical(TechnicalCommand),

    /// SEC filing lookups.
    #[command(subcommand)]
    Filings(FilingsCommand),

    /// Cryptocurrency quotes and historical prices.
    #[command(subcommand)]
    Crypto(CryptoCommand),

    /// Forex quotes and historical prices.
    #[command(subcommand)]
    Forex(ForexCommand),

    /// News endpoints.
    News(NewsArgs),

    /// Hidden compatibility alias for `company profile`.
    #[command(hide = true)]
    Profile(SymbolArgs),

    /// Hidden compatibility alias for `company executives`.
    #[command(hide = true)]
    KeyExecutives(SymbolArgs),

    /// Hidden compatibility alias for `market quote`.
    #[command(hide = true)]
    Quote(SymbolArgs),

    /// Hidden compatibility alias for `market historical`.
    #[command(hide = true)]
    Historical(SymbolDateRangeArgs),

    /// Hidden compatibility alias for `market daily-chart`.
    #[command(hide = true)]
    DailyChart(SymbolDateRangeArgs),

    /// Hidden compatibility alias for `company peers`.
    #[command(hide = true)]
    StockPeers(SymbolArgs),

    /// Hidden compatibility alias for `market dividends`.
    #[command(hide = true)]
    Dividends(SymbolArgs),

    /// Hidden compatibility alias for `market splits`.
    #[command(hide = true)]
    Splits(SymbolArgs),

    /// Hidden compatibility alias for `calendar earnings`.
    #[command(hide = true)]
    EarningsCalendar(DateRangeArgs),

    /// Hidden compatibility alias for `rates treasury`.
    #[command(hide = true)]
    TreasuryRates(DateRangeArgs),

    /// Hidden compatibility alias for `technical sma`.
    #[command(hide = true)]
    TechnicalSma(TechnicalSmaArgs),

    /// Hidden compatibility alias for `market price-change`.
    #[command(hide = true)]
    StockPriceChange(SymbolArgs),

    /// Hidden compatibility alias for `filings sec`.
    #[command(hide = true)]
    SecFilings(SymbolDateRangeArgs),

    /// Hidden compatibility alias for `fundamentals income-statement`.
    #[command(hide = true)]
    IncomeStatement(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals income-statement-as-reported`.
    #[command(hide = true)]
    IncomeStatementAsReported(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals balance-sheet`.
    #[command(hide = true)]
    BalanceSheet(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals cash-flow`.
    #[command(hide = true)]
    CashFlow(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals ratios`.
    #[command(hide = true)]
    Ratios(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals metrics`.
    #[command(hide = true)]
    Metrics(AnnualArgs),

    /// Hidden compatibility alias for `company profile`.
    #[command(hide = true)]
    CompanyStats(SymbolArgs),

    /// Hidden compatibility alias for `fundamentals income-statement-growth`.
    #[command(hide = true)]
    IncomeStatementGrowth(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals balance-sheet-growth`.
    #[command(hide = true)]
    BalanceSheetGrowth(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals cash-flow-growth`.
    #[command(hide = true)]
    CashFlowGrowth(AnnualArgs),

    /// Hidden compatibility alias for `fundamentals enterprise-values`.
    #[command(hide = true)]
    EnterpriseValues(AnnualArgs),

    /// Hidden compatibility alias for `company financial-scores`.
    #[command(hide = true)]
    FinancialScores(SymbolArgs),

    /// Hidden compatibility alias for `fundamentals analyst-estimates`.
    #[command(hide = true)]
    AnalystEstimates(AnnualArgs),

    /// Hidden compatibility alias for `news stock`.
    #[command(hide = true)]
    StockNews(StockNewsArgs),
}

/// Company-focused commands.
#[derive(Debug, Subcommand)]
pub enum CompanyCommand {
    /// Get company profile/reference data for a symbol.
    Profile(SymbolArgs),

    /// Get key executives for a symbol.
    Executives(SymbolArgs),

    /// Get peer companies for a symbol.
    Peers(SymbolArgs),

    /// Get company key statistics for a symbol.
    Stats(SymbolArgs),

    /// Get financial scores for a symbol.
    FinancialScores(SymbolArgs),

    /// Get share float data for a symbol.
    ShareFloat(SymbolArgs),

    /// Get analyst rating consensus for a symbol.
    Rating(SymbolArgs),
}

/// Market data commands.
#[derive(Debug, Subcommand)]
pub enum MarketCommand {
    /// Get the latest quote for a symbol.
    Quote(SymbolArgs),

    /// Get historical end-of-day price bars for a symbol.
    Historical(SymbolDateRangeArgs),

    /// Get daily chart bars for a symbol.
    DailyChart(SymbolDateRangeArgs),

    /// Get historical dividends for a symbol.
    Dividends(SymbolArgs),

    /// Get historical stock splits for a symbol.
    Splits(SymbolArgs),

    /// Get price change percentages for a symbol.
    PriceChange(SymbolArgs),
}

/// Fundamental analysis commands.
#[derive(Debug, Subcommand)]
pub enum FundamentalsCommand {
    /// Get annual income statements for a symbol.
    IncomeStatement(AnnualArgs),

    /// Get annual income statements as reported for a symbol.
    IncomeStatementAsReported(AnnualArgs),

    /// Get annual balance sheets for a symbol.
    BalanceSheet(AnnualArgs),

    /// Get annual cash flow statements for a symbol.
    CashFlow(AnnualArgs),

    /// Get annual financial ratios for a symbol.
    Ratios(AnnualArgs),

    /// Get annual key metrics for a symbol.
    Metrics(AnnualArgs),

    /// Get annual income statement growth for a symbol.
    IncomeStatementGrowth(AnnualArgs),

    /// Get annual balance sheet growth for a symbol.
    BalanceSheetGrowth(AnnualArgs),

    /// Get annual cash flow growth for a symbol.
    CashFlowGrowth(AnnualArgs),

    /// Get annual enterprise values for a symbol.
    EnterpriseValues(AnnualArgs),

    /// Get annual analyst estimates for a symbol.
    AnalystEstimates(AnnualArgs),

    /// Get available financial report dates for a symbol.
    ReportDates(SymbolArgs),
}

/// Analyst-focused commands.
#[derive(Debug, Subcommand)]
pub enum AnalystCommand {
    /// Get price target consensus for a symbol.
    PriceTargetConsensus(SymbolArgs),

    /// Get price target summary for a symbol.
    PriceTargetSummary(SymbolArgs),

    /// Get analyst grade actions for a symbol.
    Grades(SymbolArgs),
}

/// Calendar commands.
#[derive(Debug, Subcommand)]
pub enum CalendarCommand {
    /// Get earnings calendar rows for a date range.
    Earnings(DateRangeArgs),
}

/// Rates commands.
#[derive(Debug, Subcommand)]
pub enum RatesCommand {
    /// Get treasury rates for a date range.
    Treasury(DateRangeArgs),
}

/// Technical indicator commands.
#[derive(Debug, Subcommand)]
pub enum TechnicalCommand {
    /// Get simple moving average technical indicator rows for a symbol.
    Sma(TechnicalSmaArgs),
}

/// Filing commands.
#[derive(Debug, Subcommand)]
pub enum FilingsCommand {
    /// Get SEC filings for a symbol.
    Sec(SymbolDateRangeArgs),
}

/// Cryptocurrency commands.
#[derive(Debug, Subcommand)]
pub enum CryptoCommand {
    /// List supported cryptocurrency symbols.
    List,

    /// Get the latest quote for a cryptocurrency pair.
    Quote(SymbolArgs),

    /// Get historical end-of-day price bars for a cryptocurrency pair.
    Historical(SymbolDateRangeArgs),
}

/// Forex commands.
#[derive(Debug, Subcommand)]
pub enum ForexCommand {
    /// Get the latest quote for a forex pair.
    Quote(SymbolArgs),

    /// Get historical end-of-day price bars for a forex pair.
    Historical(SymbolDateRangeArgs),
}

/// News commands.
#[derive(Debug, Subcommand)]
pub enum NewsCommand {
    /// Get recent stock news for a symbol.
    Stock(StockNewsArgs),

    /// Get latest general market news.
    General(PagedArgs),

    /// Get latest FMP articles.
    Articles(PagedArgs),

    /// Get latest forex news.
    Forex(PagedArgs),

    /// Get latest crypto news.
    Crypto(PagedArgs),
}

/// Shared symbol argument.
#[derive(Debug, Args)]
pub struct SymbolArgs {
    /// Ticker symbol, forex pair, or crypto pair.
    pub symbol: String,
}

/// Shared symbol and date range arguments.
#[derive(Debug, Args)]
pub struct SymbolDateRangeArgs {
    /// Ticker symbol, forex pair, or crypto pair.
    pub symbol: String,

    /// Inclusive start date in `YYYY-MM-DD` format.
    #[arg(long)]
    pub from: Option<String>,

    /// Inclusive end date in `YYYY-MM-DD` format.
    #[arg(long)]
    pub to: Option<String>,
}

/// Shared date range arguments.
#[derive(Debug, Args)]
pub struct DateRangeArgs {
    /// Inclusive start date in `YYYY-MM-DD` format.
    #[arg(long)]
    pub from: Option<String>,

    /// Inclusive end date in `YYYY-MM-DD` format.
    #[arg(long)]
    pub to: Option<String>,
}

/// Shared annual endpoint arguments.
#[derive(Debug, Args)]
pub struct AnnualArgs {
    /// Ticker symbol.
    pub symbol: String,

    /// Maximum number of annual rows to return.
    #[arg(long)]
    pub limit: Option<u16>,
}

/// Simple moving average arguments.
#[derive(Debug, Args)]
pub struct TechnicalSmaArgs {
    /// Ticker symbol.
    pub symbol: String,

    /// Moving average period length.
    #[arg(long, default_value_t = 10)]
    pub period_length: u16,

    /// FMP timeframe, for example `1day`.
    #[arg(long, default_value = "1day")]
    pub timeframe: String,
}

/// News command arguments.
#[derive(Debug, Args)]
pub struct NewsArgs {
    /// Grouped news command.
    #[command(subcommand)]
    pub command: Option<NewsCommand>,

    /// Legacy ticker symbol for `news <SYMBOL>`.
    #[arg(hide = true)]
    pub symbol: Option<String>,

    /// Maximum number of news items to return with the legacy `news <SYMBOL>` form.
    #[arg(long, hide = true)]
    pub limit: Option<u16>,
}

/// Stock news arguments.
#[derive(Debug, Args)]
pub struct StockNewsArgs {
    /// Ticker symbol.
    pub symbol: String,

    /// Maximum number of news items to return.
    #[arg(long)]
    pub limit: Option<u16>,
}

/// Shared paginated endpoint arguments.
#[derive(Debug, Args)]
pub struct PagedArgs {
    /// Zero-based result page.
    #[arg(long)]
    pub page: Option<u16>,

    /// Maximum number of items to return.
    #[arg(long)]
    pub limit: Option<u16>,
}