Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.hit.com/llms.txt

Use this file to discover all available pages before exploring further.

Hit trading bots use API key authentication with HMAC-SHA256 signatures. Public market data endpoints do not require authentication. Private trading endpoints and the /user WebSocket namespace require a trading API key, secret, and passphrase.
Keep the API secret and passphrase out of source control and browser code. They are for server-side bots and services.

Credentials

Configure your bot with:
export HIT_API_KEY='API_KEY'
export HIT_API_SECRET='API_SECRET'
export HIT_API_PASSPHRASE='API_PASSPHRASE'
API key creation and key management are handled in the Hit app. These docs cover how to use an existing trading key from a programmatic client.

REST HMAC Headers

Every authenticated REST request must include:
HeaderValue
hit-api-keyAPI key identifier
hit-signatureHMAC-SHA256 signature
hit-timestampUnix timestamp in milliseconds
hit-passphraseAPI passphrase returned at key creation
The signature message is:
timestamp + method + path + body
Rules:
  • method is uppercase, such as GET, POST, or DELETE.
  • path includes /api/v1 and excludes the scheme, host, and query string.
  • body is the exact JSON string sent on the request, or an empty string for requests without a body.
  • Timestamps must be within 30 seconds of server time.

REST Signing Examples

import { createHmac } from "node:crypto";

type JsonBody = Record<string, unknown>;

function signRequest(
  apiSecret: string,
  timestamp: string,
  method: string,
  path: string,
  body = "",
) {
  return createHmac("sha256", apiSecret)
    .update(`${timestamp}${method.toUpperCase()}${path}${body}`)
    .digest("hex");
}

async function hitRequest(method: string, path: string, body?: JsonBody) {
  const apiHost = "https://hit.com";
  const fullPath = `/api/v1${path}`;
  const timestamp = Date.now().toString();
  const bodyText = body ? JSON.stringify(body) : "";

  const response = await fetch(`${apiHost}${fullPath}`, {
    method,
    headers: {
      "Content-Type": "application/json",
      "hit-api-key": process.env.HIT_API_KEY!,
      "hit-signature": signRequest(
        process.env.HIT_API_SECRET!,
        timestamp,
        method,
        fullPath,
        bodyText,
      ),
      "hit-timestamp": timestamp,
      "hit-passphrase": process.env.HIT_API_PASSPHRASE!,
    },
    body: bodyText || undefined,
  });

  if (!response.ok) {
    throw new Error(`${response.status}: ${await response.text()}`);
  }

  return response.json() as Promise<unknown>;
}

const orders = await hitRequest("GET", "/orders");
console.log(orders);

WebSocket Auth

The /user Socket.IO namespace authenticates after connect with a user-connect message. The WebSocket signature message is different from REST:
timestamp + WEBSOCKET + /user
Payload:
{
  "auth": {
    "apiKey": "API_KEY",
    "signature": "HMAC_SIGNATURE",
    "timestamp": "1778748000000",
    "passphrase": "API_PASSPHRASE"
  }
}
The server responds on user-authenticated with { "success": true } or { "success": false, "error": "..." }.

Security Notes

  • Keep API secrets out of source control and client-side browser code.
  • Use separate keys for separate bots or services.
  • Deactivate unused or compromised keys immediately.
  • Keep host clocks synchronized; requests outside the timestamp window are rejected.