Relayer API

The Relayer API provides programmatic access to the Twilight Exchange, including market data, account operations, and real-time streams. It consists of three main components:

  • Public API — for general market data (no authentication required).

  • Private API — for authenticated trading and account operations.

  • WebSocket Streams — for live price and market updates.

This guide outlines how to connect, query, and subscribe using each of these interfaces. For full endpoint specifications and live code examples, visit the Twilight API Referencearrow-up-right.


Public API

The Public API provides access to market data without requiring authentication. These endpoints are ideal for fetching order books, tickers, trades, and other publicly available exchange data.

Base URL

https://api.twilight.rest/api/v1/

Common Endpoints

Endpoint
Description

/markets

List available trading pairs.

/ticker?symbol=BTCUSDT

Latest ticker information for a trading pair.

/orderbook?symbol=BTCUSDT

Retrieve the current order book snapshot.

/trades?symbol=BTCUSDT

Recent trades for a given symbol.

Example Request (Shell)

Example Response

Use the public API for lightweight integrations such as dashboards, analytics, or bots that don’t require authentication.


Private API

The Private API allows users to execute trades, manage orders, and query their account balances. Authentication is required using your Twilight API key and secret.

Authentication

All private requests must be signed using your API key. Include headers:

Common Endpoints

Endpoint
Description

/order

Place a new order (limit or market).

/cancel

Cancel an existing order.

/balance

Retrieve wallet balances.

/positions

View open or closed positions.

Example Request (POST /order)

Example Response

For details on signing, authentication flow, and error codes, see the Private API Referencearrow-up-right.


WebSocket Streams

For real-time updates, Twilight provides WebSocket streams for both public market data and authenticated account notifications.

WebSocket URL

Available Streams

Stream
Description

@ticker

Live ticker updates for all markets.

@trades

Real-time trade events.

@orderbook

Incremental order book updates.

@account

Account balance and order updates (authenticated).

Example Connection

Example Response

WebSocket streams are the preferred way to monitor markets and active positions with minimal latency.


circle-info

Best Practices

  • Use REST endpoints for snapshots and WebSockets for live updates.

  • Implement rate-limiting and reconnect logic in your client.

  • Validate all signatures and timestamps on Private API requests.

  • Keep your API keys secure — never expose them in front-end code.

  • For heavy-load trading bots, consider local caching of order books.


Additional Resources

Last updated: November 2025

Last updated