Skip to content

Commit d3ea0fd

Browse files
authored
Data Streams: New TypeScript SDK, Updated HA Mode, and Go SDK Reference Update (#3005)
* init, blank * draft ts-sdk-fetch * ts sdk stream draft * ts-node->tsx * updated installation instructions, avoid typescript issues * sdk reference cherrypicked from old branch * lint + link fix * update go sdk docs: ha mode, requirements, and report format+schema guidance * update * trim * more references * bumped example output with vetted, real returns from npm package testing * restore section for multiple streams + normalize * ha mode polish * link fix * heading level * added clarifying comments * codesample update
1 parent af250dd commit d3ea0fd

File tree

19 files changed

+1775
-65
lines changed

19 files changed

+1775
-65
lines changed
Lines changed: 1 addition & 0 deletions
Loading

src/config/sidebar.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
446446
{
447447
title: "Fetch and decode reports",
448448
url: "data-streams/tutorials/go-sdk-fetch",
449-
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-fetch"],
449+
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-fetch", "data-streams/tutorials/ts-sdk-fetch"],
450450
},
451451
{
452452
title: "Stream and decode reports (WebSocket)",
453453
url: "data-streams/tutorials/go-sdk-stream",
454-
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-stream"],
454+
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-stream", "data-streams/tutorials/ts-sdk-stream"],
455455
},
456456
{
457457
title: "Verify report data (EVM)",
@@ -529,7 +529,10 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
529529
{
530530
title: "SDK References",
531531
url: "data-streams/reference/data-streams-api/go-sdk",
532-
highlightAsCurrent: ["data-streams/reference/data-streams-api/rust-sdk"],
532+
highlightAsCurrent: [
533+
"data-streams/reference/data-streams-api/rust-sdk",
534+
"data-streams/reference/data-streams-api/ts-sdk",
535+
],
533536
},
534537
{
535538
title: "Onchain report verification (EVM chains)",

src/content/data-streams/index.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ Chainlink Data Streams offers price points such as mid prices and [Liquidity-Wei
5050

5151
Data Streams API services use an [active-active multi-site deployment](/data-streams/architecture#active-active-multi-site-deployment) model across multiple distributed and isolated origins. This architecture ensures continuous operations even if one origin fails, delivering robust fault tolerance and high availability.
5252

53+
For real-time streaming applications, the SDKs support **High Availability (HA) mode** that establishes multiple simultaneous connections for zero-downtime operation. When enabled, HA mode provides:
54+
55+
- **Automatic failover** between connections
56+
- **Report deduplication** across connections
57+
- **Automatic origin discovery** to find available endpoints
58+
- **Per-connection monitoring** and statistics
59+
60+
**Learn more:** [Go SDK](/data-streams/reference/data-streams-api/go-sdk#high-availability-ha-mode) | [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk#high-availability-mode) | [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk#high-availability-mode)
61+
5362
## Example use cases
5463

5564
Access to low-latency, high-frequency data enables a variety of onchain applications:
@@ -82,6 +91,7 @@ Access data directly through REST APIs or WebSocket connections using our SDKs:
8291

8392
- **[Go SDK](/data-streams/reference/data-streams-api/go-sdk)** - Full-featured SDK with comprehensive examples
8493
- **[Rust SDK](/data-streams/reference/data-streams-api/rust-sdk)** - High-performance SDK for Rust applications
94+
- **[TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk)** - Type-safe SDK for TypeScript applications
8595
- **[REST API](/data-streams/reference/data-streams-api/interface-api)** or **[WebSocket](/data-streams/reference/data-streams-api/interface-ws)** - Direct access to Data Streams endpoints
8696

8797
### Getting started

src/content/data-streams/reference/data-streams-api/authentication/go-examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Go.
1717

1818
To learn more about the Data Streams API authentication, see the [Data Streams Authentication](/data-streams/reference/data-streams-api/authentication) page.
1919

20-
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk) or [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), you don't need to implement the authentication logic manually.
20+
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk), [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), or [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk), you don't need to implement the authentication logic manually.
2121

2222
## API Authentication Example
2323

src/content/data-streams/reference/data-streams-api/authentication/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ This page explains how to authenticate with the Chainlink Data Streams API, cove
2626

2727
<Aside type="note" title="Data Streams SDKs">
2828
The Data Streams SDKs handle authentication automatically. If you're using the [Go
29-
SDK](/data-streams/reference/data-streams-api/go-sdk) or [Rust
30-
SDK](/data-streams/reference/data-streams-api/rust-sdk), you don't need to implement the authentication logic
31-
manually.
29+
SDK](/data-streams/reference/data-streams-api/go-sdk), [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk),
30+
or [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk), you don't need to implement the authentication
31+
logic manually.
3232
</Aside>
3333

3434
## Authentication Requirements

src/content/data-streams/reference/data-streams-api/authentication/javascript-examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Java
1717

1818
To learn more about the Data Streams API authentication, see the [Data Streams Authentication](/data-streams/reference/data-streams-api/authentication) page.
1919

20-
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk) or [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), you don't need to implement the authentication logic manually.
20+
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk), [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), or [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk), you don't need to implement the authentication logic manually.
2121

