@fin.cx/opendata 2.1.0 → 3.1.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 (30) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/stocks/classes.fundamentalsservice.d.ts +104 -0
  3. package/dist_ts/stocks/classes.fundamentalsservice.js +298 -0
  4. package/dist_ts/stocks/classes.stockservice.d.ts +16 -7
  5. package/dist_ts/stocks/classes.stockservice.js +17 -98
  6. package/dist_ts/stocks/index.d.ts +3 -0
  7. package/dist_ts/stocks/index.js +5 -2
  8. package/dist_ts/stocks/interfaces/fundamentals.d.ts +82 -0
  9. package/dist_ts/stocks/interfaces/fundamentals.js +6 -0
  10. package/dist_ts/stocks/interfaces/provider.d.ts +2 -3
  11. package/dist_ts/stocks/interfaces/stockprice.d.ts +2 -10
  12. package/dist_ts/stocks/interfaces/stockprice.js +2 -2
  13. package/dist_ts/stocks/providers/provider.marketstack.d.ts +6 -11
  14. package/dist_ts/stocks/providers/provider.marketstack.js +32 -24
  15. package/dist_ts/stocks/providers/provider.secedgar.d.ts +102 -0
  16. package/dist_ts/stocks/providers/provider.secedgar.js +343 -0
  17. package/dist_ts/stocks/providers/provider.yahoo.d.ts +13 -3
  18. package/dist_ts/stocks/providers/provider.yahoo.js +27 -4
  19. package/package.json +1 -1
  20. package/readme.md +383 -388
  21. package/ts/00_commitinfo_data.ts +1 -1
  22. package/ts/stocks/classes.fundamentalsservice.ts +404 -0
  23. package/ts/stocks/classes.stockservice.ts +28 -140
  24. package/ts/stocks/index.ts +5 -2
  25. package/ts/stocks/interfaces/fundamentals.ts +102 -0
  26. package/ts/stocks/interfaces/provider.ts +5 -6
  27. package/ts/stocks/interfaces/stockprice.ts +4 -19
  28. package/ts/stocks/providers/provider.marketstack.ts +39 -30
  29. package/ts/stocks/providers/provider.secedgar.ts +429 -0
  30. package/ts/stocks/providers/provider.yahoo.ts +33 -4
@@ -1,6 +1,11 @@
1
1
  import * as plugins from '../../plugins.js';
2
2
  import type { IStockProvider, IProviderConfig } from '../interfaces/provider.js';
3
- import type { IStockPrice, IStockQuoteRequest, IStockBatchQuoteRequest } from '../interfaces/stockprice.js';
3
+ import type {
4
+ IStockPrice,
5
+ IStockDataRequest,
6
+ IStockCurrentRequest,
7
+ IStockBatchCurrentRequest
8
+ } from '../interfaces/stockprice.js';
4
9
 
5
10
  export class YahooFinanceProvider implements IStockProvider {
6
11
  public name = 'Yahoo Finance';
@@ -17,7 +22,28 @@ export class YahooFinanceProvider implements IStockProvider {
17
22
 
18
23
  constructor(private config?: IProviderConfig) {}
19
24
 
20
- public async fetchPrice(request: IStockQuoteRequest): Promise<IStockPrice> {
25
+ /**
26
+ * Unified data fetching method
27
+ */
28
+ public async fetchData(request: IStockDataRequest): Promise<IStockPrice | IStockPrice[]> {
29
+ switch (request.type) {
30
+ case 'current':
31
+ return this.fetchCurrentPrice(request);
32
+ case 'batch':
33
+ return this.fetchBatchCurrentPrices(request);
34
+ case 'historical':
35
+ throw new Error('Yahoo Finance provider does not support historical data. Use Marketstack provider instead.');
36
+ case 'intraday':
37
+ throw new Error('Yahoo Finance provider does not support intraday data yet. Use Marketstack provider instead.');
38
+ default:
39
+ throw new Error(`Unsupported request type: ${(request as any).type}`);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Fetch current price for a single ticker
45
+ */
46
+ private async fetchCurrentPrice(request: IStockCurrentRequest): Promise<IStockPrice> {
21
47
  try {
22
48
  const url = `${this.baseUrl}/v8/finance/chart/${request.ticker}`;
23
49
  const response = await plugins.smartrequest.SmartRequest.create()
@@ -64,7 +90,10 @@ export class YahooFinanceProvider implements IStockProvider {
64
90
  }
65
91
  }
66
92
 
67
- public async fetchPrices(request: IStockBatchQuoteRequest): Promise<IStockPrice[]> {
93
+ /**
94
+ * Fetch batch current prices
95
+ */
96
+ private async fetchBatchCurrentPrices(request: IStockBatchCurrentRequest): Promise<IStockPrice[]> {
68
97
  try {
69
98
  const symbols = request.tickers.join(',');
70
99
  const url = `${this.baseUrl}/v8/finance/spark?symbols=${symbols}&range=1d&interval=5m`;
@@ -123,7 +152,7 @@ export class YahooFinanceProvider implements IStockProvider {
123
152
  public async isAvailable(): Promise<boolean> {
124
153
  try {
125
154
  // Test with a well-known ticker
126
- await this.fetchPrice({ ticker: 'AAPL' });
155
+ await this.fetchData({ type: 'current', ticker: 'AAPL' });
127
156
  return true;
128
157
  } catch (error) {
129
158
  console.warn('Yahoo Finance provider is not available:', error);