Skip to content

Commit e25e4ee

Browse files
authored
DS-899 Implement V11 and V12 support for TypeScript (#51)
2 parents e2097ca + 15a8fcc commit e25e4ee

File tree

14 files changed

+564
-50
lines changed

14 files changed

+564
-50
lines changed

typescript/README.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TypeScript SDK for accessing Chainlink Data Streams with real-time streaming and
2727
- **Real-time streaming** via WebSocket connections
2828
- **High Availability mode** with multiple connections and automatic failover
2929
- **Historical data access** via REST API
30-
- **Automatic report decoding** for all supported formats (V2, V3, V4, V5, V6, V7, V8, V9, V10, V13)
30+
- **Automatic report decoding** for all supported formats (V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13)
3131
- **Metrics** for monitoring and observability
3232
- **Type-safe** with full TypeScript support
3333
- **Event-driven architecture** for complete developer control
@@ -48,12 +48,14 @@ npm install @chainlink/data-streams-sdk
4848
**Set your credentials:**
4949

5050
Option 1 - Environment variables:
51+
5152
```bash
5253
export API_KEY="your_api_key_here"
5354
export USER_SECRET="your_user_secret_here"
5455
```
5556

5657
Option 2 - `.env` file:
58+
5759
```bash
5860
# Create .env file from template
5961
cp .env.example .env
@@ -64,6 +66,7 @@ USER_SECRET="your_user_secret_here"
6466
```
6567

6668
**Basic streaming:**
69+
6770
```typescript
6871
import { createClient, LogLevel } from '@chainlink/data-streams-sdk';
6972

@@ -104,17 +107,17 @@ interface Config {
104107
userSecret: string; // User secret for authentication
105108
endpoint: string; // REST API URL
106109
wsEndpoint: string; // WebSocket URL
107-
110+
108111
// Optional - Request & Retry
109112
timeout?: number; // Request timeout (default: 30000ms)
110113
retryAttempts?: number; // Retry attempts (default: 3)
111114
retryDelay?: number; // Retry delay (default: 1000ms)
112-
115+
113116
// Optional - High Availability
114117
haMode?: boolean; // Enable HA mode (default: false)
115118
haConnectionTimeout?: number; // HA connection timeout (default: 10000ms)
116119
connectionStatusCallback?: (isConnected: boolean, host: string, origin: string) => void;
117-
120+
118121
// Optional - Logging
119122
logging?: LoggingConfig; // See Logging Configuration section
120123
}
@@ -148,6 +151,7 @@ const haClient = createClient({
148151
## Examples
149152

150153
**Quick Commands:**
154+
151155
```bash
152156
# Real-time streaming
153157
npx ts-node examples/stream-reports.ts 0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782
@@ -166,7 +170,7 @@ npx ts-node examples/list-feeds.ts
166170
See [`examples/README.md`](./examples/README.md) for detailed usage instructions, setup, and all available examples including:
167171

168172
- **Streaming:** Basic streaming, HA mode, metrics monitoring
169-
- **REST API:** Latest reports, historical data, bulk operations, feed management
173+
- **REST API:** Latest reports, historical data, bulk operations, feed management
170174
- **Configuration:** Logging setup, debugging, monitoring integration
171175

172176
## API Reference
@@ -191,7 +195,6 @@ await stream.close();
191195
const metrics = stream.getMetrics();
192196
```
193197
194-
195198
### Stream Options
196199
197200
```typescript
@@ -235,23 +238,27 @@ const decoded = decodeReport(report.fullReport, report.feedID);
235238
### Schema Auto-Detection
236239
237240
The SDK automatically detects and decodes all report versions based on Feed ID patterns:
241+
238242
- **V2**: Feed IDs starting with `0x0002`
239-
- **V3**: Feed IDs starting with `0x0003` (Crypto Streams)
243+
- **V3**: Feed IDs starting with `0x0003` (Crypto Streams)
240244
- **V4**: Feed IDs starting with `0x0004` (Real-World Assets)
241245
- **V5**: Feed IDs starting with `0x0005`
242246
- **V6**: Feed IDs starting with `0x0006` (Multiple Price Values)
243247
- **V7**: Feed IDs starting with `0x0007`
244248
- **V8**: Feed IDs starting with `0x0008` (Non-OTC RWA)
245249
- **V9**: Feed IDs starting with `0x0009` (NAV Fund Data)
246250
- **V10**: Feed IDs starting with `0x000a` (Tokenized Equity)
251+
- **V11**: Feed IDs starting with `0x000b` (Deutsche Boerse)
252+
- **V12**: Feed IDs starting with `0x000c` (Nav Fund Data + Next)
247253
- **V13**: Feed IDs starting with `0x000d` (Best Bid/Ask)
248254
249255
### Common Fields
250256
251257
All reports include standard metadata:
258+
252259
```typescript
253260
interface BaseFields {
254-
version: "V2" | "V3" | "V4" | "V5" | "V6" | "V7" | "V8" | "V9" | "V10" | "V13";
261+
version: "V2" | "V3" | "V4" | "V5" | "V6" | "V7" | "V8" | "V9" | "V10" | "V11" | "V12" | "V13";
255262
nativeFee: bigint;
256263
linkFee: bigint;
257264
expiresAt: number;
@@ -264,14 +271,16 @@ interface BaseFields {
264271
### Schema-Specific Fields
265272
266273
- **V2/V3/V4**: `price: bigint` - Standard price data
267-
- **V3**: `bid: bigint, ask: bigint` - Crypto bid/ask spreads
274+
- **V3**: `bid: bigint, ask: bigint` - Crypto bid/ask spreads
268275
- **V4**: `marketStatus: MarketStatus` - Real-world asset market status
269276
- **V5**: `rate: bigint, timestamp: number, duration: number` - Interest rate data with observation timestamp and duration
270277
- **V6**: `price: bigint, price2: bigint, price3: bigint, price4: bigint, price5: bigint` - Multiple price values in a single payload
271278
- **V7**: `exchangeRate: bigint` - Exchange rate data
272279
- **V8**: `midPrice: bigint, lastUpdateTimestamp: number, marketStatus: MarketStatus` - Non-OTC RWA data
273280
- **V9**: `navPerShare: bigint, navDate: number, aum: bigint, ripcord: number` - NAV fund data
274281
- **V10**: `price: bigint, lastUpdateTimestamp: number, marketStatus: MarketStatus, currentMultiplier: bigint, newMultiplier: bigint, activationDateTime: number, tokenizedPrice: bigint` - Tokenized equity data
282+
- **V11**: `mid: bigint, LastSeenTimestampNs: number, bid: bigint, vidVolume: number, ask: bigint, askVolume: number, lastTradedPrice: bigint, marketStatus: MarketStatus` - Deutsche Boerse
283+
- **V12**: `navPerShare: bigint, nextNavPerShare: bigint, navDate: number, ripcord: number` - NAV fund data + Next
275284
- **V13**: `bestAsk: bigint, bestBid: bigint, askVolume: number, bidVolume: number, lastTradedPrice: bigint` - Best Bid/Ask
276285
277286
For complete field definitions, see the [documentation](https://docs.chain.link/data-streams/reference/report-schema-v3).
@@ -281,7 +290,7 @@ For complete field definitions, see the [documentation](https://docs.chain.link/
281290
HA mode establishes multiple simultaneous connections for zero-downtime operation:
282291
283292
- **Automatic failover** between connections
284-
- **Report deduplication** across connections
293+
- **Report deduplication** across connections
285294
- **Automatic origin discovery** to find available endpoints
286295
- **Per-connection monitoring** and statistics
287296
@@ -303,22 +312,22 @@ const client = createClient({
303312
304313
### Error Types Overview
305314
306-
| **Error Type** | **When Thrown** | **Key Properties** |
307-
|---|---|---|
308-
| `ValidationError` | Invalid feed IDs, timestamps, parameters | `message` |
309-
| `AuthenticationError` | Invalid credentials, HMAC failures | `message` |
310-
| `APIError` | HTTP 4xx/5xx, network timeouts, rate limits | `statusCode`, `message` |
311-
| `ReportDecodingError` | Corrupted report data, unsupported versions | `message` |
312-
| `WebSocketError` | Connection failures, protocol errors | `message` |
313-
| `OriginDiscoveryError` | HA discovery failures | `cause`, `message` |
314-
| `MultiConnectionError` | All HA connections failed | `message` |
315-
| `PartialConnectionFailureError` | Some HA connections failed | `failedConnections`, `totalConnections` |
316-
| `InsufficientConnectionsError` | HA degraded performance | `availableConnections`, `requiredConnections` |
315+
| **Error Type** | **When Thrown** | **Key Properties** |
316+
|---------------------------------|---------------------------------------------|-----------------------------------------------|
317+
| `ValidationError` | Invalid feed IDs, timestamps, parameters | `message` |
318+
| `AuthenticationError` | Invalid credentials, HMAC failures | `message` |
319+
| `APIError` | HTTP 4xx/5xx, network timeouts, rate limits | `statusCode`, `message` |
320+
| `ReportDecodingError` | Corrupted report data, unsupported versions | `message` |
321+
| `WebSocketError` | Connection failures, protocol errors | `message` |
322+
| `OriginDiscoveryError` | HA discovery failures | `cause`, `message` |
323+
| `MultiConnectionError` | All HA connections failed | `message` |
324+
| `PartialConnectionFailureError` | Some HA connections failed | `failedConnections`, `totalConnections` |
325+
| `InsufficientConnectionsError` | HA degraded performance | `availableConnections`, `requiredConnections` |
317326
318327
### Usage Examples
319328
320329
```typescript
321-
import {
330+
import {
322331
ValidationError,
323332
AuthenticationError,
324333
APIError,
@@ -356,6 +365,7 @@ stream.on('error', (error) => {
356365
```
357366
358367
**Catch-all error handling:**
368+
359369
```typescript
360370
import { DataStreamsError } from './src';
361371

@@ -402,6 +412,7 @@ const client = createClient({
402412
```
403413
404414
Using Pino (structured JSON):
415+
405416
```typescript
406417
import pino from 'pino';
407418
import { createClient, LogLevel } from '@chainlink/data-streams-sdk';
@@ -427,6 +438,7 @@ const client = createClient({
427438
```
428439
429440
Command-line with pretty output:
441+
430442
```bash
431443
PINO_LEVEL=info npx ts-node examples/metrics-monitoring.ts | npx pino-pretty
432444
```
@@ -503,10 +515,10 @@ interface LoggingConfig {
503515
warn?: (message: string, ...args: any[]) => void;
504516
error?: (message: string, ...args: any[]) => void;
505517
};
506-
518+
507519
/** Minimum logging level - filters out lower priority logs */
508520
logLevel?: LogLevel; // DEBUG (0) | INFO (1) | WARN (2) | ERROR (3)
509-
521+
510522
/** Enable WebSocket ping/pong and connection state debugging logs */
511523
enableConnectionDebug?: boolean;
512524
}
@@ -531,6 +543,7 @@ const m = stream.getMetrics();
531543
```
532544
533545
Simple periodic print (example):
546+
534547
```typescript
535548
setInterval(() => {
536549
const m = stream.getMetrics();

typescript/examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ npx ts-node examples/list-feeds.ts
8787

8888
## Feed IDs
8989

90-
The SDK automatically detects and supports all report schema versions (V2, V3, V4, V5, V6, V7, V8, V9, V10, V13).
90+
The SDK automatically detects and supports all report schema versions (V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13).
9191

9292
For available feed IDs, see the official [Chainlink documentation](https://docs.chain.link/data-streams/).
9393

typescript/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chainlink/data-streams-sdk",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "TypeScript SDK for Chainlink Data Streams",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

0 commit comments

Comments
 (0)