2024-04-17 06:13:21 +00:00
2023-09-08 08:39:35 -07:00
2023-07-05 20:09:22 -07:00
2024-04-16 15:22:47 -07:00
2023-05-23 12:40:57 -07:00
2023-10-27 11:39:05 -07:00
2024-03-29 17:26:36 -07:00
2024-02-19 23:37:13 -08:00
2023-05-23 12:40:57 -07:00

DLOB Server for Drift Protocol v2

Docs Discord Chat License

DLOB Server

This is the backend server that provides a REST API for the drift DLOB.

Run the server

Setup

First set the necessary environment variables:

cp .env.example .env

Environment Configuration

To properly configure the DLOB server, set the following environment variables in your .env file:

Variable Description Example Value
ENDPOINT The Solana RPC node http endpoint. https://your-private-rpc-node.com
WS_ENDPOINT The Solana RPC node websocket endpoint. wss://your-private-rpc-node.com
USE_WEBSOCKET Flag to enable WebSocket connection. true
USE_ORDER_SUBSCRIBER Flag to enable order subscriber DLOB source. true
DISABLE_GPA_REFRESH Flag to disable periodic refresh using getProgramAccounts. true
ENV The network environment the server is connecting to. mainnet-beta
PORT The port number the HTTP server listens on. 6969
METRICS_PORT The port number for Prometheus metrics. 9465
PRIVATE_KEY Path to the Solana private key file. /path/to/keypair.json
RATE_LIMIT_CALLS_PER_SECOND Maximum number of API calls per second. 100
PERP_MARKETS_TO_LOAD Number of perpetual markets to load at startup. 0
SPOT_MARKETS_TO_LOAD Number of spot markets to load at startup. 5
REDIS_HOSTS (for websocket server) Redis host endpoint. localhost
REDIS_PASSWORDS (for websocket server) Redis password. password
REDIS_PORTS (for websocket server) Redis port. 6379
WS_PORT (for websocket server) The port to run the websocket server on. 3000

Note: multiple Redis hosts can be provided by providing a comma separated string.

HTTP mode

The HTTP server as documented here can be run with, and by default accessible on http://127.0.0.1:6969:

yarn run dev

Websocket mode

The websocket server has 2 components, the dlob-publisher that takes frequent snapshots of the DLOB and publishes them to Redis, and ws-manager listens for new connections and sends the latest DLOB to ws clients, the two components communicate through Redis pub-sub.

To run the websocket server, a Redis cache is required, and the following environment variables must be set:

  • REDIS_HOSTS
  • REDIS_PASSWORDS
  • REDIS_PORTS

In one terminal, run:

yarn run dlob-publisher

In a second terminal, run:

yarn run ws-manager

Then connect to the ws server at ws://127.0.0.1:3000

Run the example client

Documentation for connecting to the dlob server are available here

TODO: complete client examples.

Description
No description provided
Readme 2.2 MiB
Languages
TypeScript 89.8%
HTML 6.8%
Shell 3%
JavaScript 0.2%
Dockerfile 0.2%