yfinance-mcp-ts 1.1.0 → 1.2.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.
- package/README.md +175 -6
- package/dist/config/browsers.d.ts +44 -0
- package/dist/config/browsers.d.ts.map +1 -1
- package/dist/config/browsers.js +163 -1
- package/dist/config/browsers.js.map +1 -1
- package/dist/core/ImpitClient.d.ts +192 -0
- package/dist/core/ImpitClient.d.ts.map +1 -0
- package/dist/core/ImpitClient.js +334 -0
- package/dist/core/ImpitClient.js.map +1 -0
- package/dist/core/ProxyManager.d.ts +5 -0
- package/dist/core/ProxyManager.d.ts.map +1 -1
- package/dist/core/ProxyManager.js +11 -4
- package/dist/core/ProxyManager.js.map +1 -1
- package/dist/core/SessionManager.d.ts +96 -9
- package/dist/core/SessionManager.d.ts.map +1 -1
- package/dist/core/SessionManager.js +440 -96
- package/dist/core/SessionManager.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/config.d.ts +5 -2
- package/dist/mcp/config.d.ts.map +1 -1
- package/dist/mcp/config.js +39 -6
- package/dist/mcp/config.js.map +1 -1
- package/dist/types/impit.d.ts +131 -0
- package/dist/types/impit.d.ts.map +1 -0
- package/dist/types/impit.js +103 -0
- package/dist/types/impit.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/helpers.d.ts +7 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +45 -3
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/migration.d.ts +90 -0
- package/dist/utils/migration.d.ts.map +1 -0
- package/dist/utils/migration.js +218 -0
- package/dist/utils/migration.js.map +1 -0
- package/dist/utils/performance.d.ts +177 -0
- package/dist/utils/performance.d.ts.map +1 -0
- package/dist/utils/performance.js +290 -0
- package/dist/utils/performance.js.map +1 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ A TypeScript wrapper for the unofficial Yahoo Finance API. This library provides
|
|
|
13
13
|
- **Search**: Search for stocks, ETFs, mutual funds, and more
|
|
14
14
|
- **Premium Support**: Optional Yahoo Finance Premium authentication
|
|
15
15
|
- **MCP Server**: Built-in Model Context Protocol server for AI agents (Claude, etc.)
|
|
16
|
+
- **Browser Impersonation**: TLS fingerprinting bypass using impit - achieves 100% success rate vs constant rate limiting with traditional HTTP clients
|
|
16
17
|
- **Proxy Rotation**: Distribute requests across multiple proxies with automatic failure tracking
|
|
17
18
|
- **Retry with Backoff**: Automatic retry with exponential backoff for rate limits and transient errors
|
|
18
19
|
|
|
@@ -29,7 +30,7 @@ Add to your Claude Desktop configuration (`~/.config/claude/claude_desktop_confi
|
|
|
29
30
|
"mcpServers": {
|
|
30
31
|
"yfinance": {
|
|
31
32
|
"command": "npx",
|
|
32
|
-
"args": ["yfinance-mcp"]
|
|
33
|
+
"args": ["yfinance-mcp-ts"]
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -72,13 +73,16 @@ To use proxy rotation with the MCP server, configure environment variables:
|
|
|
72
73
|
|
|
73
74
|
| Variable | Description | Default |
|
|
74
75
|
|----------|-------------|---------|
|
|
76
|
+
| `YFINANCE_HTTP_CLIENT` | HTTP client: 'impit' or 'axios' | impit |
|
|
77
|
+
| `YFINANCE_HTTP3` | Enable HTTP/3 (impit only) | false |
|
|
78
|
+
| `YFINANCE_IGNORE_TLS_ERRORS` | Ignore TLS certificate errors | false |
|
|
75
79
|
| `YFINANCE_PROXY_LIST` | Newline-separated proxy URLs | - |
|
|
76
80
|
| `YFINANCE_PROXY_MAX_FAILURES` | Failures before marking proxy unhealthy | 3 |
|
|
77
81
|
| `YFINANCE_PROXY_COOLDOWN_MS` | Cooldown before retrying unhealthy proxy | 300000 |
|
|
78
82
|
| `YFINANCE_RETRY_ENABLED` | Enable automatic retry | true |
|
|
79
|
-
| `YFINANCE_RETRY_MAX_RETRIES` | Maximum retry attempts |
|
|
80
|
-
| `YFINANCE_RETRY_INITIAL_DELAY` | Initial retry delay (ms) |
|
|
81
|
-
| `YFINANCE_RETRY_MAX_DELAY` | Maximum retry delay (ms) |
|
|
83
|
+
| `YFINANCE_RETRY_MAX_RETRIES` | Maximum retry attempts | 5 |
|
|
84
|
+
| `YFINANCE_RETRY_INITIAL_DELAY` | Initial retry delay (ms) | 2000 |
|
|
85
|
+
| `YFINANCE_RETRY_MAX_DELAY` | Maximum retry delay (ms) | 60000 |
|
|
82
86
|
| `YFINANCE_TIMEOUT` | Request timeout (ms) | 30000 |
|
|
83
87
|
|
|
84
88
|
### Available MCP Tools (20 tools)
|
|
@@ -128,7 +132,7 @@ Once configured, you can ask Claude things like:
|
|
|
128
132
|
npm run mcp
|
|
129
133
|
|
|
130
134
|
# Or directly
|
|
131
|
-
npx yfinance-mcp
|
|
135
|
+
npx yfinance-mcp-ts
|
|
132
136
|
|
|
133
137
|
# Or with node
|
|
134
138
|
node dist/mcp/server.js
|
|
@@ -609,9 +613,174 @@ import {
|
|
|
609
613
|
} from 'yfinance-mcp-ts';
|
|
610
614
|
```
|
|
611
615
|
|
|
616
|
+
## HTTP Client Configuration
|
|
617
|
+
|
|
618
|
+
yfinance-mcp-ts supports two HTTP client backends:
|
|
619
|
+
|
|
620
|
+
### impit (Default, Recommended)
|
|
621
|
+
|
|
622
|
+
**impit** provides sophisticated browser impersonation with TLS fingerprinting bypass. This is the recommended option for avoiding rate limits and blocks from Yahoo Finance.
|
|
623
|
+
|
|
624
|
+
#### Why impit?
|
|
625
|
+
|
|
626
|
+
Yahoo Finance uses aggressive anti-bot measures including TLS fingerprinting to detect and block automated requests. Our benchmarks show a dramatic difference:
|
|
627
|
+
|
|
628
|
+
| HTTP Client | Rate Limit Errors | Success Rate |
|
|
629
|
+
|-------------|-------------------|--------------|
|
|
630
|
+
| **impit** | 0 errors | 100% |
|
|
631
|
+
| **axios** | Multiple 429 errors per request | Very low |
|
|
632
|
+
|
|
633
|
+
With impit, requests are indistinguishable from real browser traffic because it:
|
|
634
|
+
- Matches real Chrome/Firefox TLS fingerprints (JA3/JA4)
|
|
635
|
+
- Uses correct HTTP/2 pseudo-header ordering
|
|
636
|
+
- Includes proper browser headers and timing patterns
|
|
637
|
+
|
|
638
|
+
#### Features
|
|
639
|
+
|
|
640
|
+
- TLS fingerprinting that matches real Chrome/Firefox browsers
|
|
641
|
+
- HTTP/2 pseudo-header ordering matching real browsers
|
|
642
|
+
- Automatic cookie handling
|
|
643
|
+
- Optional HTTP/3 support
|
|
644
|
+
- Browser rotation to further avoid detection
|
|
645
|
+
|
|
646
|
+
```typescript
|
|
647
|
+
import { SessionManager, Ticker } from 'yfinance-mcp-ts';
|
|
648
|
+
|
|
649
|
+
// impit is used by default
|
|
650
|
+
const session = new SessionManager();
|
|
651
|
+
|
|
652
|
+
// Or explicitly specify
|
|
653
|
+
const session = new SessionManager({
|
|
654
|
+
httpClient: 'impit',
|
|
655
|
+
http3: false, // Optional HTTP/3 support (experimental)
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// With Ticker
|
|
659
|
+
const ticker = new Ticker('AAPL', { httpClient: 'impit' });
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
### axios (Fallback)
|
|
663
|
+
|
|
664
|
+
**axios** is available as a fallback if impit is not supported on your platform. Note that axios is more likely to encounter rate limiting.
|
|
665
|
+
|
|
666
|
+
```typescript
|
|
667
|
+
const session = new SessionManager({
|
|
668
|
+
httpClient: 'axios',
|
|
669
|
+
});
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
### Environment Variables
|
|
673
|
+
|
|
674
|
+
Configure HTTP client behavior via environment variables:
|
|
675
|
+
|
|
676
|
+
| Variable | Description | Default |
|
|
677
|
+
|----------|-------------|---------|
|
|
678
|
+
| `YFINANCE_HTTP_CLIENT` | HTTP client: 'impit' or 'axios' | impit |
|
|
679
|
+
| `YFINANCE_HTTP3` | Enable HTTP/3 (impit only): 'true'/'false' | false |
|
|
680
|
+
| `YFINANCE_IGNORE_TLS_ERRORS` | Ignore TLS errors: 'true'/'false' | false |
|
|
681
|
+
| `YFINANCE_REQUEST_TIMEOUT` | Request timeout in milliseconds | 30000 |
|
|
682
|
+
|
|
683
|
+
### Migration Utilities
|
|
684
|
+
|
|
685
|
+
For automatic client detection and configuration:
|
|
686
|
+
|
|
687
|
+
```typescript
|
|
688
|
+
import {
|
|
689
|
+
isImpitAvailable,
|
|
690
|
+
getRecommendedHttpClient,
|
|
691
|
+
getHttpClientConfigFromEnv,
|
|
692
|
+
createAutoConfiguredSession,
|
|
693
|
+
logMigrationStatus,
|
|
694
|
+
} from 'yfinance-mcp-ts';
|
|
695
|
+
|
|
696
|
+
// Check if impit is available
|
|
697
|
+
const hasImpit = await isImpitAvailable();
|
|
698
|
+
console.log('Impit available:', hasImpit);
|
|
699
|
+
|
|
700
|
+
// Get recommended client based on environment
|
|
701
|
+
const recommended = await getRecommendedHttpClient();
|
|
702
|
+
console.log('Recommended client:', recommended);
|
|
703
|
+
|
|
704
|
+
// Create session with automatic configuration
|
|
705
|
+
const session = await createAutoConfiguredSession({
|
|
706
|
+
retry: { maxRetries: 5 },
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// Debug: log migration status
|
|
710
|
+
await logMigrationStatus(true);
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### Browser Rotation (impit only)
|
|
714
|
+
|
|
715
|
+
When using impit, you can rotate browser fingerprints to help avoid detection:
|
|
716
|
+
|
|
717
|
+
```typescript
|
|
718
|
+
const session = new SessionManager({ httpClient: 'impit' });
|
|
719
|
+
await session.initialize();
|
|
720
|
+
|
|
721
|
+
// Get current browser info
|
|
722
|
+
const browser = session.getCurrentBrowser();
|
|
723
|
+
console.log(browser); // { browser: 'chrome', platform: 'windows', headers: {...} }
|
|
724
|
+
|
|
725
|
+
// Rotate to a new browser fingerprint
|
|
726
|
+
const newBrowser = session.rotateBrowser();
|
|
727
|
+
console.log(newBrowser); // { browser: 'firefox', platform: 'macos', headers: {...} }
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
### Performance Utilities
|
|
731
|
+
|
|
732
|
+
The library includes utilities for optimizing API request patterns:
|
|
733
|
+
|
|
734
|
+
```typescript
|
|
735
|
+
import {
|
|
736
|
+
batchExecute,
|
|
737
|
+
RequestThrottler,
|
|
738
|
+
ResponseCache,
|
|
739
|
+
createCacheKey,
|
|
740
|
+
getGlobalImpitClient,
|
|
741
|
+
} from 'yfinance-mcp-ts';
|
|
742
|
+
|
|
743
|
+
// Batch execution with concurrency control
|
|
744
|
+
const symbols = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'META'];
|
|
745
|
+
const tasks = symbols.map(symbol => () => fetchQuote(symbol));
|
|
746
|
+
const results = await batchExecute(tasks, {
|
|
747
|
+
concurrency: 3, // Max 3 concurrent requests
|
|
748
|
+
batchDelay: 200, // 200ms between batches
|
|
749
|
+
onProgress: (done, total) => console.log(`${done}/${total}`),
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
// Request throttling
|
|
753
|
+
const throttler = new RequestThrottler(100); // 100ms min delay
|
|
754
|
+
await throttler.throttle(); // Wait if needed
|
|
755
|
+
await makeRequest();
|
|
756
|
+
|
|
757
|
+
// Response caching with TTL
|
|
758
|
+
const cache = new ResponseCache<QuoteData>(60000); // 1 minute TTL
|
|
759
|
+
const quote = await cache.getOrSet('AAPL', () => fetchQuote('AAPL'));
|
|
760
|
+
|
|
761
|
+
// Global client for connection reuse
|
|
762
|
+
const client = getGlobalImpitClient({ timeout: 30000 });
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
### Request Delay Configuration
|
|
766
|
+
|
|
767
|
+
Control the delay between sequential API requests to prevent rate limiting:
|
|
768
|
+
|
|
769
|
+
```typescript
|
|
770
|
+
const session = new SessionManager({
|
|
771
|
+
httpClient: 'impit',
|
|
772
|
+
requestDelay: 100, // 100ms minimum delay between requests (default)
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// Or disable throttling
|
|
776
|
+
const fastSession = new SessionManager({
|
|
777
|
+
requestDelay: 0, // No delay
|
|
778
|
+
});
|
|
779
|
+
```
|
|
780
|
+
|
|
612
781
|
## Requirements
|
|
613
782
|
|
|
614
|
-
- Node.js >=
|
|
783
|
+
- Node.js >= 20.0.0 (required for impit)
|
|
615
784
|
- TypeScript >= 5.0 (for development)
|
|
616
785
|
- puppeteer >= 21.0.0 (optional, for premium features)
|
|
617
786
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Browser fingerprint configurations for Yahoo Finance API requests.
|
|
3
3
|
* These headers help avoid detection and blocking.
|
|
4
4
|
*/
|
|
5
|
+
import type { Browser } from 'impit';
|
|
5
6
|
export interface BrowserHeaders {
|
|
6
7
|
'sec-ch-ua': string;
|
|
7
8
|
'sec-ch-ua-mobile': string;
|
|
@@ -17,6 +18,18 @@ export interface BrowserHeaders {
|
|
|
17
18
|
'accept-language': string;
|
|
18
19
|
'priority'?: string;
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Browser configuration for impit library.
|
|
23
|
+
* Maps browser names to impit browser types and supplementary headers.
|
|
24
|
+
*/
|
|
25
|
+
export interface ImpitBrowserConfig {
|
|
26
|
+
/** The impit browser type to use for TLS fingerprinting */
|
|
27
|
+
browser: Browser;
|
|
28
|
+
/** Platform identifier for logging/debugging */
|
|
29
|
+
platform: 'windows' | 'macos' | 'linux';
|
|
30
|
+
/** Supplementary headers to use with this browser config */
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
}
|
|
20
33
|
export declare const BROWSERS: Record<string, BrowserHeaders>;
|
|
21
34
|
/**
|
|
22
35
|
* Get a random browser fingerprint for request headers
|
|
@@ -26,4 +39,35 @@ export declare function getRandomBrowser(): [string, BrowserHeaders];
|
|
|
26
39
|
* Get browser headers as a plain object (for axios)
|
|
27
40
|
*/
|
|
28
41
|
export declare function getBrowserHeadersAsRecord(browser: BrowserHeaders): Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Chrome browser configurations for impit.
|
|
44
|
+
* impit uses Chrome 125 TLS fingerprinting internally.
|
|
45
|
+
* These headers supplement the TLS-level impersonation.
|
|
46
|
+
*/
|
|
47
|
+
export declare const IMPIT_CHROME_CONFIGS: ImpitBrowserConfig[];
|
|
48
|
+
/**
|
|
49
|
+
* Firefox browser configurations for impit.
|
|
50
|
+
* impit uses Firefox 128 TLS fingerprinting internally.
|
|
51
|
+
*/
|
|
52
|
+
export declare const IMPIT_FIREFOX_CONFIGS: ImpitBrowserConfig[];
|
|
53
|
+
/**
|
|
54
|
+
* All impit browser configurations combined.
|
|
55
|
+
* Chrome configs are weighted more heavily (3:1 ratio) as they're more common.
|
|
56
|
+
*/
|
|
57
|
+
export declare const ALL_IMPIT_CONFIGS: ImpitBrowserConfig[];
|
|
58
|
+
/**
|
|
59
|
+
* Get a random impit browser configuration.
|
|
60
|
+
* Chrome is weighted 2:1 over Firefox to reflect real-world usage.
|
|
61
|
+
*
|
|
62
|
+
* @returns A random impit browser configuration
|
|
63
|
+
*/
|
|
64
|
+
export declare function getRandomImpitBrowserConfig(): ImpitBrowserConfig;
|
|
65
|
+
/**
|
|
66
|
+
* Get a specific impit browser configuration.
|
|
67
|
+
*
|
|
68
|
+
* @param browser - The browser type ('chrome' or 'firefox')
|
|
69
|
+
* @param platform - Optional platform preference ('windows', 'macos', 'linux')
|
|
70
|
+
* @returns The matching browser configuration, or a random one if not found
|
|
71
|
+
*/
|
|
72
|
+
export declare function getImpitBrowserConfig(browser: 'chrome' | 'firefox', platform?: 'windows' | 'macos' | 'linux'): ImpitBrowserConfig;
|
|
29
73
|
//# sourceMappingURL=browsers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browsers.d.ts","sourceRoot":"","sources":["../../src/config/browsers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2BAA2B,EAAE,MAAM,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CA2KnD,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAI3D;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzF"}
|
|
1
|
+
{"version":3,"file":"browsers.d.ts","sourceRoot":"","sources":["../../src/config/browsers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2BAA2B,EAAE,MAAM,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gB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Property(exports, "__esModule", { value: true });
|
|
7
|
-
exports.BROWSERS = void 0;
|
|
7
|
+
exports.ALL_IMPIT_CONFIGS = exports.IMPIT_FIREFOX_CONFIGS = exports.IMPIT_CHROME_CONFIGS = exports.BROWSERS = void 0;
|
|
8
8
|
exports.getRandomBrowser = getRandomBrowser;
|
|
9
9
|
exports.getBrowserHeadersAsRecord = getBrowserHeadersAsRecord;
|
|
10
|
+
exports.getRandomImpitBrowserConfig = getRandomImpitBrowserConfig;
|
|
11
|
+
exports.getImpitBrowserConfig = getImpitBrowserConfig;
|
|
10
12
|
exports.BROWSERS = {
|
|
11
13
|
chrome99: {
|
|
12
14
|
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"',
|
|
@@ -193,4 +195,164 @@ function getRandomBrowser() {
|
|
|
193
195
|
function getBrowserHeadersAsRecord(browser) {
|
|
194
196
|
return { ...browser };
|
|
195
197
|
}
|
|
198
|
+
// ============================================================================
|
|
199
|
+
// Impit-specific Browser Configurations
|
|
200
|
+
// ============================================================================
|
|
201
|
+
/**
|
|
202
|
+
* Chrome browser configurations for impit.
|
|
203
|
+
* impit uses Chrome 125 TLS fingerprinting internally.
|
|
204
|
+
* These headers supplement the TLS-level impersonation.
|
|
205
|
+
*/
|
|
206
|
+
exports.IMPIT_CHROME_CONFIGS = [
|
|
207
|
+
// Chrome on macOS
|
|
208
|
+
{
|
|
209
|
+
browser: 'chrome',
|
|
210
|
+
platform: 'macos',
|
|
211
|
+
headers: {
|
|
212
|
+
'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
|
213
|
+
'sec-ch-ua-mobile': '?0',
|
|
214
|
+
'sec-ch-ua-platform': '"macOS"',
|
|
215
|
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
216
|
+
'sec-fetch-site': 'none',
|
|
217
|
+
'sec-fetch-mode': 'navigate',
|
|
218
|
+
'sec-fetch-user': '?1',
|
|
219
|
+
'sec-fetch-dest': 'document',
|
|
220
|
+
'accept-encoding': 'gzip, deflate, br, zstd',
|
|
221
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
222
|
+
'upgrade-insecure-requests': '1',
|
|
223
|
+
'priority': 'u=0, i',
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
// Chrome on Windows
|
|
227
|
+
{
|
|
228
|
+
browser: 'chrome',
|
|
229
|
+
platform: 'windows',
|
|
230
|
+
headers: {
|
|
231
|
+
'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
|
232
|
+
'sec-ch-ua-mobile': '?0',
|
|
233
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
234
|
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
235
|
+
'sec-fetch-site': 'none',
|
|
236
|
+
'sec-fetch-mode': 'navigate',
|
|
237
|
+
'sec-fetch-user': '?1',
|
|
238
|
+
'sec-fetch-dest': 'document',
|
|
239
|
+
'accept-encoding': 'gzip, deflate, br, zstd',
|
|
240
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
241
|
+
'upgrade-insecure-requests': '1',
|
|
242
|
+
'priority': 'u=0, i',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
// Chrome on Linux
|
|
246
|
+
{
|
|
247
|
+
browser: 'chrome',
|
|
248
|
+
platform: 'linux',
|
|
249
|
+
headers: {
|
|
250
|
+
'sec-ch-ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
|
251
|
+
'sec-ch-ua-mobile': '?0',
|
|
252
|
+
'sec-ch-ua-platform': '"Linux"',
|
|
253
|
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
254
|
+
'sec-fetch-site': 'none',
|
|
255
|
+
'sec-fetch-mode': 'navigate',
|
|
256
|
+
'sec-fetch-user': '?1',
|
|
257
|
+
'sec-fetch-dest': 'document',
|
|
258
|
+
'accept-encoding': 'gzip, deflate, br, zstd',
|
|
259
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
260
|
+
'upgrade-insecure-requests': '1',
|
|
261
|
+
'priority': 'u=0, i',
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
/**
|
|
266
|
+
* Firefox browser configurations for impit.
|
|
267
|
+
* impit uses Firefox 128 TLS fingerprinting internally.
|
|
268
|
+
*/
|
|
269
|
+
exports.IMPIT_FIREFOX_CONFIGS = [
|
|
270
|
+
// Firefox on Linux (default impit Firefox config)
|
|
271
|
+
{
|
|
272
|
+
browser: 'firefox',
|
|
273
|
+
platform: 'linux',
|
|
274
|
+
headers: {
|
|
275
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0',
|
|
276
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
|
277
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
278
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
279
|
+
'sec-fetch-dest': 'document',
|
|
280
|
+
'sec-fetch-mode': 'navigate',
|
|
281
|
+
'sec-fetch-site': 'none',
|
|
282
|
+
'sec-fetch-user': '?1',
|
|
283
|
+
'Upgrade-Insecure-Requests': '1',
|
|
284
|
+
'Priority': 'u=0, i',
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
// Firefox on macOS
|
|
288
|
+
{
|
|
289
|
+
browser: 'firefox',
|
|
290
|
+
platform: 'macos',
|
|
291
|
+
headers: {
|
|
292
|
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0',
|
|
293
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
|
294
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
295
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
296
|
+
'sec-fetch-dest': 'document',
|
|
297
|
+
'sec-fetch-mode': 'navigate',
|
|
298
|
+
'sec-fetch-site': 'none',
|
|
299
|
+
'sec-fetch-user': '?1',
|
|
300
|
+
'Upgrade-Insecure-Requests': '1',
|
|
301
|
+
'Priority': 'u=0, i',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
// Firefox on Windows
|
|
305
|
+
{
|
|
306
|
+
browser: 'firefox',
|
|
307
|
+
platform: 'windows',
|
|
308
|
+
headers: {
|
|
309
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0',
|
|
310
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
|
311
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
312
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
313
|
+
'sec-fetch-dest': 'document',
|
|
314
|
+
'sec-fetch-mode': 'navigate',
|
|
315
|
+
'sec-fetch-site': 'none',
|
|
316
|
+
'sec-fetch-user': '?1',
|
|
317
|
+
'Upgrade-Insecure-Requests': '1',
|
|
318
|
+
'Priority': 'u=0, i',
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
];
|
|
322
|
+
/**
|
|
323
|
+
* All impit browser configurations combined.
|
|
324
|
+
* Chrome configs are weighted more heavily (3:1 ratio) as they're more common.
|
|
325
|
+
*/
|
|
326
|
+
exports.ALL_IMPIT_CONFIGS = [
|
|
327
|
+
...exports.IMPIT_CHROME_CONFIGS,
|
|
328
|
+
...exports.IMPIT_CHROME_CONFIGS, // Double Chrome weight
|
|
329
|
+
...exports.IMPIT_FIREFOX_CONFIGS,
|
|
330
|
+
];
|
|
331
|
+
/**
|
|
332
|
+
* Get a random impit browser configuration.
|
|
333
|
+
* Chrome is weighted 2:1 over Firefox to reflect real-world usage.
|
|
334
|
+
*
|
|
335
|
+
* @returns A random impit browser configuration
|
|
336
|
+
*/
|
|
337
|
+
function getRandomImpitBrowserConfig() {
|
|
338
|
+
const index = Math.floor(Math.random() * exports.ALL_IMPIT_CONFIGS.length);
|
|
339
|
+
return exports.ALL_IMPIT_CONFIGS[index];
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get a specific impit browser configuration.
|
|
343
|
+
*
|
|
344
|
+
* @param browser - The browser type ('chrome' or 'firefox')
|
|
345
|
+
* @param platform - Optional platform preference ('windows', 'macos', 'linux')
|
|
346
|
+
* @returns The matching browser configuration, or a random one if not found
|
|
347
|
+
*/
|
|
348
|
+
function getImpitBrowserConfig(browser, platform) {
|
|
349
|
+
const configs = browser === 'chrome' ? exports.IMPIT_CHROME_CONFIGS : exports.IMPIT_FIREFOX_CONFIGS;
|
|
350
|
+
if (platform) {
|
|
351
|
+
const match = configs.find((c) => c.platform === platform);
|
|
352
|
+
if (match)
|
|
353
|
+
return match;
|
|
354
|
+
}
|
|
355
|
+
// Return random from matching browser type
|
|
356
|
+
return configs[Math.floor(Math.random() * configs.length)];
|
|
357
|
+
}
|
|
196
358
|
//# sourceMappingURL=browsers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browsers.js","sourceRoot":"","sources":["../../src/config/browsers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"browsers.js","sourceRoot":"","sources":["../../src/config/browsers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmNH,4CAIC;AAKD,8DAEC;AAiJD,kEAGC;AASD,sDAaC;AArWY,QAAA,QAAQ,GAAmC;IACtD,QAAQ,EAAE;QACR,WAAW,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AAC,IAAI,CAAC,MAAM,EAAE,GAAG,yBAAiB,CAAC,MAAM,CAAC,CAAC;IACnE,OAAO,yBAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,OAA6B,EAC7B,QAAwC;IAExC,MAAM,OAAO,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAAoB,CAAC,CAAC,CAAC,6BAAqB,CAAC;IAEpF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;QAC3D,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IAED,2CAA2C;IAC3C,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImpitClient - Impit-based HTTP client wrapper for yfinance-mcp-ts.
|
|
3
|
+
*
|
|
4
|
+
* Provides an axios-compatible interface using the impit library for
|
|
5
|
+
* sophisticated browser impersonation with TLS fingerprinting bypass.
|
|
6
|
+
*/
|
|
7
|
+
import { Impit, ImpitResponse } from 'impit';
|
|
8
|
+
import { CookieJar } from 'tough-cookie';
|
|
9
|
+
import { YFinanceImpitOptions, ImpitRequestConfig, ImpitPostConfig, ImpitAxiosLikeResponse } from '../types/impit';
|
|
10
|
+
import { ImpitBrowserConfig } from '../config/browsers';
|
|
11
|
+
/**
|
|
12
|
+
* ImpitClient - HTTP client using impit for browser impersonation.
|
|
13
|
+
*
|
|
14
|
+
* This class wraps the impit library to provide an interface compatible
|
|
15
|
+
* with the existing axios-based SessionManager, enabling seamless switching
|
|
16
|
+
* between HTTP clients.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - TLS fingerprinting bypass (Chrome/Firefox impersonation)
|
|
20
|
+
* - Cookie jar persistence (tough-cookie compatible)
|
|
21
|
+
* - Proxy support (HTTP, HTTPS, SOCKS4, SOCKS5)
|
|
22
|
+
* - Automatic header management
|
|
23
|
+
* - Response parsing (JSON, text)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const client = new ImpitClient({ browser: 'chrome', timeout: 30000 });
|
|
28
|
+
* const response = await client.get('https://finance.yahoo.com/quote/AAPL');
|
|
29
|
+
* console.log(response.data);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class ImpitClient {
|
|
33
|
+
private client;
|
|
34
|
+
private cookieJar;
|
|
35
|
+
private browserConfig;
|
|
36
|
+
private defaultTimeout;
|
|
37
|
+
private proxyUrl?;
|
|
38
|
+
private options;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new ImpitClient instance.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Configuration options for the client
|
|
43
|
+
*/
|
|
44
|
+
constructor(options?: YFinanceImpitOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Create a new impit instance with current configuration.
|
|
47
|
+
*/
|
|
48
|
+
private createImpitInstance;
|
|
49
|
+
/**
|
|
50
|
+
* Build URL with query parameters.
|
|
51
|
+
*
|
|
52
|
+
* @param baseUrl - The base URL
|
|
53
|
+
* @param params - Query parameters to append
|
|
54
|
+
* @returns The full URL with query parameters
|
|
55
|
+
*/
|
|
56
|
+
private buildUrl;
|
|
57
|
+
/**
|
|
58
|
+
* Convert Headers object to plain record.
|
|
59
|
+
*/
|
|
60
|
+
private headersToRecord;
|
|
61
|
+
/**
|
|
62
|
+
* Convert impit response to axios-like response format.
|
|
63
|
+
*
|
|
64
|
+
* @param response - The impit response object
|
|
65
|
+
* @returns An axios-compatible response object
|
|
66
|
+
*/
|
|
67
|
+
private toAxiosLikeResponse;
|
|
68
|
+
/**
|
|
69
|
+
* Merge custom headers with browser defaults.
|
|
70
|
+
*
|
|
71
|
+
* @param customHeaders - Custom headers to merge
|
|
72
|
+
* @returns Merged headers object
|
|
73
|
+
*/
|
|
74
|
+
private mergeHeaders;
|
|
75
|
+
/**
|
|
76
|
+
* Make a GET request.
|
|
77
|
+
*
|
|
78
|
+
* @param url - The URL to request
|
|
79
|
+
* @param config - Optional request configuration
|
|
80
|
+
* @returns Promise resolving to the response data
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const response = await client.get('https://api.example.com/data', {
|
|
85
|
+
* params: { symbol: 'AAPL' },
|
|
86
|
+
* timeout: 5000,
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
get<T = unknown>(url: string, config?: ImpitRequestConfig): Promise<ImpitAxiosLikeResponse<T>>;
|
|
91
|
+
/**
|
|
92
|
+
* Make a POST request.
|
|
93
|
+
*
|
|
94
|
+
* @param url - The URL to request
|
|
95
|
+
* @param data - Request body data
|
|
96
|
+
* @param config - Optional request configuration
|
|
97
|
+
* @returns Promise resolving to the response data
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const response = await client.post('https://api.example.com/data', {
|
|
102
|
+
* symbol: 'AAPL',
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
post<T = unknown>(url: string, data?: unknown, config?: ImpitPostConfig): Promise<ImpitAxiosLikeResponse<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* Make a raw fetch request (for advanced use cases).
|
|
109
|
+
*
|
|
110
|
+
* @param url - The URL to request
|
|
111
|
+
* @param init - Fetch-compatible request init
|
|
112
|
+
* @returns The raw impit response
|
|
113
|
+
*/
|
|
114
|
+
fetch(url: string, init?: Parameters<Impit['fetch']>[1]): Promise<ImpitResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the cookie jar for external access.
|
|
117
|
+
*
|
|
118
|
+
* @returns The tough-cookie CookieJar instance
|
|
119
|
+
*/
|
|
120
|
+
getCookieJar(): CookieJar;
|
|
121
|
+
/**
|
|
122
|
+
* Get the current browser configuration.
|
|
123
|
+
*
|
|
124
|
+
* @returns The current ImpitBrowserConfig
|
|
125
|
+
*/
|
|
126
|
+
getBrowserConfig(): ImpitBrowserConfig;
|
|
127
|
+
/**
|
|
128
|
+
* Rotate to a new random browser configuration.
|
|
129
|
+
*
|
|
130
|
+
* This recreates the impit instance with a new browser fingerprint,
|
|
131
|
+
* while preserving the cookie jar and other settings.
|
|
132
|
+
*/
|
|
133
|
+
rotateBrowser(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Update the proxy URL.
|
|
136
|
+
*
|
|
137
|
+
* This recreates the impit instance with the new proxy setting,
|
|
138
|
+
* while preserving the cookie jar and browser configuration.
|
|
139
|
+
*
|
|
140
|
+
* @param proxyUrl - The new proxy URL, or undefined to disable proxy
|
|
141
|
+
*/
|
|
142
|
+
setProxy(proxyUrl: string | undefined): void;
|
|
143
|
+
/**
|
|
144
|
+
* Get the current proxy URL.
|
|
145
|
+
*
|
|
146
|
+
* @returns The current proxy URL, or undefined if not set
|
|
147
|
+
*/
|
|
148
|
+
getProxy(): string | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Get the default timeout value.
|
|
151
|
+
*
|
|
152
|
+
* @returns The default timeout in milliseconds
|
|
153
|
+
*/
|
|
154
|
+
getTimeout(): number;
|
|
155
|
+
/**
|
|
156
|
+
* Update the default timeout.
|
|
157
|
+
*
|
|
158
|
+
* @param timeout - The new timeout in milliseconds
|
|
159
|
+
*/
|
|
160
|
+
setTimeout(timeout: number): void;
|
|
161
|
+
/**
|
|
162
|
+
* Check if HTTP/3 is enabled.
|
|
163
|
+
*
|
|
164
|
+
* @returns True if HTTP/3 is enabled
|
|
165
|
+
*/
|
|
166
|
+
isHttp3Enabled(): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Get information about the current impersonation.
|
|
169
|
+
*
|
|
170
|
+
* @returns Object containing browser and platform information
|
|
171
|
+
*/
|
|
172
|
+
getImpersonation(): {
|
|
173
|
+
browser: string;
|
|
174
|
+
platform: string;
|
|
175
|
+
headers: Record<string, string>;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create a new ImpitClient instance.
|
|
180
|
+
*
|
|
181
|
+
* Factory function for creating ImpitClient instances.
|
|
182
|
+
*
|
|
183
|
+
* @param options - Configuration options
|
|
184
|
+
* @returns A new ImpitClient instance
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const client = createImpitClient({ browser: 'chrome' });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function createImpitClient(options?: YFinanceImpitOptions): ImpitClient;
|
|
192
|
+
//# sourceMappingURL=ImpitClient.d.ts.map
|