openfigi-sdk 1.2.0 → 1.3.1
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 +147 -0
- package/dist/index.cjs +29 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# openfigi-sdk
|
|
2
|
+
|
|
3
|
+
Type-safe TypeScript SDK for the [OpenFIGI API](https://www.openfigi.com/api). Map financial identifiers (ISIN, CUSIP, SEDOL, Ticker, Bloomberg ID) to FIGIs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install openfigi-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { searchByISIN, searchByTicker, createClient } from 'openfigi-sdk'
|
|
15
|
+
|
|
16
|
+
// Search by ISIN (no API key required for basic usage)
|
|
17
|
+
const result = await searchByISIN('US0378331005')
|
|
18
|
+
console.log(result.data?.[0].figi) // BBG000B9XRY4
|
|
19
|
+
|
|
20
|
+
// Search by ticker with exchange code
|
|
21
|
+
const apple = await searchByTicker('AAPL', 'US')
|
|
22
|
+
|
|
23
|
+
// With API key for higher rate limits
|
|
24
|
+
const client = createClient({ apiKey: 'your-api-key' })
|
|
25
|
+
await client.searchByISIN('US0378331005')
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **Type-safe**: Full TypeScript support with Zod schema validation
|
|
31
|
+
- **Multiple identifier types**: ISIN, CUSIP, SEDOL, Ticker, Bloomberg ID
|
|
32
|
+
- **Smart ticker search**: Auto-detects security types (Common Stock, Preference, ETF, etc.)
|
|
33
|
+
- **Batch operations**: Map up to 100 identifiers in a single request
|
|
34
|
+
- **Rate limit handling**: Built-in retry logic with exponential backoff
|
|
35
|
+
- **Validation utilities**: Validate identifiers before making API calls
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### Search Functions
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Search by ISIN
|
|
43
|
+
const result = await searchByISIN('US0378331005')
|
|
44
|
+
|
|
45
|
+
// Search by CUSIP
|
|
46
|
+
const result = await searchByCUSIP('037833100')
|
|
47
|
+
|
|
48
|
+
// Search by SEDOL
|
|
49
|
+
const result = await searchBySEDOL('2046251')
|
|
50
|
+
|
|
51
|
+
// Search by Ticker (auto-detects security type)
|
|
52
|
+
const result = await searchByTicker('AAPL', 'US')
|
|
53
|
+
const result = await searchByTicker('VOW3', 'GY') // Preference shares
|
|
54
|
+
|
|
55
|
+
// Search by Bloomberg ID
|
|
56
|
+
const result = await searchByBloombergId('BBG000B9XRY4')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Batch Mapping
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { mapping } from 'openfigi-sdk'
|
|
63
|
+
|
|
64
|
+
const results = await mapping([
|
|
65
|
+
{ idType: 'ID_ISIN', idValue: 'US0378331005' },
|
|
66
|
+
{ idType: 'ID_CUSIP', idValue: '037833100' },
|
|
67
|
+
{ idType: 'ID_EXCH_SYMBOL', idValue: 'AAPL', exchCode: 'US' },
|
|
68
|
+
])
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Client Configuration
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { createClient } from 'openfigi-sdk'
|
|
75
|
+
|
|
76
|
+
const client = createClient({
|
|
77
|
+
apiKey: 'your-api-key', // Optional, increases rate limit
|
|
78
|
+
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
79
|
+
retryLimit: 3, // Number of retries (default: 3)
|
|
80
|
+
retryDelay: 1000, // Base retry delay in ms (default: 1000)
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Validation Utilities
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { isValidISIN, isValidCUSIP, isValidSEDOL, isValidBloombergId } from 'openfigi-sdk'
|
|
88
|
+
|
|
89
|
+
isValidISIN('US0378331005') // true
|
|
90
|
+
isValidCUSIP('037833100') // true
|
|
91
|
+
isValidSEDOL('2046251') // true
|
|
92
|
+
isValidBloombergId('BBG000B9XRY4') // true
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Rate Limit Info
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { getRateLimitInfo, searchByISIN } from 'openfigi-sdk'
|
|
99
|
+
|
|
100
|
+
await searchByISIN('US0378331005')
|
|
101
|
+
const info = getRateLimitInfo()
|
|
102
|
+
console.log(`${info?.remaining}/${info?.limit} requests remaining`)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Exchange Codes
|
|
106
|
+
|
|
107
|
+
Common exchange codes for ticker searches:
|
|
108
|
+
|
|
109
|
+
| Code | Exchange |
|
|
110
|
+
|------|----------|
|
|
111
|
+
| `US` | United States |
|
|
112
|
+
| `LN` | London |
|
|
113
|
+
| `GY` | Germany (Xetra) |
|
|
114
|
+
| `SS` | Stockholm |
|
|
115
|
+
| `JP` | Japan |
|
|
116
|
+
| `HK` | Hong Kong |
|
|
117
|
+
| `FP` | France (Euronext Paris) |
|
|
118
|
+
|
|
119
|
+
## API Key
|
|
120
|
+
|
|
121
|
+
Get your free API key at [openfigi.com/api](https://www.openfigi.com/api).
|
|
122
|
+
|
|
123
|
+
| | Without API Key | With API Key |
|
|
124
|
+
|---|-----------------|--------------|
|
|
125
|
+
| Rate Limit | 25 req/min | 250 req/min |
|
|
126
|
+
|
|
127
|
+
## Error Handling
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { searchByISIN, OpenFigiError, RateLimitError, ValidationError } from 'openfigi-sdk'
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const result = await searchByISIN('US0378331005')
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof RateLimitError) {
|
|
136
|
+
console.log(`Rate limited. Retry after ${error.retryAfter} seconds`)
|
|
137
|
+
} else if (error instanceof ValidationError) {
|
|
138
|
+
console.log('Invalid input:', error.message)
|
|
139
|
+
} else if (error instanceof OpenFigiError) {
|
|
140
|
+
console.log('API error:', error.message, error.statusCode)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -3092,23 +3092,47 @@ const createClient = (config = {}) => {
|
|
|
3092
3092
|
*
|
|
3093
3093
|
* @param ticker - Ticker symbol (e.g., 'AAPL')
|
|
3094
3094
|
* @param exchCode - Optional exchange code (e.g., 'US')
|
|
3095
|
-
* @param options - Additional search options
|
|
3095
|
+
* @param options - Additional search options. If securityType2 is not specified,
|
|
3096
|
+
* the method will automatically try multiple common security types
|
|
3097
|
+
* (Common Stock, Preference, Depositary Receipt, ETP) until a match is found.
|
|
3096
3098
|
* @returns Mapping response with FIGI data
|
|
3097
3099
|
*
|
|
3098
3100
|
* @example
|
|
3099
3101
|
* ```typescript
|
|
3100
3102
|
* const result = await searchByTicker('AAPL', 'US')
|
|
3103
|
+
* // For preference shares (auto-detected):
|
|
3104
|
+
* const result2 = await searchByTicker('VOW3', 'GY')
|
|
3105
|
+
* // Or specify explicitly:
|
|
3106
|
+
* const result3 = await searchByTicker('VOW3', 'GY', { securityType2: 'Preference' })
|
|
3101
3107
|
* ```
|
|
3102
3108
|
*/
|
|
3103
3109
|
const searchByTicker$1 = async (ticker, exchCode, options) => {
|
|
3104
3110
|
if (!ticker || typeof ticker !== "string") throw new ValidationError("Ticker must be a non-empty string. Example: \"AAPL\"");
|
|
3105
|
-
|
|
3111
|
+
const normalizedTicker = ticker.trim().toUpperCase();
|
|
3112
|
+
const normalizedExchCode = exchCode?.trim();
|
|
3113
|
+
if (options?.securityType2) return mappingSingle$1({
|
|
3106
3114
|
idType: "ID_EXCH_SYMBOL",
|
|
3107
|
-
idValue:
|
|
3108
|
-
exchCode:
|
|
3109
|
-
securityType2: "Common Stock",
|
|
3115
|
+
idValue: normalizedTicker,
|
|
3116
|
+
exchCode: normalizedExchCode,
|
|
3110
3117
|
...options
|
|
3111
3118
|
});
|
|
3119
|
+
const securityTypesToTry = [
|
|
3120
|
+
"Common Stock",
|
|
3121
|
+
"Preference",
|
|
3122
|
+
"Depositary Receipt",
|
|
3123
|
+
"ETP"
|
|
3124
|
+
];
|
|
3125
|
+
for (const securityType2 of securityTypesToTry) {
|
|
3126
|
+
const response = await mappingSingle$1({
|
|
3127
|
+
idType: "ID_EXCH_SYMBOL",
|
|
3128
|
+
idValue: normalizedTicker,
|
|
3129
|
+
exchCode: normalizedExchCode,
|
|
3130
|
+
securityType2,
|
|
3131
|
+
...options
|
|
3132
|
+
});
|
|
3133
|
+
if (response.data && response.data.length > 0) return response;
|
|
3134
|
+
}
|
|
3135
|
+
return { warning: `No identifier found for ticker "${normalizedTicker}"${normalizedExchCode ? ` on exchange ${normalizedExchCode}` : ""}. Tried security types: ${securityTypesToTry.join(", ")}.` };
|
|
3112
3136
|
};
|
|
3113
3137
|
/**
|
|
3114
3138
|
* Search for FIGI by Bloomberg ID
|