yfinance-mcp-ts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +628 -0
  3. package/dist/auth/HeadlessAuth.d.ts +68 -0
  4. package/dist/auth/HeadlessAuth.d.ts.map +1 -0
  5. package/dist/auth/HeadlessAuth.js +212 -0
  6. package/dist/auth/HeadlessAuth.js.map +1 -0
  7. package/dist/auth/index.d.ts +5 -0
  8. package/dist/auth/index.d.ts.map +1 -0
  9. package/dist/auth/index.js +21 -0
  10. package/dist/auth/index.js.map +1 -0
  11. package/dist/config/browsers.d.ts +29 -0
  12. package/dist/config/browsers.d.ts.map +1 -0
  13. package/dist/config/browsers.js +196 -0
  14. package/dist/config/browsers.js.map +1 -0
  15. package/dist/config/countries.d.ts +24 -0
  16. package/dist/config/countries.d.ts.map +1 -0
  17. package/dist/config/countries.js +108 -0
  18. package/dist/config/countries.js.map +1 -0
  19. package/dist/config/endpoints.d.ts +59 -0
  20. package/dist/config/endpoints.d.ts.map +1 -0
  21. package/dist/config/endpoints.js +384 -0
  22. package/dist/config/endpoints.js.map +1 -0
  23. package/dist/config/index.d.ts +9 -0
  24. package/dist/config/index.d.ts.map +1 -0
  25. package/dist/config/index.js +25 -0
  26. package/dist/config/index.js.map +1 -0
  27. package/dist/config/modules.d.ts +28 -0
  28. package/dist/config/modules.d.ts.map +1 -0
  29. package/dist/config/modules.js +550 -0
  30. package/dist/config/modules.js.map +1 -0
  31. package/dist/config/screeners.d.ts +23 -0
  32. package/dist/config/screeners.d.ts.map +1 -0
  33. package/dist/config/screeners.js +1946 -0
  34. package/dist/config/screeners.js.map +1 -0
  35. package/dist/core/BaseFinance.d.ts +82 -0
  36. package/dist/core/BaseFinance.d.ts.map +1 -0
  37. package/dist/core/BaseFinance.js +311 -0
  38. package/dist/core/BaseFinance.js.map +1 -0
  39. package/dist/core/ProxyManager.d.ts +106 -0
  40. package/dist/core/ProxyManager.d.ts.map +1 -0
  41. package/dist/core/ProxyManager.js +224 -0
  42. package/dist/core/ProxyManager.js.map +1 -0
  43. package/dist/core/Research.d.ts +112 -0
  44. package/dist/core/Research.d.ts.map +1 -0
  45. package/dist/core/Research.js +423 -0
  46. package/dist/core/Research.js.map +1 -0
  47. package/dist/core/Screener.d.ts +59 -0
  48. package/dist/core/Screener.d.ts.map +1 -0
  49. package/dist/core/Screener.js +100 -0
  50. package/dist/core/Screener.js.map +1 -0
  51. package/dist/core/SessionManager.d.ts +161 -0
  52. package/dist/core/SessionManager.d.ts.map +1 -0
  53. package/dist/core/SessionManager.js +575 -0
  54. package/dist/core/SessionManager.js.map +1 -0
  55. package/dist/core/Ticker.d.ts +211 -0
  56. package/dist/core/Ticker.d.ts.map +1 -0
  57. package/dist/core/Ticker.js +678 -0
  58. package/dist/core/Ticker.js.map +1 -0
  59. package/dist/core/index.d.ts +10 -0
  60. package/dist/core/index.d.ts.map +1 -0
  61. package/dist/core/index.js +26 -0
  62. package/dist/core/index.js.map +1 -0
  63. package/dist/index.d.ts +19 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +58 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/mcp/config.d.ts +29 -0
  68. package/dist/mcp/config.d.ts.map +1 -0
  69. package/dist/mcp/config.js +100 -0
  70. package/dist/mcp/config.js.map +1 -0
  71. package/dist/mcp/index.d.ts +25 -0
  72. package/dist/mcp/index.d.ts.map +1 -0
  73. package/dist/mcp/index.js +33 -0
  74. package/dist/mcp/index.js.map +1 -0
  75. package/dist/mcp/server.d.ts +9 -0
  76. package/dist/mcp/server.d.ts.map +1 -0
  77. package/dist/mcp/server.js +101 -0
  78. package/dist/mcp/server.js.map +1 -0
  79. package/dist/mcp/tools/misc.d.ts +107 -0
  80. package/dist/mcp/tools/misc.d.ts.map +1 -0
  81. package/dist/mcp/tools/misc.js +166 -0
  82. package/dist/mcp/tools/misc.js.map +1 -0
  83. package/dist/mcp/tools/research.d.ts +43 -0
  84. package/dist/mcp/tools/research.d.ts.map +1 -0
  85. package/dist/mcp/tools/research.js +135 -0
  86. package/dist/mcp/tools/research.js.map +1 -0
  87. package/dist/mcp/tools/screener.d.ts +70 -0
  88. package/dist/mcp/tools/screener.d.ts.map +1 -0
  89. package/dist/mcp/tools/screener.js +121 -0
  90. package/dist/mcp/tools/screener.js.map +1 -0
  91. package/dist/mcp/tools/ticker.d.ts +186 -0
  92. package/dist/mcp/tools/ticker.d.ts.map +1 -0
  93. package/dist/mcp/tools/ticker.js +339 -0
  94. package/dist/mcp/tools/ticker.js.map +1 -0
  95. package/dist/misc/functions.d.ts +116 -0
  96. package/dist/misc/functions.d.ts.map +1 -0
  97. package/dist/misc/functions.js +94 -0
  98. package/dist/misc/functions.js.map +1 -0
  99. package/dist/misc/index.d.ts +5 -0
  100. package/dist/misc/index.d.ts.map +1 -0
  101. package/dist/misc/index.js +21 -0
  102. package/dist/misc/index.js.map +1 -0
  103. package/dist/types/api-responses.d.ts +534 -0
  104. package/dist/types/api-responses.d.ts.map +1 -0
  105. package/dist/types/api-responses.js +6 -0
  106. package/dist/types/api-responses.js.map +1 -0
  107. package/dist/types/index.d.ts +94 -0
  108. package/dist/types/index.d.ts.map +1 -0
  109. package/dist/types/index.js +21 -0
  110. package/dist/types/index.js.map +1 -0
  111. package/dist/utils/helpers.d.ts +128 -0
  112. package/dist/utils/helpers.d.ts.map +1 -0
  113. package/dist/utils/helpers.js +369 -0
  114. package/dist/utils/helpers.js.map +1 -0
  115. package/dist/utils/index.d.ts +5 -0
  116. package/dist/utils/index.d.ts.map +1 -0
  117. package/dist/utils/index.js +21 -0
  118. package/dist/utils/index.js.map +1 -0
  119. package/package.json +90 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,628 @@
