Go SDK

Data Engine's live data feeds can be accessed through the Relayer using the official Go SDK.

Overview

The general process to set-up and other do's & don'ts while connecting to the relayer remain the same as discussed in the WebSockets section.

Quick Start

1. Install

First, install Relayer-Go-SDK using go get command:

$ go get github.com/Yggdrasil-Protocol/Relayer-Go-SDK

2. Set-Up

Now, set-up the SDK with the relevant imports and feedIDs.

main.go
package main

import (
	"context"
	"log"
	"os"
	"time"

	rel "github.com/Yggdrasil-Protocol/Relayer-Go-SDK"
)

func main() {
	logger := log.New(os.Stdout, "relayergosdk: ", log.LstdFlags)
	feedIDs := 

	ctx, cancel := 	
	defer cancel()

	ws := 
	defer ws.Close()
}

3. Consume Events

After initializing the SDK with the relevant parameters. You can now start consuming the events through the relevant channels. Here, the deadline context helps to cleanly close off the RelayerWS connection.

main.go
dataChan, infoChan := 

err := 
if err != nil {
	logger.Panicf("Failed to subscribe: %v", err)
}

// continuously listen to events
for {
	select {
	case price, ok := <-dataChan:
		if !ok {
			return
		}
		logger.Printf("Received price feed event: %+v", price)
	case info, ok := <-infoChan:
		if !ok {
			return
		}
		logger.Printf("Received info event: %+v", info)
	}
}

Live Example

Note - Run the Go Playground for the example with the Run in Browser option i.e. WASM

Last updated