Go SDK

Encrypted Go client for the GoDark API. Module: github.com/gq-godark/gdx-go-sdk (import as godark).

Requirements: Go 1.22+
Status: Beta — clone the public examples repo to get started.

Get the SDK

Clone gdx-go-sdk-examples. The repo vendors the SDK under sdk/ (replace in go.mod) so no private module proxy is required:

git clone https://github.com/gq-godark/gdx-go-sdk-examples.git
cd gdx-go-sdk-examples
cp .env.example .env
# set GODARK_API_KEY_ID, GODARK_API_SECRET, GODARK_PASSPHRASE

go build ./examples/...
go run ./examples/quickstart
go run ./examples/full_trader_example

You can also point an LLM / coding agent at the cloned repo and ask it to build a strategy using your credentials in .env. See the repo README for full setup, examples, and packaging details.

Public module proxy release is not yet available; until then this repo is the supported distribution.

Quickstart

Set credentials, then place a limit order over encrypted WebSocket (godark.NewClient). Subscribe to orders before placing so book confirmation can wait on private updates. Limit prices must stay near the oracle or the venue rejects — see Error Codes.

package main

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

	"github.com/gq-godark/gdx-go-sdk"
)

func main() {
	client, err := godark.NewClient(godark.ClientConfig{
		APIKeyID:    os.Getenv("GODARK_API_KEY_ID"),
		APISecret:   os.Getenv("GODARK_API_SECRET"),
		Passphrase:  os.Getenv("GODARK_PASSPHRASE"),
		Environment: godark.EnvironmentTestnet,
		BaseURL:     os.Getenv("GODARK_EDGE_URL"), // empty => Testnet preset
	})
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()
	if err := client.Connect(ctx); err != nil {
		log.Fatal(err)
	}
	defer func() { _ = client.Disconnect() }()

	if err := client.Subscribe(ctx, "orders"); err != nil {
		log.Fatal(err)
	}

	ack, err := client.PlaceOrder(ctx, godark.PlaceOrderRequest{
		Symbol:    "BTC-USDC-PERP",
		Side:      godark.SideSell,
		OrderType: godark.OrderTypeLimit,
		Price:     68000, // within ~10% of oracle
		Quantity:  0.01,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("placed %s\n", ack.OrderID)

	time.Sleep(500 * time.Millisecond)

	cancel, err := client.CancelOrder(ctx, ack.OrderID, "BTC-USDC-PERP")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("cancelled %s\n", cancel.OrderID)
}

See WebSocket Trading and Place Order for request fields.

Clients

TypeDescription
GodarkClientWebSocket trading + order/position streams on /ws/v1
MarketDataClientExternal venue feeds on /ws/gomarket

Construct with godark.NewClient(cfg). GodarkRestClient / NewRestClient may still be exported for residual HTTP helpers; encrypted order place / cancel / modify is WebSocket-only.

GodarkClient methods

MethodDocs reference
Connect(ctx) / Disconnect()Authentication, Encryption
Subscribe(ctx, ...)WebSocket Trading
PlaceOrder(ctx, req)Place Order, WebSocket Trading
CancelOrder(ctx, orderID, symbol)Cancel Order
ModifyOrder(ctx, ...)Modify Order
MassQuote(ctx, ...)Mass Quote
BatchCancel(ctx, ...)Cancel Order
OrderUpdates()Orders Channel
PositionUpdates()Positions Channel

Callbacks (OnOrderUpdate, etc.) run on the WebSocket receive goroutine — keep them fast or hand off to your own queue. The SDK does not auto-reconnect.

Types and errors

Exported enums: Environment, Side, OrderType, TimeInForce, OrderStatus, and related request/ack types.

Error types (use errors.As): AuthenticationError, SessionError, OrderError, EncryptionError, ConnectionError, TimeoutError. See Error Codes.

Environment variables: OS GODARK_*, then OS GDX_*, then .env GODARK_*, then .env GDX_*. The process environment always wins over .env. Quickstart snippets use the canonical GODARK_* names.

Bundled examples

Runnable under examples/ in the examples repo: quickstart (connect → subscribe → place → cancel) and full_trader_example (modify, mass quote, batch cancel).

go run ./examples/quickstart

See also