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 — contact GoDark for SDK access.

Installation

Public module proxy release is not yet available. Approved integrators receive distribution instructions directly.

When published:

go get github.com/gq-godark/gdx-go-sdk

Build from source (requires git submodule update --init --recursive for gdx-proto):

go build ./...
go test ./... -count=1

Quickstart

Set credentials, then place a limit order over encrypted REST:

package main

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

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

func main() {
	client, err := godark.NewRestClient(godark.RestClientConfig{
		APIKeyID:   os.Getenv("GDX_API_KEY_ID"),
		APISecret:  os.Getenv("GDX_API_SECRET"),
		Passphrase: os.Getenv("GDX_PASSPHRASE"),
		BaseURL:    os.Getenv("GDX_REST_URL"), // optional
	})
	if err != nil {
		log.Fatal(err)
	}

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

	ack, err := client.PlaceOrder(ctx, godark.PlaceOrderRestRequest{
		PlaceOrderRequest: godark.PlaceOrderRequest{
			Symbol:    "BTC-USDC-PERP",
			Side:      godark.SideBuy,
			OrderType: godark.OrderTypeLimit,
			Quantity:  0.01,
			Price:     95000,
		},
		ClientOrderID: "my-first-order",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("placed %s\n", ack.OrderID)
}

See Place Order for all request fields.

Clients

TypeDescription
GodarkRestClientREST-only: auth → session setup → encrypted /orders
GodarkClientWebSocket trading + order/position streams on /ws/v1
MarketDataClientExternal venue feeds on /ws/gomarket

Construct with godark.NewRestClient(cfg) or godark.NewClient(cfg).

GodarkRestClient methods

MethodDocs reference
Connect(ctx) / Disconnect(ctx)Authentication, Encryption
PlaceOrder(ctx, req)Place Order
CancelOrder(ctx, orderID, symbol)Cancel Order
CancelOrderByClientID(ctx, clientOrderID, symbol)Cancel Order
ModifyOrder(ctx, orderID, symbol, newPrice, newQuantity)Modify Order
GetOrder(ctx, orderID)Get Order
GetOrderByClientID(ctx, clientOrderID)Get Order
GetMe(ctx) / GetMyBalance(ctx)Account Info
AwaitTerminalStatus(ctx, orderID, timeout, pollInterval)Poll until terminal order state

GodarkClient (WebSocket)

CapabilityDocs reference
PlaceOrder, CancelOrder, ModifyOrderWebSocket Trading
Subscribe / UnsubscribeChannel subscriptions
OrderUpdates(), PositionUpdates() channelsOrders Channel, User Events

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: 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 accept GDX_* or GODARK_* prefixes (for example GODARK_API_KEY_ID, GDX_REST_URL).

Bundled examples

Runnable under examples/: quickstart_docs, full_trader_rest, full_trader_example, market_data, e2e_trading_smoke.

go run ./examples/quickstart_docs

See also