Skip to content

coinbase-samples/deribit-sdk-go

Repository files navigation

Deribit Go SDK

GoDoc Go Report Card

Overview

The Deribit Go SDK is a sample Go library for the Deribit API. The SDK uses JSON-RPC 2.0 for communication and supports automatic authentication and token refresh for private endpoints.

License

The SDK is licensed under the Apache License, Version 2.0.

Usage

To use the SDK, pass your Deribit API credentials as a JSON-encoded environment variable.

Create a .env file in the project root (already in .gitignore):

DERIBIT_CREDENTIALS='{"clientId":"your_client_id","clientSecret":"your_client_secret"}'

Then source it before running examples:

source .env

Or export directly in your shell:

export DERIBIT_CREDENTIALS='{"clientId":"your_client_id","clientSecret":"your_client_secret"}'

Then initialize the client:

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/coinbase-samples/deribit-sdk-go/client"
    "github.com/coinbase-samples/deribit-sdk-go/credentials"
    "github.com/coinbase-samples/deribit-sdk-go/marketdata"
)

func main() {
    creds, err := credentials.ReadEnvCredentials("DERIBIT_CREDENTIALS")
    if err != nil {
        log.Fatalf("Error reading credentials: %v", err)
    }

    httpClient, err := client.DefaultHttpClient()
    if err != nil {
        log.Fatalf("Error creating HTTP client: %v", err)
    }

    c := client.NewRestClient(creds, &httpClient)
    service := marketdata.NewMarketDataService(c)

    resp, err := service.GetIndexPrice(context.Background(), &marketdata.GetIndexPriceRequest{
        IndexName: "btc_usd",
    })
    if err != nil {
        log.Fatalf("Error: %v", err)
    }

    fmt.Printf("BTC/USD Index Price: %s\n", resp.IndexPrice)
}

By default, the client connects to the testnet (https://test.deribit.com/api/v2). To use production:

c := client.NewRestClient(creds, &httpClient)
c.SetHttpBaseUrl(client.ProductionURL)

Build

go build ./...

Disclaimer

This SDK is offered by Coinbase to help simplify integrating with the Deribit API for institutional customers. While we aim for accuracy, Coinbase assumes no responsibility for any issues that may arise from using this SDK. Users should test thoroughly and use the SDK at their own risk. For official API documentation, please refer to the Deribit API docs.

About

Early release of the Deribit Go SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages