Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/images/tutorial-icons/ts_logo_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/config/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
{
title: "Fetch and decode reports",
url: "data-streams/tutorials/go-sdk-fetch",
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-fetch"],
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-fetch", "data-streams/tutorials/ts-sdk-fetch"],
},
{
title: "Stream and decode reports (WebSocket)",
url: "data-streams/tutorials/go-sdk-stream",
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-stream"],
highlightAsCurrent: ["data-streams/tutorials/rust-sdk-stream", "data-streams/tutorials/ts-sdk-stream"],
},
{
title: "Verify report data (EVM)",
Expand Down Expand Up @@ -524,7 +524,10 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
{
title: "SDK References",
url: "data-streams/reference/data-streams-api/go-sdk",
highlightAsCurrent: ["data-streams/reference/data-streams-api/rust-sdk"],
highlightAsCurrent: [
"data-streams/reference/data-streams-api/rust-sdk",
"data-streams/reference/data-streams-api/ts-sdk",
],
},
{
title: "Onchain report verification (EVM chains)",
Expand Down
10 changes: 10 additions & 0 deletions src/content/data-streams/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Chainlink Data Streams offers price points such as mid prices and [Liquidity-Wei

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.

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:

- **Automatic failover** between connections
- **Report deduplication** across connections
- **Automatic origin discovery** to find available endpoints
- **Per-connection monitoring** and statistics

**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)

## Example use cases

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

- **[Go SDK](/data-streams/reference/data-streams-api/go-sdk)** - Full-featured SDK with comprehensive examples
- **[Rust SDK](/data-streams/reference/data-streams-api/rust-sdk)** - High-performance SDK for Rust applications
- **[TypeScript SDK](/data-streams/reference/data-streams-api/ts-sdk)** - Type-safe SDK for TypeScript applications
- **[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

### Getting started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Go.

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

**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.
**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.

## API Authentication Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ This page explains how to authenticate with the Chainlink Data Streams API, cove

<Aside type="note" title="Data Streams SDKs">
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.
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.
</Aside>

## Authentication Requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Java

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

**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.
**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.

## API Authentication Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Rust

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

**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.
**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.

## API Authentication Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below are complete examples for authenticating with the Data Streams API in Type

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

**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.
**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.

## API Authentication Example

Expand Down
160 changes: 135 additions & 25 deletions src/content/data-streams/reference/data-streams-api/go-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,30 @@ import { PageTabs } from "@components"
url: "/data-streams/reference/data-streams-api/rust-sdk",
icon: "/images/tutorial-icons/rust_logo_blk.svg",
},
{
name: "TypeScript SDK",
url: "/data-streams/reference/data-streams-api/ts-sdk",
icon: "/images/tutorial-icons/ts_logo_black.svg",
},
]}
/>

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.

## Requirements

- Go 1.22.4 or later
- Valid Chainlink Data Streams credentials

## Installation

```go
go get github.com/smartcontractkit/data-streams-sdk/go
```

## streams

### Installation
### Import

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

```go
GetFeeds(ctx context.Context) (r []*Feed, err error)
GetFeeds(ctx context.Context) (r []*feed.Feed, err error)
```

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

```go
GetLatestReport(ctx context.Context, id FeedID) (r *Report, err error)
GetLatestReport(ctx context.Context, id feed.ID) (r *ReportResponse, err error)
```

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

```go
GetReports(ctx context.Context, ids []FeedID, timestamp uint64) ([]*Report, error)
GetReports(ctx context.Context, ids []feed.ID, timestamp uint64) ([]*ReportResponse, error)
```

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

```go
GetReportPage(ctx context.Context, id FeedID, startTS uint64) (*ReportPage, error)
GetReportPage(ctx context.Context, id feed.ID, startTS uint64) (*ReportPage, error)
```

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

```go
Stream(ctx context.Context, feedIDs []FeedID) (Stream, error)
Stream(ctx context.Context, feedIDs []feed.ID) (Stream, error)
```

- `StreamWithStatusCallback`: Creates a real-time report stream for specified stream IDs with a callback function for connection status updates.

```go
StreamWithStatusCallback(ctx context.Context, feedIDs []feed.ID, connStatusCallback func(isConnected bool, host string, origin string)) (Stream, error)
```

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

```go
type Config struct {
ApiKey string // Client API key
ApiSecret string // Client API secret
RestURL string // Rest API URL

WsURL string // Websocket API URL

WsHA bool // Use concurrent connections to multiple Streams servers
WsMaxReconnect int // Maximum number of reconnection attempts for Stream underlying connections
LogDebug bool // Log debug information
InsecureSkipVerify bool // Skip server certificate chain and host name verification
ApiKey string // Client API key
ApiSecret string // Client API secret
RestURL string // Rest API URL
WsURL string // Websocket API URL
WsHA bool // Use concurrent connections to multiple Streams servers
WsMaxReconnect int // Maximum number of reconnection attempts for Stream underlying connections
LogDebug bool // Log debug information
InsecureSkipVerify bool // Skip server certificate chain and host name verification
Logger func(format string, a ...any) // Logger function

// InspectHttp intercepts http responses for rest requests.
// InspectHttpResponse intercepts http responses for rest requests.
// The response object must not be modified.
InspectHttpResponse func(*http.Response)
}
```

