@fin.cx/opendata 1.6.1 → 2.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.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.handelsregister.d.ts +2 -1
- package/dist_ts/classes.handelsregister.js +5 -5
- package/dist_ts/classes.jsonldata.d.ts +2 -1
- package/dist_ts/classes.jsonldata.js +5 -5
- package/dist_ts/classes.main.opendata.d.ts +7 -0
- package/dist_ts/classes.main.opendata.js +16 -5
- package/dist_ts/paths.d.ts +0 -3
- package/dist_ts/paths.js +1 -6
- package/dist_ts/stocks/index.d.ts +1 -0
- package/dist_ts/stocks/index.js +2 -1
- package/dist_ts/stocks/providers/provider.marketstack.d.ts +57 -0
- package/dist_ts/stocks/providers/provider.marketstack.js +173 -0
- package/package.json +2 -2
- package/readme.md +209 -59
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.handelsregister.ts +6 -4
- package/ts/classes.jsonldata.ts +6 -4
- package/ts/classes.main.opendata.ts +39 -13
- package/ts/paths.ts +1 -10
- package/ts/stocks/index.ts +2 -1
- package/ts/stocks/providers/provider.marketstack.ts +200 -0
package/readme.md
CHANGED
|
@@ -1,41 +1,64 @@
|
|
|
1
1
|
# @fin.cx/opendata
|
|
2
|
+
|
|
2
3
|
🚀 **Real-time financial data and German business intelligence in one powerful TypeScript library**
|
|
3
4
|
|
|
4
5
|
Access live stock prices, cryptocurrencies, forex, commodities AND comprehensive German company data - all through a single, unified API.
|
|
5
6
|
|
|
7
|
+
## ⚠️ Breaking Change in v2.0
|
|
8
|
+
|
|
9
|
+
**Directory paths are now MANDATORY when using German business data features.** The package no longer creates `.nogit/` directories automatically. You must explicitly configure all directory paths when instantiating `OpenData`:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const openData = new OpenData({
|
|
13
|
+
nogitDir: '/path/to/your/data',
|
|
14
|
+
downloadDir: '/path/to/your/data/downloads',
|
|
15
|
+
germanBusinessDataDir: '/path/to/your/data/germanbusinessdata'
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This change enables the package to work in read-only filesystems (like Deno compiled binaries) and gives you full control over where data is stored.
|
|
20
|
+
|
|
6
21
|
## Installation
|
|
7
22
|
|
|
8
23
|
```bash
|
|
9
24
|
npm install @fin.cx/opendata
|
|
10
25
|
# or
|
|
11
|
-
|
|
26
|
+
pnpm add @fin.cx/opendata
|
|
12
27
|
```
|
|
13
28
|
|
|
14
29
|
## Quick Start
|
|
15
30
|
|
|
16
|
-
### 📈
|
|
31
|
+
### 📈 Stock Market Data
|
|
17
32
|
|
|
18
|
-
Get
|
|
33
|
+
Get market data with EOD (End-of-Day) pricing:
|
|
19
34
|
|
|
20
35
|
```typescript
|
|
21
|
-
import { StockPriceService,
|
|
36
|
+
import { StockPriceService, MarketstackProvider } from '@fin.cx/opendata';
|
|
37
|
+
|
|
38
|
+
// Initialize the service with caching
|
|
39
|
+
const stockService = new StockPriceService({
|
|
40
|
+
ttl: 60000, // Cache for 1 minute
|
|
41
|
+
maxEntries: 1000 // Max cached symbols
|
|
42
|
+
});
|
|
22
43
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
// Register Marketstack provider with API key
|
|
45
|
+
stockService.register(new MarketstackProvider('YOUR_API_KEY'), {
|
|
46
|
+
priority: 100,
|
|
47
|
+
retryAttempts: 3
|
|
48
|
+
});
|
|
26
49
|
|
|
27
50
|
// Get single stock price
|
|
28
51
|
const apple = await stockService.getPrice({ ticker: 'AAPL' });
|
|
29
52
|
console.log(`Apple: $${apple.price} (${apple.changePercent.toFixed(2)}%)`);
|
|
30
53
|
|
|
31
|
-
// Get multiple prices at once
|
|
32
|
-
const prices = await stockService.getPrices({
|
|
33
|
-
tickers: ['AAPL', 'MSFT', 'GOOGL', '
|
|
54
|
+
// Get multiple prices at once (batch fetching)
|
|
55
|
+
const prices = await stockService.getPrices({
|
|
56
|
+
tickers: ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA']
|
|
34
57
|
});
|
|
35
58
|
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
tickers: ['
|
|
59
|
+
// 125,000+ tickers across 72+ exchanges worldwide
|
|
60
|
+
const internationalStocks = await stockService.getPrices({
|
|
61
|
+
tickers: ['AAPL', 'VOD.LON', 'SAP.DEX', 'TM', 'BABA']
|
|
39
62
|
});
|
|
40
63
|
```
|
|
41
64
|
|
|
@@ -45,8 +68,14 @@ Access comprehensive data on German companies:
|
|
|
45
68
|
|
|
46
69
|
```typescript
|
|
47
70
|
import { OpenData } from '@fin.cx/opendata';
|
|
71
|
+
import * as path from 'path';
|
|
48
72
|
|
|
49
|
-
|
|
73
|
+
// REQUIRED: Configure directory paths
|
|
74
|
+
const openData = new OpenData({
|
|
75
|
+
nogitDir: path.join(process.cwd(), '.nogit'),
|
|
76
|
+
downloadDir: path.join(process.cwd(), '.nogit', 'downloads'),
|
|
77
|
+
germanBusinessDataDir: path.join(process.cwd(), '.nogit', 'germanbusinessdata')
|
|
78
|
+
});
|
|
50
79
|
await openData.start();
|
|
51
80
|
|
|
52
81
|
// Create a business record
|
|
@@ -73,11 +102,12 @@ await openData.buildInitialDb();
|
|
|
73
102
|
|
|
74
103
|
### 🎯 Stock Market Module
|
|
75
104
|
|
|
76
|
-
- **
|
|
105
|
+
- **Marketstack API** - End-of-Day (EOD) data for 125,000+ tickers across 72+ exchanges
|
|
106
|
+
- **Stock prices** for stocks, ETFs, indices, and more
|
|
77
107
|
- **Batch operations** - fetch 100+ symbols in one request
|
|
78
108
|
- **Smart caching** - configurable TTL, automatic invalidation
|
|
79
|
-
- **
|
|
80
|
-
- **
|
|
109
|
+
- **Extensible provider system** - easily add new data sources
|
|
110
|
+
- **Retry logic** - configurable retry attempts and delays
|
|
81
111
|
- **Type-safe** - full TypeScript support with detailed interfaces
|
|
82
112
|
|
|
83
113
|
### 🇩🇪 German Business Intelligence
|
|
@@ -92,29 +122,24 @@ await openData.buildInitialDb();
|
|
|
92
122
|
|
|
93
123
|
### Market Dashboard
|
|
94
124
|
|
|
95
|
-
Create
|
|
125
|
+
Create an EOD market overview:
|
|
96
126
|
|
|
97
127
|
```typescript
|
|
98
128
|
const indicators = [
|
|
99
129
|
// Indices
|
|
100
130
|
{ ticker: '^GSPC', name: 'S&P 500' },
|
|
101
|
-
{ ticker: '^
|
|
102
|
-
|
|
131
|
+
{ ticker: '^DJI', name: 'DOW Jones' },
|
|
132
|
+
|
|
103
133
|
// Tech Giants
|
|
104
134
|
{ ticker: 'AAPL', name: 'Apple' },
|
|
105
135
|
{ ticker: 'MSFT', name: 'Microsoft' },
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{ ticker: '
|
|
109
|
-
{ ticker: 'ETH-USD', name: 'Ethereum' },
|
|
110
|
-
|
|
111
|
-
// Commodities
|
|
112
|
-
{ ticker: 'GC=F', name: 'Gold' },
|
|
113
|
-
{ ticker: 'CL=F', name: 'Oil' }
|
|
136
|
+
{ ticker: 'GOOGL', name: 'Alphabet' },
|
|
137
|
+
{ ticker: 'AMZN', name: 'Amazon' },
|
|
138
|
+
{ ticker: 'TSLA', name: 'Tesla' }
|
|
114
139
|
];
|
|
115
140
|
|
|
116
|
-
const prices = await stockService.getPrices({
|
|
117
|
-
tickers: indicators.map(i => i.ticker)
|
|
141
|
+
const prices = await stockService.getPrices({
|
|
142
|
+
tickers: indicators.map(i => i.ticker)
|
|
118
143
|
});
|
|
119
144
|
|
|
120
145
|
// Display with color-coded changes
|
|
@@ -122,7 +147,7 @@ prices.forEach(price => {
|
|
|
122
147
|
const indicator = indicators.find(i => i.ticker === price.ticker);
|
|
123
148
|
const arrow = price.change >= 0 ? '↑' : '↓';
|
|
124
149
|
const color = price.change >= 0 ? '\x1b[32m' : '\x1b[31m';
|
|
125
|
-
|
|
150
|
+
|
|
126
151
|
console.log(
|
|
127
152
|
`${indicator.name.padEnd(15)} ${price.price.toFixed(2).padStart(10)} ` +
|
|
128
153
|
`${color}${arrow} ${price.changePercent.toFixed(2)}%\x1b[0m`
|
|
@@ -130,11 +155,41 @@ prices.forEach(price => {
|
|
|
130
155
|
});
|
|
131
156
|
```
|
|
132
157
|
|
|
158
|
+
### Provider Health and Statistics
|
|
159
|
+
|
|
160
|
+
Monitor your provider health and track usage:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Check provider health
|
|
164
|
+
const health = await stockService.checkProvidersHealth();
|
|
165
|
+
console.log(`Marketstack: ${health.get('Marketstack') ? '✅' : '❌'}`);
|
|
166
|
+
|
|
167
|
+
// Get provider statistics
|
|
168
|
+
const stats = stockService.getProviderStats();
|
|
169
|
+
const marketstackStats = stats.get('Marketstack');
|
|
170
|
+
console.log('Marketstack Stats:', {
|
|
171
|
+
successCount: marketstackStats.successCount,
|
|
172
|
+
errorCount: marketstackStats.errorCount,
|
|
173
|
+
lastError: marketstackStats.lastError
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
133
177
|
### Handelsregister Integration
|
|
134
178
|
|
|
135
179
|
Automate German company data retrieval:
|
|
136
180
|
|
|
137
181
|
```typescript
|
|
182
|
+
import { OpenData } from '@fin.cx/opendata';
|
|
183
|
+
import * as path from 'path';
|
|
184
|
+
|
|
185
|
+
// Configure paths first
|
|
186
|
+
const openData = new OpenData({
|
|
187
|
+
nogitDir: path.join(process.cwd(), '.nogit'),
|
|
188
|
+
downloadDir: path.join(process.cwd(), '.nogit', 'downloads'),
|
|
189
|
+
germanBusinessDataDir: path.join(process.cwd(), '.nogit', 'germanbusinessdata')
|
|
190
|
+
});
|
|
191
|
+
await openData.start();
|
|
192
|
+
|
|
138
193
|
// Search for a company
|
|
139
194
|
const results = await openData.handelsregister.searchCompany("Siemens AG");
|
|
140
195
|
|
|
@@ -158,6 +213,21 @@ for (const file of details.files) {
|
|
|
158
213
|
Merge financial and business data:
|
|
159
214
|
|
|
160
215
|
```typescript
|
|
216
|
+
import { OpenData, StockPriceService, MarketstackProvider } from '@fin.cx/opendata';
|
|
217
|
+
import * as path from 'path';
|
|
218
|
+
|
|
219
|
+
// Configure OpenData with paths
|
|
220
|
+
const openData = new OpenData({
|
|
221
|
+
nogitDir: path.join(process.cwd(), '.nogit'),
|
|
222
|
+
downloadDir: path.join(process.cwd(), '.nogit', 'downloads'),
|
|
223
|
+
germanBusinessDataDir: path.join(process.cwd(), '.nogit', 'germanbusinessdata')
|
|
224
|
+
});
|
|
225
|
+
await openData.start();
|
|
226
|
+
|
|
227
|
+
// Setup stock service
|
|
228
|
+
const stockService = new StockPriceService({ ttl: 60000, maxEntries: 1000 });
|
|
229
|
+
stockService.register(new MarketstackProvider('YOUR_API_KEY'));
|
|
230
|
+
|
|
161
231
|
// Find all public German companies (AG)
|
|
162
232
|
const publicCompanies = await openData.db
|
|
163
233
|
.collection('businessrecords')
|
|
@@ -169,15 +239,15 @@ for (const company of publicCompanies) {
|
|
|
169
239
|
try {
|
|
170
240
|
// Map company to ticker (custom logic needed)
|
|
171
241
|
const ticker = mapCompanyToTicker(company.data.name);
|
|
172
|
-
|
|
242
|
+
|
|
173
243
|
if (ticker) {
|
|
174
244
|
const stock = await stockService.getPrice({ ticker });
|
|
175
|
-
|
|
245
|
+
|
|
176
246
|
// Add financial metrics
|
|
177
247
|
company.data.stockPrice = stock.price;
|
|
178
248
|
company.data.marketCap = stock.price * getSharesOutstanding(ticker);
|
|
179
249
|
company.data.priceChange = stock.changePercent;
|
|
180
|
-
|
|
250
|
+
|
|
181
251
|
await company.save();
|
|
182
252
|
}
|
|
183
253
|
} catch (error) {
|
|
@@ -188,6 +258,48 @@ for (const company of publicCompanies) {
|
|
|
188
258
|
|
|
189
259
|
## Configuration
|
|
190
260
|
|
|
261
|
+
### Directory Configuration (Required for German Business Data)
|
|
262
|
+
|
|
263
|
+
**All directory paths are mandatory when using `OpenData`.** Here are examples for different environments:
|
|
264
|
+
|
|
265
|
+
#### Development Environment
|
|
266
|
+
```typescript
|
|
267
|
+
import { OpenData } from '@fin.cx/opendata';
|
|
268
|
+
import * as path from 'path';
|
|
269
|
+
|
|
270
|
+
const openData = new OpenData({
|
|
271
|
+
nogitDir: path.join(process.cwd(), '.nogit'),
|
|
272
|
+
downloadDir: path.join(process.cwd(), '.nogit', 'downloads'),
|
|
273
|
+
germanBusinessDataDir: path.join(process.cwd(), '.nogit', 'germanbusinessdata')
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### Production Environment
|
|
278
|
+
```typescript
|
|
279
|
+
import { OpenData } from '@fin.cx/opendata';
|
|
280
|
+
import * as path from 'path';
|
|
281
|
+
|
|
282
|
+
const openData = new OpenData({
|
|
283
|
+
nogitDir: '/var/lib/myapp/data',
|
|
284
|
+
downloadDir: '/var/lib/myapp/data/downloads',
|
|
285
|
+
germanBusinessDataDir: '/var/lib/myapp/data/germanbusinessdata'
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### Deno Compiled Binaries (or other read-only filesystems)
|
|
290
|
+
```typescript
|
|
291
|
+
import { OpenData } from '@fin.cx/opendata';
|
|
292
|
+
|
|
293
|
+
// Use OS temp directory or user data directory
|
|
294
|
+
const dataDir = Deno.env.get('HOME') + '/.myapp/data';
|
|
295
|
+
|
|
296
|
+
const openData = new OpenData({
|
|
297
|
+
nogitDir: dataDir,
|
|
298
|
+
downloadDir: dataDir + '/downloads',
|
|
299
|
+
germanBusinessDataDir: dataDir + '/germanbusinessdata'
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
191
303
|
### Stock Service Options
|
|
192
304
|
|
|
193
305
|
```typescript
|
|
@@ -196,8 +308,8 @@ const stockService = new StockPriceService({
|
|
|
196
308
|
maxEntries: 1000 // Max cached symbols
|
|
197
309
|
});
|
|
198
310
|
|
|
199
|
-
//
|
|
200
|
-
stockService.register(new
|
|
311
|
+
// Marketstack - EOD data, requires API key
|
|
312
|
+
stockService.register(new MarketstackProvider('YOUR_API_KEY'), {
|
|
201
313
|
enabled: true,
|
|
202
314
|
priority: 100,
|
|
203
315
|
timeout: 10000,
|
|
@@ -208,7 +320,7 @@ stockService.register(new YahooFinanceProvider(), {
|
|
|
208
320
|
|
|
209
321
|
### MongoDB Setup
|
|
210
322
|
|
|
211
|
-
Set environment variables:
|
|
323
|
+
Set environment variables for German business data:
|
|
212
324
|
|
|
213
325
|
```env
|
|
214
326
|
MONGODB_URL=mongodb://localhost:27017
|
|
@@ -217,6 +329,14 @@ MONGODB_USER=myuser
|
|
|
217
329
|
MONGODB_PASS=mypass
|
|
218
330
|
```
|
|
219
331
|
|
|
332
|
+
### Marketstack API Key
|
|
333
|
+
|
|
334
|
+
Get your free API key at [marketstack.com](https://marketstack.com) and set it in your environment:
|
|
335
|
+
|
|
336
|
+
```env
|
|
337
|
+
MARKETSTACK_COM_TOKEN=your_api_key_here
|
|
338
|
+
```
|
|
339
|
+
|
|
220
340
|
## API Reference
|
|
221
341
|
|
|
222
342
|
### Stock Types
|
|
@@ -240,10 +360,21 @@ interface IStockPrice {
|
|
|
240
360
|
### Key Methods
|
|
241
361
|
|
|
242
362
|
**StockPriceService**
|
|
243
|
-
- `getPrice(request)` - Single stock price
|
|
244
|
-
- `getPrices(request)` - Batch prices
|
|
245
|
-
- `register(provider)` - Add data provider
|
|
363
|
+
- `getPrice(request)` - Single stock price with automatic provider selection
|
|
364
|
+
- `getPrices(request)` - Batch prices (100+ symbols in one request)
|
|
365
|
+
- `register(provider, config)` - Add data provider with priority and retry config
|
|
366
|
+
- `checkProvidersHealth()` - Test all providers and return health status
|
|
367
|
+
- `getProviderStats()` - Get success/error statistics for each provider
|
|
246
368
|
- `clearCache()` - Clear price cache
|
|
369
|
+
- `setCacheTTL(ttl)` - Update cache TTL dynamically
|
|
370
|
+
|
|
371
|
+
**MarketstackProvider**
|
|
372
|
+
- ✅ End-of-Day (EOD) data
|
|
373
|
+
- ✅ 125,000+ tickers across 72+ exchanges worldwide
|
|
374
|
+
- ✅ Batch fetching support (multiple symbols in one request)
|
|
375
|
+
- ✅ Comprehensive data: open, high, low, close, volume, splits, dividends
|
|
376
|
+
- ⚠️ Requires API key (free tier: 100 requests/month)
|
|
377
|
+
- ⚠️ EOD data only (not real-time)
|
|
247
378
|
|
|
248
379
|
**OpenData**
|
|
249
380
|
- `start()` - Initialize MongoDB connection
|
|
@@ -251,31 +382,48 @@ interface IStockPrice {
|
|
|
251
382
|
- `CBusinessRecord` - Business record class
|
|
252
383
|
- `handelsregister` - Registry automation
|
|
253
384
|
|
|
254
|
-
##
|
|
255
|
-
|
|
256
|
-
- **Batch fetching**: Get 100+ prices in <500ms
|
|
257
|
-
- **Caching**: Instant repeated queries
|
|
258
|
-
- **Concurrent processing**: Handle 1000+ records/second
|
|
259
|
-
- **Streaming**: Process GB-sized datasets without memory issues
|
|
260
|
-
|
|
261
|
-
## Extensibility
|
|
385
|
+
## Provider Architecture
|
|
262
386
|
|
|
263
|
-
The provider
|
|
387
|
+
The library uses a flexible provider system that makes it easy to add new data sources:
|
|
264
388
|
|
|
265
389
|
```typescript
|
|
266
390
|
class MyCustomProvider implements IStockProvider {
|
|
267
391
|
name = 'My Provider';
|
|
268
|
-
|
|
392
|
+
priority = 50;
|
|
393
|
+
requiresAuth = true;
|
|
394
|
+
|
|
269
395
|
async fetchPrice(request: IStockQuoteRequest): Promise<IStockPrice> {
|
|
270
396
|
// Your implementation
|
|
271
397
|
}
|
|
272
|
-
|
|
273
|
-
|
|
398
|
+
|
|
399
|
+
async fetchPrices(request: IStockBatchQuoteRequest): Promise<IStockPrice[]> {
|
|
400
|
+
// Batch implementation
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
async isAvailable(): Promise<boolean> {
|
|
404
|
+
// Health check
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
supportsMarket(market: string): boolean {
|
|
408
|
+
// Market validation
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
supportsTicker(ticker: string): boolean {
|
|
412
|
+
// Ticker validation
|
|
413
|
+
}
|
|
274
414
|
}
|
|
275
415
|
|
|
276
416
|
stockService.register(new MyCustomProvider());
|
|
277
417
|
```
|
|
278
418
|
|
|
419
|
+
## Performance
|
|
420
|
+
|
|
421
|
+
- **Batch fetching**: Get 100+ EOD prices in one API request
|
|
422
|
+
- **Smart caching**: Instant repeated queries with configurable TTL
|
|
423
|
+
- **Rate limit aware**: Automatic retry logic for API limits
|
|
424
|
+
- **Concurrent processing**: Handle 1000+ business records/second
|
|
425
|
+
- **Streaming**: Process GB-sized datasets without memory issues
|
|
426
|
+
|
|
279
427
|
## Testing
|
|
280
428
|
|
|
281
429
|
Run the comprehensive test suite:
|
|
@@ -284,19 +432,21 @@ Run the comprehensive test suite:
|
|
|
284
432
|
npm test
|
|
285
433
|
```
|
|
286
434
|
|
|
287
|
-
|
|
435
|
+
Test stock provider:
|
|
288
436
|
|
|
289
437
|
```bash
|
|
290
|
-
|
|
438
|
+
npx tstest test/test.marketstack.node.ts --verbose
|
|
291
439
|
```
|
|
292
440
|
|
|
293
|
-
|
|
441
|
+
Test German business data:
|
|
294
442
|
|
|
295
|
-
|
|
443
|
+
```bash
|
|
444
|
+
npx tstest test/test.handelsregister.ts --verbose
|
|
445
|
+
```
|
|
296
446
|
|
|
297
447
|
## License and Legal Information
|
|
298
448
|
|
|
299
|
-
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
449
|
+
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
300
450
|
|
|
301
451
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
302
452
|
|
|
@@ -306,9 +456,9 @@ This project is owned and maintained by Task Venture Capital GmbH. The names and
|
|
|
306
456
|
|
|
307
457
|
### Company Information
|
|
308
458
|
|
|
309
|
-
Task Venture Capital GmbH
|
|
459
|
+
Task Venture Capital GmbH
|
|
310
460
|
Registered at District court Bremen HRB 35230 HB, Germany
|
|
311
461
|
|
|
312
462
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
|
313
463
|
|
|
314
|
-
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
|
464
|
+
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@fin.cx/opendata',
|
|
6
|
-
version: '
|
|
6
|
+
version: '2.0.0',
|
|
7
7
|
description: 'A comprehensive TypeScript library for accessing business data and real-time financial information. Features include German company data management with MongoDB integration, JSONL bulk processing, automated Handelsregister interactions, and real-time stock market data from multiple providers.'
|
|
8
8
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { BusinessRecord } from './classes.businessrecord.js';
|
|
2
2
|
import type { OpenData } from './classes.main.opendata.js';
|
|
3
3
|
import * as plugins from './plugins.js';
|
|
4
|
-
import * as paths from './paths.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* the HandlesRegister exposed as a class
|
|
@@ -9,13 +8,16 @@ import * as paths from './paths.js';
|
|
|
9
8
|
export class HandelsRegister {
|
|
10
9
|
private openDataRef: OpenData;
|
|
11
10
|
private asyncExecutionStack = new plugins.lik.AsyncExecutionStack();
|
|
12
|
-
private
|
|
11
|
+
private downloadDir: string;
|
|
12
|
+
private uniqueDowloadFolder: string;
|
|
13
13
|
|
|
14
14
|
// Puppeteer wrapper instance
|
|
15
15
|
public smartbrowserInstance = new plugins.smartbrowser.SmartBrowser();
|
|
16
16
|
|
|
17
|
-
constructor(openDataRef: OpenData) {
|
|
17
|
+
constructor(openDataRef: OpenData, downloadDirArg: string) {
|
|
18
18
|
this.openDataRef = openDataRef;
|
|
19
|
+
this.downloadDir = downloadDirArg;
|
|
20
|
+
this.uniqueDowloadFolder = plugins.path.join(this.downloadDir, plugins.smartunique.uniSimple());
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
public async start() {
|
|
@@ -76,7 +78,7 @@ export class HandelsRegister {
|
|
|
76
78
|
timeout: 30000,
|
|
77
79
|
})
|
|
78
80
|
.catch(async (err) => {
|
|
79
|
-
await pageArg.screenshot({ path:
|
|
81
|
+
await pageArg.screenshot({ path: this.downloadDir + '/error.png' });
|
|
80
82
|
throw err;
|
|
81
83
|
});
|
|
82
84
|
|
package/ts/classes.jsonldata.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
-
import * as paths from './paths.js';
|
|
3
2
|
import type { OpenData } from './classes.main.opendata.js';
|
|
4
3
|
|
|
5
4
|
export type SeedEntryType = {
|
|
@@ -41,8 +40,11 @@ export type SeedEntryType = {
|
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
export class JsonlDataProcessor<T> {
|
|
43
|
+
private germanBusinessDataDir: string;
|
|
44
44
|
public forEachFunction: (entryArg: T) => Promise<void>;
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
constructor(germanBusinessDataDirArg: string, forEachFunctionArg: typeof this.forEachFunction) {
|
|
47
|
+
this.germanBusinessDataDir = germanBusinessDataDirArg;
|
|
46
48
|
this.forEachFunction = forEachFunctionArg;
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -51,9 +53,9 @@ export class JsonlDataProcessor<T> {
|
|
|
51
53
|
dataUrlArg = 'https://daten.offeneregister.de/de_companies_ocdata.jsonl.bz2'
|
|
52
54
|
) {
|
|
53
55
|
const done = plugins.smartpromise.defer();
|
|
54
|
-
const dataExists = await plugins.smartfile.fs.isDirectory(
|
|
56
|
+
const dataExists = await plugins.smartfile.fs.isDirectory(this.germanBusinessDataDir);
|
|
55
57
|
if (!dataExists) {
|
|
56
|
-
await plugins.smartfile.fs.ensureDir(
|
|
58
|
+
await plugins.smartfile.fs.ensureDir(this.germanBusinessDataDir);
|
|
57
59
|
} else {
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -4,16 +4,39 @@ import { JsonlDataProcessor, type SeedEntryType } from './classes.jsonldata.js';
|
|
|
4
4
|
import * as paths from './paths.js';
|
|
5
5
|
import * as plugins from './plugins.js';
|
|
6
6
|
|
|
7
|
+
export interface IOpenDataConfig {
|
|
8
|
+
downloadDir: string;
|
|
9
|
+
germanBusinessDataDir: string;
|
|
10
|
+
nogitDir: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
export class OpenData {
|
|
8
14
|
public db: plugins.smartdata.SmartdataDb;
|
|
9
|
-
private serviceQenv
|
|
15
|
+
private serviceQenv: plugins.qenv.Qenv;
|
|
16
|
+
private config: IOpenDataConfig;
|
|
10
17
|
|
|
11
18
|
public jsonLDataProcessor: JsonlDataProcessor<SeedEntryType>;
|
|
12
19
|
public handelsregister: HandelsRegister;
|
|
13
20
|
|
|
14
21
|
public CBusinessRecord = plugins.smartdata.setDefaultManagerForDoc(this, BusinessRecord);
|
|
15
22
|
|
|
23
|
+
constructor(configArg: IOpenDataConfig) {
|
|
24
|
+
if (!configArg) {
|
|
25
|
+
throw new Error('@fin.cx/opendata: Configuration is required. You must provide downloadDir, germanBusinessDataDir, and nogitDir paths.');
|
|
26
|
+
}
|
|
27
|
+
if (!configArg.downloadDir || !configArg.germanBusinessDataDir || !configArg.nogitDir) {
|
|
28
|
+
throw new Error('@fin.cx/opendata: All directory paths are required (downloadDir, germanBusinessDataDir, nogitDir).');
|
|
29
|
+
}
|
|
30
|
+
this.config = configArg;
|
|
31
|
+
this.serviceQenv = new plugins.qenv.Qenv(paths.packageDir, this.config.nogitDir);
|
|
32
|
+
}
|
|
33
|
+
|
|
16
34
|
public async start() {
|
|
35
|
+
// Ensure configured directories exist
|
|
36
|
+
await plugins.smartfile.fs.ensureDir(this.config.nogitDir);
|
|
37
|
+
await plugins.smartfile.fs.ensureDir(this.config.downloadDir);
|
|
38
|
+
await plugins.smartfile.fs.ensureDir(this.config.germanBusinessDataDir);
|
|
39
|
+
|
|
17
40
|
this.db = new plugins.smartdata.SmartdataDb({
|
|
18
41
|
mongoDbUrl: await this.serviceQenv.getEnvVarOnDemand('MONGODB_URL'),
|
|
19
42
|
mongoDbName: await this.serviceQenv.getEnvVarOnDemand('MONGODB_NAME'),
|
|
@@ -21,18 +44,21 @@ export class OpenData {
|
|
|
21
44
|
mongoDbPass: await this.serviceQenv.getEnvVarOnDemand('MONGODB_PASS'),
|
|
22
45
|
});
|
|
23
46
|
await this.db.init();
|
|
24
|
-
this.jsonLDataProcessor = new JsonlDataProcessor(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
this.jsonLDataProcessor = new JsonlDataProcessor(
|
|
48
|
+
this.config.germanBusinessDataDir,
|
|
49
|
+
async (entryArg) => {
|
|
50
|
+
const businessRecord = new this.CBusinessRecord();
|
|
51
|
+
businessRecord.id = await this.CBusinessRecord.getNewId();
|
|
52
|
+
businessRecord.data.name = entryArg.name;
|
|
53
|
+
businessRecord.data.germanParsedRegistration = {
|
|
54
|
+
court: entryArg.all_attributes.registered_office,
|
|
55
|
+
number: entryArg.all_attributes._registerNummer,
|
|
56
|
+
type: entryArg.all_attributes._registerArt as 'HRA' | 'HRB',
|
|
57
|
+
};
|
|
58
|
+
await businessRecord.save();
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
this.handelsregister = new HandelsRegister(this, this.config.downloadDir);
|
|
36
62
|
await this.handelsregister.start();
|
|
37
63
|
}
|
|
38
64
|
|
package/ts/paths.ts
CHANGED
|
@@ -3,13 +3,4 @@ import * as plugins from './plugins.js';
|
|
|
3
3
|
export const packageDir = plugins.path.join(
|
|
4
4
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
|
5
5
|
'../'
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
export const nogitDir = plugins.path.join(packageDir, './.nogit/');
|
|
9
|
-
plugins.smartfile.fs.ensureDirSync(nogitDir);
|
|
10
|
-
|
|
11
|
-
export const downloadDir = plugins.path.join(nogitDir, 'downloads');
|
|
12
|
-
plugins.smartfile.fs.ensureDirSync(downloadDir);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const germanBusinessDataDir = plugins.path.join(nogitDir, 'germanbusinessdata');
|
|
6
|
+
);
|
package/ts/stocks/index.ts
CHANGED