ZetariumZetariumDex

Go

Signed-request helper plus a public WebSocket subscription.

REST

// zdex/zdex.go
package zdex

import (
    "bytes"
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "sort"
    "time"
)

const (
    APIKey  = "zd_84444a6e..."
    Secret  = "073CuVWk..."
    BaseURL = "https://api.zetariumdex.com"
)

func SignedRequest(method, path string, params map[string]string, body any) ([]byte, error) {
    if params == nil {
        params = map[string]string{}
    }
    params["timestamp"] = fmt.Sprintf("%d", time.Now().UnixMilli())

    keys := make([]string, 0, len(params))
    for k := range params {
        keys = append(keys, k)
    }
    sort.Strings(keys)
    v := url.Values{}
    for _, k := range keys {
        v.Set(k, params[k])
    }
    qs := v.Encode()

    mac := hmac.New(sha256.New, []byte(Secret))
    mac.Write([]byte(qs))
    sig := hex.EncodeToString(mac.Sum(nil))

    var bodyReader io.Reader
    if body != nil {
        b, _ := json.Marshal(body)
        bodyReader = bytes.NewReader(b)
    }

    u := fmt.Sprintf("%s%s?%s&signature=%s", BaseURL, path, qs, sig)
    req, err := http.NewRequest(method, u, bodyReader)
    if err != nil {
        return nil, err
    }
    req.Header.Set("X-API-KEY", APIKey)
    if body != nil {
        req.Header.Set("Content-Type", "application/json")
    }

    res, err := http.DefaultClient.Do(req)
    if err != nil {
        return nil, err
    }
    defer res.Body.Close()
    return io.ReadAll(res.Body)
}

Usage

package main

import (
    "fmt"
    "github.com/google/uuid"
    "yourproject/zdex"
)

func main() {
    // 1. Read futures balance
    balance, _ := zdex.SignedRequest("GET", "/v2/futures/balance", nil, nil)
    fmt.Println(string(balance))

    // 2. Idempotent LIMIT BUY
    _, _ = zdex.SignedRequest("POST", "/v2/orders", nil, map[string]any{
        "symbol":        "BTCUSDT",
        "side":          "BUY",
        "type":          "LIMIT",
        "quantity":      "0.001",
        "price":         "30000",
        "clientOrderId": uuid.NewString(),
    })
}

WebSocket — public ticker

import (
    "fmt"
    "github.com/gorilla/websocket"
)

conn, _, _ := websocket.DefaultDialer.Dial("wss://api.zetariumdex.com/ws", nil)
defer conn.Close()

_ = conn.WriteJSON(map[string]string{
    "action":  "subscribe",
    "channel": "ticker",
    "symbol":  "BTCUSDT",
})

for {
    _, raw, err := conn.ReadMessage()
    if err != nil {
        return
    }
    fmt.Println(string(raw))
}

On this page