**Note**: If `WsMaxReconnect` is not specified, it defaults to 5 attempts.

#### `CtxKey` string

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

```go
type ReportPage struct {
Reports []*Report // Slice of Report, representing individual report entries.
NextPageTS uint64 // Timestamp for the next page, used for fetching subsequent pages.
Reports []*ReportResponse // Slice of ReportResponse, representing individual report entries.
NextPageTS uint64 // Timestamp for the next page, used for fetching subsequent pages.
}
```

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

```go
Read(context.Context) (*Report, error)
Read(context.Context) (*ReportResponse, error)
```

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

### High Availability (HA) Mode

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.

#### HA Mode Behavior

When high availability mode is enabled:

- The client queries the server for available origins using the `X-Cll-Available-Origins` header
- Multiple WebSocket connections are established to different server instances
- Reports are deduplicated when received across connections
- Partial reconnects occur when some connections fail while others remain active
- Full reconnects occur when all connections fail

#### HA Configuration

HA mode is controlled by the `WsHA` field in the client configuration:

```go
config := streams.Config{
WsHA: true, // Use concurrent connections to multiple Streams servers
}
```

### Functions

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

### Errors

#### `ErrStreamClosed`

Error returned when attempting to use a closed stream.

```go
var ErrStreamClosed = fmt.Errorf("client: use of closed Stream")
```

## feed

### Installation
### Import

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

#### `FeedVersion` uint16

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

```go
type FeedVersion uint16
```

##### Constants

- `FeedVersion1`: Version 1 schema
- `FeedVersion2`: Version 2 schema
- `FeedVersion3`: Version 3 schema
- `FeedVersion4`: Version 4 schema
- `FeedVersion5`: Version 5 schema
- `FeedVersion6`: Version 6 schema
- `FeedVersion7`: Version 7 schema
- `FeedVersion8`: Version 8 schema
- `FeedVersion9`: Version 9 schema
- `FeedVersion10`: Version 10 schema

#### `ID` [32]byte

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

## report

### Installation
### Import

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

#### `Data` interface

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

```go
type Data interface {
v1.Data | v2.Data | v3.Data | v4.Data | v8.Data | v9.Data
v1.Data | v2.Data | v3.Data | v4.Data | v5.Data | v6.Data | v7.Data | v8.Data | v9.Data | v10.Data
Schema() abi.Arguments
}
```
Expand Down Expand Up @@ -382,3 +451,44 @@ streams.LogPrintf(
report.Data.ExpiresAt,
)
```

## Report Format and Schema Versions

### Schema Versions

The SDK supports multiple report schema versions (v1-v10), each optimized for different use cases:

- **v2**: Feed IDs starting with `0x0002`
- **v3**: Feed IDs starting with `0x0003` (Crypto Streams)
- **v4**: Feed IDs starting with `0x0004` (Real-World Assets)
- **v5**: Feed IDs starting with `0x0005`
- **v6**: Feed IDs starting with `0x0006` (Multiple Price Values)
- **v7**: Feed IDs starting with `0x0007` (Exchange Rate)
- **v8**: Feed IDs starting with `0x0008` (Non-OTC RWA)
- **v9**: Feed IDs starting with `0x0009` (NAV Fund Data)
- **v10**: Feed IDs starting with `0x000a` (Tokenized Equity)

### Common Fields

All report versions include standard metadata:

- `FeedID`: Unique identifier for the data stream
- `ValidFromTimestamp`: When the report becomes valid
- `ExpiresAt`: When the report expires
- `LinkFee`: Fee in LINK tokens
- `NativeFee`: Fee in native blockchain currency
- `ObservationsTimestamp`: When the data was observed

### Usage Pattern

Each version follows the same decoding pattern:

```go
import v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"

report, err := report.Decode[v3.Data](fullReport)
```

Use the appropriate version import based on your feed's schema version, which can be determined by calling `feedID.Version()`.

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).
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import { PageTabs } from "@components"
url: "/data-streams/reference/data-streams-api/rust-sdk",
icon: "/images/tutorial-icons/rust_logo_blk.svg",
},
{
name: "TypeScript SDK",
url: "/data-streams/reference/data-streams-api/ts-sdk",
icon: "/images/tutorial-icons/ts_logo_black.svg",
},
]}
/>

Expand Down
Loading
Loading