1
+ # yfinance-mcp-ts
2
+
3
+ A TypeScript wrapper for the unofficial Yahoo Finance API. This library provides easy access to stock quotes, historical data, financial statements, options chains, screeners, and more.
4
+
5
+ ## Features
6
+
7
+ - **Ticker Data**: Get quotes, price, summary, earnings, financials, and more
8
+ - **Historical Data**: Fetch OHLCV data with customizable periods and intervals
9
+ - **Financial Statements**: Income statements, balance sheets, cash flow statements
10
+ - **Options Chains**: Full options data with calls and puts
11
+ - **Screeners**: Access 300+ predefined stock screeners
12
+ - **Research**: Reports, trade ideas, earnings calendar, IPOs, splits
13
+ - **Search**: Search for stocks, ETFs, mutual funds, and more
14
+ - **Premium Support**: Optional Yahoo Finance Premium authentication
15
+ - **MCP Server**: Built-in Model Context Protocol server for AI agents (Claude, etc.)
16
+ - **Proxy Rotation**: Distribute requests across multiple proxies with automatic failure tracking
17
+ - **Retry with Backoff**: Automatic retry with exponential backoff for rate limits and transient errors
18
+
19
+ ## MCP Server (AI Agent Integration)
20
+
21
+ This library includes a built-in [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that allows AI agents like Claude to access Yahoo Finance data directly.
22
+
23
+ ### Quick Setup for Claude Desktop
24
+
25
+ Add to your Claude Desktop configuration (`~/.config/claude/claude_desktop_config.json` on macOS/Linux or `%APPDATA%\Claude\claude_desktop_config.json` on Windows):
26
+
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "yfinance": {
31
+ "command": "npx",
32
+ "args": ["yfinance-mcp"]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ Or if installed locally:
39
+
40
+ ```json
41
+ {
42
+ "mcpServers": {
43
+ "yfinance": {
44
+ "command": "node",
45
+ "args": ["/path/to/yfinance-mcp-ts/dist/mcp/server.js"]
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### MCP Server with Proxy Rotation
52
+
53
+ To use proxy rotation with the MCP server, configure environment variables:
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "yfinance": {
59
+ "command": "node",
60
+ "args": ["/path/to/yfinance-mcp-ts/dist/mcp/server.js"],
61
+ "env": {
62
+ "YFINANCE_PROXY_LIST": "http://user:pass@proxy1.com:8080\nhttp://user:pass@proxy2.com:8080",
63
+ "YFINANCE_PROXY_MAX_FAILURES": "3",
64
+ "YFINANCE_PROXY_COOLDOWN_MS": "300000"
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ #### MCP Environment Variables
72
+
73
+ | Variable | Description | Default |
74
+ |----------|-------------|---------|
75
+ | `YFINANCE_PROXY_LIST` | Newline-separated proxy URLs | - |
76
+ | `YFINANCE_PROXY_MAX_FAILURES` | Failures before marking proxy unhealthy | 3 |
77
+ | `YFINANCE_PROXY_COOLDOWN_MS` | Cooldown before retrying unhealthy proxy | 300000 |
78
+ | `YFINANCE_RETRY_ENABLED` | Enable automatic retry | true |
79
+ | `YFINANCE_RETRY_MAX_RETRIES` | Maximum retry attempts | 3 |
80
+ | `YFINANCE_RETRY_INITIAL_DELAY` | Initial retry delay (ms) | 1000 |
81
+ | `YFINANCE_RETRY_MAX_DELAY` | Maximum retry delay (ms) | 30000 |
82
+ | `YFINANCE_TIMEOUT` | Request timeout (ms) | 30000 |
83
+
84
+ ### Available MCP Tools (20 tools)
85
+
86
+ | Tool | Description |
87
+ |------|-------------|
88
+ | **Stock Data** | |
89
+ | `get_stock_price` | Get current price, market cap, and price changes |
90
+ | `get_stock_summary` | Get P/E ratio, volume, 52-week range, dividend yield |
91
+ | `get_stock_profile` | Get company info (industry, sector, employees) |
92
+ | `get_stock_history` | Get historical OHLCV price data |
93
+ | `get_financials` | Get income statement, balance sheet, cash flow |
94
+ | `get_options` | Get option chain (calls, puts, strikes, Greeks) |
95
+ | `get_key_stats` | Get forward P/E, PEG ratio, beta, EPS |
96
+ | `get_recommendations` | Get analyst recommendations |
97
+ | `get_earnings` | Get earnings data (EPS estimates/actuals) |
98
+ | **Screeners** | |
99
+ | `list_screeners` | List all 300+ available screeners |
100
+ | `get_screener` | Run a screener (day_gainers, most_actives, etc.) |
101
+ | `get_screener_info` | Get screener details |
102
+ | **Research** | |
103
+ | `get_earnings_calendar` | Get upcoming earnings announcements |
104
+ | `get_ipos` | Get upcoming and recent IPOs |
105
+ | `get_splits` | Get upcoming and recent stock splits |
106
+ | **Market Data** | |
107
+ | `search_stocks` | Search for stocks by name or symbol |
108
+ | `get_market_summary` | Get major indices (S&P 500, Dow, NASDAQ) |
109
+ | `get_trending` | Get trending/most watched stocks |
110
+ | `get_currencies` | Get currency pairs and exchange rates |
111
+ | `get_supported_countries` | Get list of supported countries |
112
+
113
+ ### Example AI Interactions
114
+
115
+ Once configured, you can ask Claude things like:
116
+
117
+ - "What's the current price of AAPL?"
118
+ - "Show me the top 10 day gainers"
119
+ - "Get the financial statements for Microsoft"
120
+ - "What stocks are trending right now?"
121
+ - "Search for electric vehicle companies"
122
+ - "What are the upcoming earnings this week?"
123
+
124
+ ### Running MCP Server Manually
125
+
126
+ ```bash
127
+ # Using npm scripts
128
+ npm run mcp
129
+
130
+ # Or directly
131
+ npx yfinance-mcp
132
+
133
+ # Or with node
134
+ node dist/mcp/server.js
135
+ ```
136
+
137
+ ## Installation
138
+
139
+ ```bash
140
+ npm install yfinance-mcp-ts
141
+ ```
142
+
143
+ For premium features (optional):
144
+ ```bash
145
+ npm install puppeteer
146
+ ```
147
+
148
+ ## Quick Start
149
+
150
+ ```typescript
151
+ import { Ticker } from 'yfinance-mcp-ts';
152
+
153
+ // Create a ticker for one or more symbols
154
+ const ticker = new Ticker('AAPL');
155
+ // or multiple symbols
156
+ const tickers = new Ticker('AAPL MSFT GOOG');
157
+ // or as an array
158
+ const tickersArray = new Ticker(['AAPL', 'MSFT', 'GOOG']);
159
+
160
+ // Get price data
161
+ const price = await ticker.getPrice();
162
+ console.log(price);
163
+
164
+ // Get historical data
165
+ const history = await ticker.getHistory({ period: '1mo', interval: '1d' });
166
+ console.log(history);
167
+
168
+ // Get financial statements
169
+ const income = await ticker.getIncomeStatement('a'); // 'a' for annual, 'q' for quarterly
170
+ console.log(income);
171
+ ```
172
+
173
+ ## API Reference
174
+
175
+ ### Ticker Class
176
+
177
+ The main class for accessing stock data.
178
+
179
+ ```typescript
180
+ import { Ticker, createTicker } from 'yfinance-mcp-ts';
181
+
182
+ // Constructor
183
+ const ticker = new Ticker(symbols, options?);
184
+
185
+ // Or use the async factory (auto-initializes session)
186
+ const ticker = await createTicker(symbols, options?);
187
+ ```
188
+
189
+ #### Options
190
+
191
+ ```typescript
192
+ interface TickerOptions {
193
+ country?: string; // Default: 'united states'
194
+ formatted?: boolean; // Return formatted values (default: false)
195
+ progress?: boolean; // Show progress (default: false)
196
+ validate?: boolean; // Validate symbols on creation
197
+ username?: string; // Yahoo username for premium
198
+ password?: string; // Yahoo password for premium
199
+ timeout?: number; // Request timeout in ms (default: 30000)
200
+
201
+ // Retry configuration
202
+ retry?: {
203
+ enabled?: boolean; // Enable automatic retry (default: true)
204
+ maxRetries?: number; // Max retry attempts (default: 3)
205
+ initialDelay?: number; // Initial delay in ms (default: 1000)
206
+ maxDelay?: number; // Max delay in ms (default: 30000)
207
+ factor?: number; // Exponential backoff factor (default: 2)
208
+ jitter?: boolean; // Add random jitter (default: true)
209
+ };
210
+
211
+ // Proxy rotation configuration
212
+ proxyRotation?: {
213
+ proxyList?: string; // Newline-separated proxy URLs
214
+ maxFailures?: number; // Failures before unhealthy (default: 3)
215
+ cooldownMs?: number; // Cooldown period in ms (default: 300000)
216
+ };
217
+ }
218
+ ```
219
+
220
+ #### Quote Summary Methods
221
+
222
+ ```typescript
223
+ // Get all available modules
224
+ const allData = await ticker.getAllModules();
225
+
226
+ // Get specific modules
227
+ const data = await ticker.getModules(['price', 'summaryDetail']);
228
+
229
+ // Individual module methods
230
+ await ticker.getPrice(); // Current price and market data
231
+ await ticker.getSummaryDetail(); // Summary statistics
232
+ await ticker.getSummaryProfile(); // Company profile
233
+ await ticker.getAssetProfile(); // Detailed company info
234
+ await ticker.getKeyStats(); // Key statistics
235
+ await ticker.getFinancialDataSummary(); // Financial KPIs
236
+ await ticker.getEarnings(); // Earnings data
237
+ await ticker.getEarningsTrend(); // Earnings trend
238
+ await ticker.getCalendarEvents(); // Upcoming events
239
+ await ticker.getRecommendationTrend(); // Analyst recommendations
240
+ await ticker.getEsgScores(); // ESG metrics
241
+ await ticker.getMajorHolders(); // Major shareholders
242
+ await ticker.getInsiderHolders(); // Insider holdings
243
+ await ticker.getInsiderTransactions(); // Insider transactions
244
+ await ticker.getInstitutionOwnership(); // Institutional ownership
245
+ await ticker.getFundOwnership(); // Fund ownership
246
+ await ticker.getSecFilings(); // SEC filings
247
+ await ticker.getQuoteType(); // Quote type info
248
+ await ticker.getGradingHistory(); // Upgrade/downgrade history
249
+ ```
250
+
251
+ #### Historical Data
252
+
253
+ ```typescript
254
+ // Get historical data
255
+ const history = await ticker.getHistory({
256
+ period: '1mo', // 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
257
+ interval: '1d', // 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
258
+ start: '2024-01-01', // Optional: start date
259
+ end: '2024-12-31', // Optional: end date
260
+ adjOhlc: false, // Adjust OHLC for splits/dividends
261
+ adjTimezone: true, // Adjust for exchange timezone
262
+ });
263
+
264
+ // Get dividend history
265
+ const dividends = await ticker.getDividendHistory('2020-01-01', '2024-01-01');
266
+ ```
267
+
268
+ #### Financial Statements
269
+
270
+ ```typescript
271
+ // Income Statement
272
+ const income = await ticker.getIncomeStatement('a'); // 'a' annual, 'q' quarterly
273
+
274
+ // Balance Sheet
275
+ const balance = await ticker.getBalanceSheet('a');
276
+
277
+ // Cash Flow Statement
278
+ const cashFlow = await ticker.getCashFlow('a');
279
+
280
+ // Valuation Measures
281
+ const valuation = await ticker.getValuationMeasures();
282
+
283
+ // All Financial Data
284
+ const allFinancials = await ticker.getAllFinancialData('a');
285
+
286
+ // Specific financial types
287
+ const specific = await ticker.getFinancialData(['TotalRevenue', 'NetIncome'], 'a');
288
+ ```
289
+
290
+ #### Options
291
+
292
+ ```typescript
293
+ // Get full options chain
294
+ const options = await ticker.getOptionChain();
295
+ // Returns: { AAPL: { calls: [...], puts: [...], expirationDates: [...], strikes: [...] } }
296
+ ```
297
+
298
+ #### Fund-Specific Methods (ETFs, Mutual Funds)
299
+
300
+ ```typescript
301
+ await ticker.getFundHoldingInfo(); // All holding info
302
+ await ticker.getFundTopHoldings(); // Top holdings
303
+ await ticker.getFundSectorWeightings(); // Sector allocation
304
+ await ticker.getFundBondHoldings(); // Bond holdings
305
+ await ticker.getFundEquityHoldings(); // Equity holdings
306
+ await ticker.getFundBondRatings(); // Bond ratings
307
+ await ticker.getFundPerformance(); // Performance data
308
+ await ticker.getFundProfile(); // Fund profile
309
+ ```
310
+
311
+ #### Additional Methods
312
+
313
+ ```typescript
314
+ await ticker.getQuotes(); // Quick quotes
315
+ await ticker.getRecommendations(); // Similar stocks
316
+ await ticker.getTechnicalInsights(); // Technical analysis
317
+ await ticker.getNews(25); // Recent news
318
+ await ticker.getCompanyOfficers(); // Company executives
319
+ await ticker.validate(); // Validate symbols
320
+ ```
321
+
322
+ ### Screener Class
323
+
324
+ Access Yahoo Finance predefined screeners.
325
+
326
+ ```typescript
327
+ import { Screener, createScreener } from 'yfinance-mcp-ts';
328
+
329
+ const screener = new Screener();
330
+
331
+ // Get available screeners (300+)
332
+ const available = screener.availableScreeners;
333
+ // ['day_gainers', 'day_losers', 'most_actives', 'aggressive_small_caps', ...]
334
+
335
+ // Get screener info
336
+ const info = screener.getScreenerInfo('day_gainers');
337
+
338
+ // Run screeners
339
+ const results = await screener.getScreeners('day_gainers', 25);
340
+ // or multiple
341
+ const multi = await screener.getScreeners('day_gainers most_actives', 25);
342
+ ```
343
+
344
+ #### Popular Screeners
345
+
346
+ - `day_gainers` - Top gaining stocks today
347
+ - `day_losers` - Top losing stocks today
348
+ - `most_actives` - Most actively traded
349
+ - `aggressive_small_caps` - Small cap growth stocks
350
+ - `conservative_foreign_funds` - Conservative international funds
351
+ - `growth_technology_stocks` - Tech growth stocks
352
+ - `high_yield_bond` - High yield bonds
353
+ - `undervalued_growth_stocks` - Undervalued growth stocks
354
+ - `undervalued_large_caps` - Undervalued large caps
355
+
356
+ ### Research Class
357
+
358
+ Access research reports, trade ideas, and market events (some features require Premium).
359
+
360
+ ```typescript
361
+ import { Research, createResearch } from 'yfinance-mcp-ts';
362
+
363
+ const research = new Research();
364
+
365
+ // Get research reports (Premium)
366
+ const reports = await research.getReports(100, {
367
+ sector: 'Technology',
368
+ investment_rating: 'Bullish',
369
+ report_date: 'Last Month',
370
+ });
371
+
372
+ // Get trade ideas (Premium)
373
+ const trades = await research.getTrades(100, {
374
+ trend: 'Bullish',
375
+ term: 'Short term',
376
+ });
377
+
378
+ // Get earnings calendar
379
+ const earnings = await research.getEarnings('2024-01-01', '2024-01-31');
380
+
381
+ // Get stock splits
382
+ const splits = await research.getSplits('2024-01-01', '2024-12-31');
383
+
384
+ // Get IPO calendar
385
+ const ipos = await research.getIPOs('2024-01-01', '2024-12-31');
386
+ ```
387
+
388
+ ### Standalone Functions
389
+
390
+ ```typescript
391
+ import {
392
+ search,
393
+ getCurrencies,
394
+ getMarketSummary,
395
+ getTrending,
396
+ getValidCountries
397
+ } from 'yfinance-mcp-ts';
398
+
399
+ // Search Yahoo Finance
400
+ const results = await search('Apple', { quotesCount: 10, newsCount: 5 });
401
+
402
+ // Get first quote only
403
+ const apple = await search('AAPL', { firstQuote: true });
404
+
405
+ // Get available currencies
406
+ const currencies = await getCurrencies();
407
+
408
+ // Get market summary (major indices)
409
+ const summary = await getMarketSummary('united states');
410
+
411
+ // Get trending stocks
412
+ const trending = await getTrending('united states');
413
+
414
+ // Get valid countries
415
+ const countries = getValidCountries();
416
+ // ['united states', 'france', 'germany', 'united kingdom', ...]
417
+ ```
418
+
419
+ ### Proxy Rotation
420
+
421
+ Distribute requests across multiple proxies to avoid rate limits and IP blocks. The ProxyManager automatically rotates through proxies and tracks failures.
422
+
423
+ ```typescript
424
+ import { Ticker, createSession } from 'yfinance-mcp-ts';
425
+
426
+ // Option 1: Configure via Ticker options
427
+ const ticker = new Ticker('AAPL', {
428
+ proxyRotation: {
429
+ proxyList: `
430
+ http://user:pass@proxy1.example.com:8080
431
+ http://user:pass@proxy2.example.com:8080
432
+ socks5://proxy3.example.com:1080
433
+ `,
434
+ maxFailures: 3, // Mark unhealthy after 3 failures
435
+ cooldownMs: 300000, // 5 min cooldown before retry
436
+ },
437
+ });
438
+
439
+ // Option 2: Create session with proxies
440
+ const session = await createSession({
441
+ proxyRotation: {
442
+ proxyList: process.env.PROXY_LIST || '',
443
+ },
444
+ });
445
+
446
+ // Check proxy status
447
+ console.log('Proxy rotation enabled:', session.hasProxyRotation());
448
+ console.log('Proxy stats:', session.getProxyStats());
449
+ ```
450
+
451
+ #### Supported Proxy Formats
452
+
453
+ ```
454
+ http://host:port # HTTP proxy without auth
455
+ http://username:password@host:port # HTTP proxy with auth
456
+ https://host:port # HTTPS proxy
457
+ socks5://username:password@host:port # SOCKS5 proxy
458
+ ```
459
+
460
+ #### Proxy Rotation Features
461
+
462
+ - **Round-robin rotation**: Automatically cycles through available proxies
463
+ - **Failure tracking**: Marks proxies as unhealthy after consecutive failures
464
+ - **Automatic recovery**: Unhealthy proxies are retried after cooldown period
465
+ - **Statistics**: Monitor proxy health and success rates
466
+
467
+ #### Required Dependencies
468
+
469
+ For proxy support, install the optional dependencies:
470
+
471
+ ```bash
472
+ npm install https-proxy-agent socks-proxy-agent
473
+ ```
474
+
475
+ ### Premium Features
476
+
477
+ For Yahoo Finance Premium subscribers:
478
+
479
+ ```typescript
480
+ import { Ticker, yahooLogin, hasPuppeteer } from 'yfinance-mcp-ts';
481
+
482
+ // Check if puppeteer is installed
483
+ const hasPup = await hasPuppeteer();
484
+
485
+ // Option 1: Manual login
486
+ const result = await yahooLogin('your@email.com', 'password');
487
+ if (result.success) {
488
+ console.log('Logged in successfully');
489
+ }
490
+
491
+ // Option 2: Auto-login with Ticker
492
+ const ticker = new Ticker('AAPL', {
493
+ username: 'your@email.com',
494
+ password: 'password',
495
+ });
496
+
497
+ // Check if premium is active
498
+ const session = ticker['session']; // Access internal session
499
+ console.log(session.hasPremium());
500
+ ```
501
+
502
+ ## Configuration
503
+
504
+ ### Countries
505
+
506
+ The library supports 14 countries/regions:
507
+
508
+ | Country | Lang | Region |
509
+ |---------|------|--------|
510
+ | united states | en-US | US |
511
+ | australia | en-AU | AU |
512
+ | canada | en-CA | CA |
513
+ | france | fr-FR | FR |
514
+ | germany | de-DE | DE |
515
+ | hong kong | zh-Hant-HK | HK |
516
+ | india | en-IN | IN |
517
+ | italy | it-IT | IT |
518
+ | spain | es-ES | ES |
519
+ | united kingdom | en-GB | GB |
520
+ | brazil | pt-BR | BR |
521
+ | new zealand | en-NZ | NZ |
522
+ | singapore | en-SG | SG |
523
+ | taiwan | zh-TW | TW |
524
+
525
+ ```typescript
526
+ const ticker = new Ticker('AAPL', { country: 'germany' });
527
+ ```
528
+
529
+ ### Intervals
530
+
531
+ For historical data:
532
+
533
+ | Interval | Description |
534
+ |----------|-------------|
535
+ | 1m | 1 minute |
536
+ | 2m | 2 minutes |
537
+ | 5m | 5 minutes |
538
+ | 15m | 15 minutes |
539
+ | 30m | 30 minutes |
540
+ | 60m / 1h | 1 hour |
541
+ | 90m | 90 minutes |
542
+ | 1d | 1 day |
543
+ | 5d | 5 days |
544
+ | 1wk | 1 week |
545
+ | 1mo | 1 month |
546
+ | 3mo | 3 months |
547
+
548
+ ### Periods
549
+
550
+ | Period | Description |
551
+ |--------|-------------|
552
+ | 1d | 1 day |
553
+ | 5d | 5 days |
554
+ | 1mo | 1 month |
555
+ | 3mo | 3 months |
556
+ | 6mo | 6 months |
557
+ | 1y | 1 year |
558
+ | 2y | 2 years |
559
+ | 5y | 5 years |
560
+ | 10y | 10 years |
561
+ | ytd | Year to date |
562
+ | max | Maximum available |
563
+
564
+ ## Error Handling
565
+
566
+ ```typescript
567
+ import { Ticker } from 'yfinance-mcp-ts';
568
+
569
+ try {
570
+ const ticker = new Ticker('INVALID_SYMBOL');
571
+ const price = await ticker.getPrice();
572
+
573
+ if (price.INVALID_SYMBOL && typeof price.INVALID_SYMBOL === 'string') {
574
+ console.error('Error:', price.INVALID_SYMBOL);
575
+ }
576
+ } catch (error) {
577
+ console.error('Request failed:', error.message);
578
+ }
579
+
580
+ // Validate symbols
581
+ const ticker = new Ticker('AAPL INVALID');
582
+ const { valid, invalid } = await ticker.validateSymbols();
583
+ console.log('Valid:', valid); // ['AAPL']
584
+ console.log('Invalid:', invalid); // ['INVALID']
585
+ ```
586
+
587
+ ## TypeScript Support
588
+
589
+ Full TypeScript support with exported types:
590
+
591
+ ```typescript
592
+ import {
593
+ // Classes
594
+ Ticker,
595
+ Screener,
596
+ Research,
597
+ SessionManager,
598
+ ProxyManager,
599
+
600
+ // Types
601
+ TickerOptions,
602
+ HistoryParams,
603
+ SessionOptions,
604
+ RetryConfig,
605
+ ProxyRotationConfig,
606
+ ProxyConfig,
607
+ SearchResult,
608
+ AuthCookie,
609
+ } from 'yfinance-mcp-ts';
610
+ ```
611
+
612
+ ## Requirements
613
+
614
+ - Node.js >= 18.0.0
615
+ - TypeScript >= 5.0 (for development)
616
+ - puppeteer >= 21.0.0 (optional, for premium features)
617
+
618
+ ## License
619
+
620
+ MIT
621
+
622
+ ## Credits
623
+
624
+ This is a TypeScript port of the excellent [yahooquery](https://github.com/dpguthrie/yahooquery) Python library by Doug Guthrie.
625
+
626
+ ## Disclaimer
627
+
628
+ This library is not affiliated with Yahoo, Inc. The data retrieved is for personal use only. Please review Yahoo's terms of service before using this library in production applications.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * HeadlessAuth - Puppeteer-based authentication for Yahoo Finance Premium
3
+ *
4
+ * This module provides headless browser authentication for accessing
5
+ * Yahoo Finance Premium features that require a subscription.
6
+ *
7
+ * Note: Requires puppeteer to be installed separately:
8
+ * npm install puppeteer
9
+ */
10
+ export interface AuthCookie {
11
+ name: string;
12
+ value: string;
13
+ domain: string;
14
+ path: string;
15
+ expires?: number;
16
+ httpOnly?: boolean;
17
+ secure?: boolean;
18
+ }
19
+ export interface HeadlessAuthResult {
20
+ success: boolean;
21
+ cookies: AuthCookie[];
22
+ error?: string;
23
+ }
24
+ /**
25
+ * Check if puppeteer is available
26
+ */
27
+ export declare function hasPuppeteer(): Promise<boolean>;
28
+ /**
29
+ * HeadlessAuth class for Yahoo Finance Premium authentication
30
+ */
31
+ export declare class HeadlessAuth {
32
+ private readonly username;
33
+ private readonly password;
34
+ private static readonly LOGIN_URL;
35
+ private static readonly TIMEOUT;
36
+ private browser;
37
+ private cookies;
38
+ constructor(username: string, password: string);
39
+ /**
40
+ * Perform login and retrieve authentication cookies
41
+ */
42
+ login(): Promise<HeadlessAuthResult>;
43
+ /**
44
+ * Get the retrieved cookies
45
+ */
46
+ getCookies(): AuthCookie[];
47
+ /**
48
+ * Close the browser instance
49
+ */
50
+ close(): Promise<void>;
51
+ /**
52
+ * Convert Puppeteer cookies to our cookie format
53
+ */
54
+ private convertCookies;
55
+ /**
56
+ * Delay helper
57
+ */
58
+ private delay;
59
+ }
60
+ /**
61
+ * Perform Yahoo Finance Premium login
62
+ *
63
+ * @param username - Yahoo username/email
64
+ * @param password - Yahoo password
65
+ * @returns Authentication result with cookies
66
+ */
67
+ export declare function yahooLogin(username: string, password: string): Promise<HeadlessAuthResult>;
68
+ //# sourceMappingURL=HeadlessAuth.d.ts.map