2222
## API Authentication Example
2323

src/content/data-streams/reference/data-streams-api/authentication/rust-examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Rust
1717

1818
To learn more about the Data Streams API authentication, see the [Data Streams Authentication](/data-streams/reference/data-streams-api/authentication) page.
1919

20-
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk) or [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), you don't need to implement the authentication logic manually.
20+
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk), [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), or [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk), you don't need to implement the authentication logic manually.
2121

2222
## API Authentication Example
2323

src/content/data-streams/reference/data-streams-api/authentication/typescript-examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Type
1717

1818
To learn more about the Data Streams API authentication, see the [Data Streams Authentication](/data-streams/reference/data-streams-api/authentication) page.
1919

20-
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk) or [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), you don't need to implement the authentication logic manually.
20+
**Note**: The Data Streams SDKs handle authentication automatically. If you're using the [Go SDK](/data-streams/reference/data-streams-api/go-sdk), [Rust SDK](/data-streams/reference/data-streams-api/rust-sdk), or [TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk), you don't need to implement the authentication logic manually.
2121

2222
## API Authentication Example
2323

src/content/data-streams/reference/data-streams-api/go-sdk.mdx

Lines changed: 135 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,30 @@ import { PageTabs } from "@components"
3232
url: "/data-streams/reference/data-streams-api/rust-sdk",
3333
icon: "/images/tutorial-icons/rust_logo_blk.svg",
3434
},
35+
{
36+
name: "TypeScript SDK",
37+
url: "/data-streams/reference/data-streams-api/ts-sdk",
38+
icon: "/images/tutorial-icons/ts_logo_black.svg",
39+
},
3540
]}
3641
/>
3742

3843
This documentation provides a detailed reference for the Data Streams SDK for Go. It implements a client library that offers a domain-oriented abstraction for interacting with the Data Streams API and enables both point-in-time data retrieval and real-time data streaming with built-in fault tolerance capabilities.
3944

45+
## Requirements
46+
47+
- Go 1.22.4 or later
48+
- Valid Chainlink Data Streams credentials
49+
50+
## Installation
51+
52+
```go
53+
go get github.com/smartcontractkit/data-streams-sdk/go
54+
```
55+
4056
## streams
4157

42-
### Installation
58+
### Import
4359

