update README.md
This commit is contained in:
114
README.md
114
README.md
@@ -1,7 +1,7 @@
|
||||
<div align="center">
|
||||
<img height="120x" src="https://uploads-ssl.webflow.com/611580035ad59b20437eb024/616f97a42f5637c4517d0193_Logo%20(1)%20(1).png" />
|
||||
|
||||
<h1 style="margin-top:20px;">DLOB Serverfor Drift Protocol v2</h1>
|
||||
<h1 style="margin-top:20px;">DLOB Server for Drift Protocol v2</h1>
|
||||
|
||||
<p>
|
||||
<a href="https://docs.drift.trade/tutorial-keeper-bots"><img alt="Docs" src="https://img.shields.io/badge/docs-tutorials-blueviolet" /></a>
|
||||
@@ -10,63 +10,77 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
# Run the example client
|
||||
# DLOB Server
|
||||
|
||||
Modify the variables at the top of `example/client.ts` to match your environment.
|
||||
|
||||
```shell
|
||||
yarn run example
|
||||
This is the backend server that provides a REST API for the drift [DLOB](https://docs.drift.trade/about-v2/decentralized-orderbook).
|
||||
|
||||
dlob orders count: 38
|
||||
maxSlot from DLOB init orders: 165107666
|
||||
Initialized DLOb from server
|
||||
DLOB for market 0:
|
||||
Asks
|
||||
[13] limit 21
|
||||
[12] limit 20.32
|
||||
[11] limit 17.73
|
||||
[10] limit 15.63
|
||||
[9] limit 15.32
|
||||
[8] limit 14.35
|
||||
[7] limit 14.32
|
||||
[6] limit 14.3
|
||||
[5] limit 14.23
|
||||
[4] limit 14.2
|
||||
[3] vAMMNode 13.896583
|
||||
[2] limit 13.896194
|
||||
[1] triggerMarket 0
|
||||
Bids
|
||||
[0] limit 13.879792
|
||||
[1] vAMMNode 13.771213
|
||||
[2] limit 13.37
|
||||
[3] limit 13
|
||||
[4] limit 13
|
||||
[5] limit 12.45
|
||||
[6] limit 12
|
||||
[7] limit 10.37
|
||||
[8] limit 10
|
||||
[9] limit 9.97
|
||||
[10] limit 9.42
|
||||
[11] limit 9
|
||||
[12] limit 8.89
|
||||
[13] limit 8
|
||||
```
|
||||
# Run the server
|
||||
|
||||
# Setting up
|
||||
## Setup Environment
|
||||
## Setup
|
||||
|
||||
|
||||
```shell
|
||||
First set the necessary environment variables:
|
||||
```
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Update values in `.env` accordingly
|
||||
|
||||
* `ANCHOR_PRIVATE_KEY`: can be a number array (as in example), or a path to a `keypair.json` as generated by `solana-keygen`, it needs to be an initialized user in order to load `DriftClient`.
|
||||
* `ENV` should be a drift env: `devnet` or `mainnet-beta`
|
||||
## Environment Configuration
|
||||
|
||||
## Run
|
||||
To properly configure the DLOB server, set the following environment variables in your `.env` file:
|
||||
|
||||
```shell
|
||||
| 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](https://drift-labs.github.io/v2-teacher/?python#orderbook-trades-dlob-server) 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](https://drift-labs.github.io/v2-teacher/?python#orderbook-trades-dlob-server)
|
||||
|
||||
TODO: complete client examples.
|
||||
Reference in New Issue
Block a user