diff --git a/README.md b/README.md index a08103b..26716f0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
-# 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. \ No newline at end of file diff --git a/package.json b/package.json index f7afbd0..5c84f3f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.29.0", - "@drift-labs/sdk": "2.64.0-beta.0", + "@drift-labs/sdk": "2.64.0-beta.1", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/yarn.lock b/yarn.lock index 913dfcb..b0a93cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,10 +115,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.64.0-beta.0": - version "2.64.0-beta.0" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.64.0-beta.0.tgz#819ca499a7341b056f551edd7b7afc3e3615f7cb" - integrity sha512-BmuCoAKK3FzMdJ+jgdXLzwb/X6rwc6wGBC9vO6iILHD/bOdMTI+zEpoWHlCdGDXee4qGGrmCJcTpOLn7xdMExA== +"@drift-labs/sdk@2.64.0-beta.1": + version "2.64.0-beta.1" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.64.0-beta.1.tgz#b1cf6263d7acaea32ef2c2dcb937417e211797f2" + integrity sha512-uzM1cKpMyk16eyKRSJiBn3Ru2qoGoGPtbmYxu45WnAYDb/0wxFwIjQPhZIX2pn4kAHtQwxSaV+hfMKeFNU9FbA== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2"