4460
```go
4561
import streams "github.com/smartcontractkit/data-streams-sdk/go"
@@ -56,31 +72,37 @@ import streams "github.com/smartcontractkit/data-streams-sdk/go"
5672
- `GetFeeds`: Lists all streams available to you.
5773

5874
```go
59-
GetFeeds(ctx context.Context) (r []*Feed, err error)
75+
GetFeeds(ctx context.Context) (r []*feed.Feed, err error)
6076
```
6177

6278
- `GetLatestReport`: Fetches the latest report available for the specified `FeedID`.
6379

6480
```go
65-
GetLatestReport(ctx context.Context, id FeedID) (r *Report, err error)
81+
GetLatestReport(ctx context.Context, id feed.ID) (r *ReportResponse, err error)
6682
```
6783

6884
- `GetReports`: Fetches reports for the specified stream IDs and a given timestamp.
6985

7086
```go
71-
GetReports(ctx context.Context, ids []FeedID, timestamp uint64) ([]*Report, error)
87+
GetReports(ctx context.Context, ids []feed.ID, timestamp uint64) ([]*ReportResponse, error)
7288
```
7389

7490
- `GetReportPage`: Paginates the reports for a specified `FeedID` starting from a given timestamp.
7591

7692
```go
77-
GetReportPage(ctx context.Context, id FeedID, startTS uint64) (*ReportPage, error)
93+
GetReportPage(ctx context.Context, id feed.ID, startTS uint64) (*ReportPage, error)
7894
```
7995

8096
- `Stream`: Creates a real-time report stream for specified stream IDs.
8197

8298
```go
83-
Stream(ctx context.Context, feedIDs []FeedID) (Stream, error)
99+
Stream(ctx context.Context, feedIDs []feed.ID) (Stream, error)
100+
```
101+
102+
- `StreamWithStatusCallback`: Creates a real-time report stream for specified stream IDs with a callback function for connection status updates.
103+
104+
```go
105+
StreamWithStatusCallback(ctx context.Context, feedIDs []feed.ID, connStatusCallback func(isConnected bool, host string, origin string)) (Stream, error)
84106
```
85107

86108
#### `Config` struct
@@ -89,24 +111,24 @@ Configuration struct for the client. `Config` specifies the client configuration
89111

90112
```go
91113
type Config struct {
92-
ApiKey string // Client API key
93-
ApiSecret string // Client API secret
94-
RestURL string // Rest API URL
95-
96-
WsURL string // Websocket API URL
97-
98-
WsHA bool // Use concurrent connections to multiple Streams servers
99-
WsMaxReconnect int // Maximum number of reconnection attempts for Stream underlying connections
100-
LogDebug bool // Log debug information
101-
InsecureSkipVerify bool // Skip server certificate chain and host name verification
114+
ApiKey string // Client API key
115+
ApiSecret string // Client API secret
116+
RestURL string // Rest API URL
117+
WsURL string // Websocket API URL
118+
WsHA bool // Use concurrent connections to multiple Streams servers
119+
WsMaxReconnect int // Maximum number of reconnection attempts for Stream underlying connections
120+
LogDebug bool // Log debug information
121+
InsecureSkipVerify bool // Skip server certificate chain and host name verification
102122
Logger func(format string, a ...any) // Logger function
103123

104-
// InspectHttp intercepts http responses for rest requests.
124+
// InspectHttpResponse intercepts http responses for rest requests.
105125
// The response object must not be modified.
106126
InspectHttpResponse func(*http.Response)
107127
}
108128
```
109129

130+
**Note**: If `WsMaxReconnect` is not specified, it defaults to 5 attempts.
131+
110132
#### `CtxKey` string
111133

112134
Custom context key type used for passing additional headers.
@@ -133,8 +155,8 @@ Represents a paginated response of reports.
133155

134156
```go
135157
type ReportPage struct {
136-
Reports []*Report // Slice of Report, representing individual report entries.
137-
NextPageTS uint64 // Timestamp for the next page, used for fetching subsequent pages.
158+
Reports []*ReportResponse // Slice of ReportResponse, representing individual report entries.
159+
NextPageTS uint64 // Timestamp for the next page, used for fetching subsequent pages.
138160
}
139161
```
140162

@@ -206,7 +228,7 @@ type Stats struct {
206228
- An error state is encountered in any of the underlying connections, such as a network failure.
207229

208230
```go
209-
Read(context.Context) (*Report, error)
231+
Read(context.Context) (*ReportResponse, error)
210232
```
211233

212234
- `Stats`: Returns statistics about the stream operations as `Stats`.
@@ -221,6 +243,30 @@ type Stats struct {
221243
Close() error
222244
```
223245

246+
### High Availability (HA) Mode
247+
248+
The Data Streams SDK supports High Availability mode for WebSocket connections. When enabled with `WsHA: true`, the SDK maintains concurrent connections to different instances to ensure high availability, fault tolerance and minimize the risk of report gaps.
249+
250+
#### HA Mode Behavior
251+
252+
When high availability mode is enabled:
253+
254+
- The client queries the server for available origins using the `X-Cll-Available-Origins` header
255+
- Multiple WebSocket connections are established to different server instances
256+
- Reports are deduplicated when received across connections
257+
- Partial reconnects occur when some connections fail while others remain active
258+
- Full reconnects occur when all connections fail
259+
260+
#### HA Configuration
261+
262+
HA mode is controlled by the `WsHA` field in the client configuration:
263+
264+
```go
265+
config := streams.Config{
266+
WsHA: true, // Use concurrent connections to multiple Streams servers
267+
}
268+
```
269+
224270
### Functions
225271

226272
#### `New`
@@ -241,9 +287,19 @@ Utility function for logging.
241287
func LogPrintf(format string, a ...any)
242288
```
243289

290+
### Errors
291+
292+
#### `ErrStreamClosed`
293+
294+
Error returned when attempting to use a closed stream.
295+
296+
```go
297+
var ErrStreamClosed = fmt.Errorf("client: use of closed Stream")
298+
```
299+
244300
## feed
245301

246-
### Installation
302+
### Import
247303

248304
```go
249305
import feed "github.com/smartcontractkit/data-streams-sdk/go/feed"
@@ -265,12 +321,25 @@ Where `ID` is the unique identifier for the stream.
265321

266322
#### `FeedVersion` uint16
267323

