JavaScript / TypeScript SDK

Encrypted JavaScript and TypeScript client for the GoDark API. Package name: @godark/sdk.

Requirements: Node.js 18+
Status: Beta — clone the public examples repo to get started.

Get the SDK

Clone gdx-js-sdk-examples. The repo vendors @godark/sdk under sdk/ so no private npm registry is required:

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

npm install
npm run quickstart
npm run full-trader

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 npm release is not yet available; until then this repo is the supported distribution.

Quickstart

Set credentials, then place a limit order over encrypted WebSocket (GodarkClient). Subscribe to orders before placing so book confirmation can wait on private updates. Limit prices must stay within ~10% of oracle (PRICE_DEVIATION_TOO_LARGE).

import { Environment, GodarkClient } from "@godark/sdk";

const SYMBOL = "BTC-USDC-PERP";

async function main(): Promise<void> {
  const edge = process.env.GODARK_EDGE_URL?.trim();
  const client = new GodarkClient({
    apiKeyId: process.env.GODARK_API_KEY_ID!,
    apiSecret: process.env.GODARK_API_SECRET!,
    passphrase: process.env.GODARK_PASSPHRASE!,
    environment: Environment.Testnet,
    ...(edge ? { baseUrl: edge } : {}),
  });

  await client.connect();
  await client.subscribe(["orders"]);

  const ack = await client.placeOrder({
    symbol: SYMBOL,
    side: "SELL",
    orderType: "LIMIT",
    price: 68000, // within ~10% of oracle
    quantity: 0.01,
  });
  console.log("placed", ack.orderId);

  await new Promise((r) => setTimeout(r, 500));
  const cancel = await client.cancelOrder(ack.orderId, SYMBOL);
  console.log("cancelled", cancel.orderId);

  await client.disconnect();
}

main().catch(console.error);

See WebSocket Trading and Place Order for request fields.

Clients

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

The package ships ESM, CJS, and TypeScript declarations (dist/index.js, dist/index.d.ts).

GodarkRestClient may still be exported for residual HTTP helpers; encrypted order place / cancel / modify is WebSocket-only.

GodarkClient methods

MethodDocs reference
connect() / disconnect()Authentication, Encryption
subscribe(...)WebSocket Trading
placeOrder(...)Place Order, WebSocket Trading
cancelOrder(...)Cancel Order
modifyOrder(...)Modify Order
massQuote(...)Mass Quote
batchCancel(...)Cancel Order
Order update callbacksOrders Channel
Position update callbacksPositions Channel

Types and errors

Exported types include Environment, OrderAck, OrderUpdate, PositionUpdate, Side, OrderType, TimeInForce, and typed error classes (AuthenticationError, SessionError, OrderError, and similar).

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 samples in the examples repo include quickstart.ts (connect → subscribe → place → cancel) and full-trader-example.ts (modify, mass quote, batch cancel) — npm run quickstart, npm run full-trader.

See also