Skip to main content
This page documents a TypeScript client pattern for server-side bots and market makers. It is meant to make the API flow concrete: authenticate, fetch market data, build orders, sign orders, save orders, subscribe to streams, and cancel orders.
This pattern is for backend services and dedicated bot accounts. Do not ship private-key signing code in a browser app, and do not use a primary wallet key for automated trading.

Dependencies

The example client uses:
The example pins ethers@5 intentionally for CommonJS-friendly bot projects. If your service already runs as ESM, you can adapt the signing helpers to ethers@6+, but do not upgrade the sample dependency without also reviewing the module format and API changes.
If you build a small wrapper around the API, use a surface like this: The examples below assume a wrapper with this shape. You can also call the REST and WebSocket endpoints directly.
OrderbookApiClient is not a published package. It is a wrapper shape you implement in your own codebase against the documented endpoints. The full signing rules — EIP-712 payloads, mode-byte prefixes, and ED25519 handling — are specified in the order placement reference.

Minimal limit order flow

Signing behavior

The bot client signs the serialized order returned by buildOrders(). For ECDSA_SECP256K1 accounts:
  1. Build the EIP-712 order payload.
  2. Sign with wallet._signTypedData(domain, types, order).
  3. Prefix the signature with 0x00.
For ED25519 Hedera accounts:
  1. Build the same EIP-712 order payload.
  2. Hash it with ethers.utils._TypedDataEncoder.hash.
  3. Sign the raw hash bytes with the Hiero SDK private key.
  4. Prefix the signature bytes with 0x00.
Wallet integrations that use Hedera personal sign should instead use the 0x01 signing mode and submit a HIP-632 SignatureMap around the raw wallet signature.

Implementation notes

  • Cache the value returned by getDomain() for the current session.
  • Reuse the same authenticated account for build, sign, save, and cancellation.
  • Sign the order returned by buildOrders(), not the original request body.
  • Preserve all integer fields as strings.
  • Use baseTokenDecimals and quoteTokenDecimals from getOrderbooks() when converting between display amounts and raw token units.
  • Keep the signature mode byte in the submitted signature.
  • Re-authenticate before reconnecting WebSocket streams.

WebSocket example

Production clients should re-authenticate before reconnecting and should not log full WebSocket URLs because the JWT is passed in the query string.

Cancellation example

Cancellation is asynchronous. Wait for the user-event stream or fetch order history before treating an order as canceled.
Use nonce-floor cancellation only for emergency recovery or deliberate session shutdown flows.

Next steps

Orderbook API overview

Integration flow, environments, and the endpoint summary.

Orders and signing

The build, sign, and save flow this client wraps.

WebSocket streams

Depth diffs and user events for live reconciliation.

Market maker onboarding

Limits coordination and contacts for high-volume flow.