268-
Represents the stream [report schema](/data-streams/reference/report-schema-v3) version.
324+
Represents the stream [report schema](/data-streams/reference/report-schema-overview) version.
269325

270326
```go
271327
type FeedVersion uint16
272328
```
273329

330+
##### Constants
331+
332+
- `FeedVersion1`: Version 1 schema
333+
- `FeedVersion2`: Version 2 schema
334+
- `FeedVersion3`: Version 3 schema
335+
- `FeedVersion4`: Version 4 schema
336+
- `FeedVersion5`: Version 5 schema
337+
- `FeedVersion6`: Version 6 schema
338+
- `FeedVersion7`: Version 7 schema
339+
- `FeedVersion8`: Version 8 schema
340+
- `FeedVersion9`: Version 9 schema
341+
- `FeedVersion10`: Version 10 schema
342+
274343
#### `ID` [32]byte
275344

276345
Represents a unique identifier for a stream.
@@ -313,7 +382,7 @@ type ID [32]byte
313382

314383
## report
315384

316-
### Installation
385+
### Import
317386

318387
```go
319388
import report "github.com/smartcontractkit/data-streams-sdk/go/report"
@@ -323,11 +392,11 @@ import report "github.com/smartcontractkit/data-streams-sdk/go/report"
323392

324393
#### `Data` interface
325394

326-
[Interface](https://github.com/smartcontractkit/data-streams-sdk/blob/main/go/report/report.go#L13) that represents the actual report data and attributes.
395+
[Interface](https://github.com/smartcontractkit/data-streams-sdk/blob/main/go/report/report.go#L20) that represents the actual report data and attributes.
327396

328397
```go
329398
type Data interface {
330-
v1.Data | v2.Data | v3.Data | v4.Data | v8.Data | v9.Data
399+
v1.Data | v2.Data | v3.Data | v4.Data | v5.Data | v6.Data | v7.Data | v8.Data | v9.Data | v10.Data
331400
Schema() abi.Arguments
332401
}
333402
```
@@ -382,3 +451,44 @@ streams.LogPrintf(
382451
report.Data.ExpiresAt,
383452
)
384453
```
454+
455+
## Report Format and Schema Versions
456+
457+
### Schema Versions
458+
459+
The SDK supports multiple report schema versions (v1-v10), each optimized for different use cases:
460+
461+
- **v2**: Feed IDs starting with `0x0002`
462+
- **v3**: Feed IDs starting with `0x0003` (Crypto Streams)
463+
- **v4**: Feed IDs starting with `0x0004` (Real-World Assets)
464+
- **v5**: Feed IDs starting with `0x0005`
465+
- **v6**: Feed IDs starting with `0x0006` (Multiple Price Values)
466+
- **v7**: Feed IDs starting with `0x0007` (Exchange Rate)
467+
- **v8**: Feed IDs starting with `0x0008` (Non-OTC RWA)
468+
- **v9**: Feed IDs starting with `0x0009` (NAV Fund Data)
469+
- **v10**: Feed IDs starting with `0x000a` (Tokenized Equity)
470+
471+
### Common Fields
472+
473+
All report versions include standard metadata:
474+
475+
- `FeedID`: Unique identifier for the data stream
476+
- `ValidFromTimestamp`: When the report becomes valid
477+
- `ExpiresAt`: When the report expires
478+
- `LinkFee`: Fee in LINK tokens
479+
- `NativeFee`: Fee in native blockchain currency
480+
- `ObservationsTimestamp`: When the data was observed
481+
482+
### Usage Pattern
483+
484+
Each version follows the same decoding pattern:
485+
486+
```go
487+
import v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
488+
489+
report, err := report.Decode[v3.Data](fullReport)
490+
```
491+
492+
Use the appropriate version import based on your feed's schema version, which can be determined by calling `feedID.Version()`.
493+
494+
For complete field definitions and decoding examples, see the [report schema overview](/data-streams/reference/report-schema-overview) and [fetch tutorial](/data-streams/tutorials/go-sdk-fetch).

src/content/data-streams/reference/data-streams-api/rust-sdk.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ import { PageTabs } from "@components"
3232
url: "/data-streams/reference/data-streams-api/rust-sdk",
3333
icon: "/images/tutorial-icons/rust_logo_blk.svg",
3434
},
35+
{
36+
name: "TypeScript SDK",
37+
url: "/data-streams/reference/data-streams-api/ts-sdk",
38+
icon: "/images/tutorial-icons/ts_logo_black.svg",
39+
},
3540
]}
3641
/>
3742

0 commit comments

Comments
 (0)