3
3
Self hosted API gateway to easily interact with Drift V2 Protocol
4
4
5
5
## Table of Contents
6
-
7
- 1 . [ Introduction ] ( #introduction )
8
- 2 . [ Installation ] ( #installation )
9
- 3 . [ Usage] ( #usage )
10
- - [ Delegated Signing Mode ] ( #delegated-signing-mode )
11
- - [ Sub-account Switching ] ( #sub-account-switching )
12
- 4 . [ API Examples ] ( #api-examples )
13
- - [ HTTP API] ( #http- api )
14
- - [ ` GET ` Markets ] ( #get-markets )
15
- - [ ` GET ` MarketInfo ] ( #get-market-info )
16
- - [ ` GET ` Orderbook] ( #get-orderbook )
17
- - [ ` GET ` Orders] ( #get-orders )
18
- - [ ` GET ` Positions] ( #get-positions )
19
- - [ ` GET ` Perp Position Info] ( #get-position-info-perps-only )
20
- - [ ` GET ` Transaction Events] ( #get-transaction-events )
21
- - [ ` GET ` SOL Balance] ( #get-sol-balance )
22
- - [ ` POST ` Place Orders] ( #place-orders )
23
- - [ ` PATCH ` Modify Orders] ( #modify-orders )
24
- - [ ` DELETE ` Cancel Orders] ( #cancel-orders )
25
- - [ ` PUT ` Atomic Cancel/Modify/Place Orders] ( #atomic-cancelmodifyplace-orders )
26
- - [ Websocket API] ( #websocket-api )
27
- - [ Subscribing] ( #subscribing )
28
- - [ Event Payloads] ( #event-payloads )
6
+ 1 . [ Build & Run ] ( #build--run )
7
+ - [ From Source ] ( #from-source )
8
+ - [ From Docker ] ( #from-docker )
9
+ 2 . [ Usage] ( #usage )
10
+ - [ Environment Variables ] ( #environment-variables )
11
+ - [ Delegated Signing Mode ] ( #delegated-signing-mode )
12
+ - [ Sub-account Switching ] ( #sub-account-switching )
13
+ 3 . [ API Examples ] ( #api-examples )
14
+ - [ HTTP API ] ( #http-api )
15
+ - [ ` GET ` Market Info ] ( #get-market-info )
16
+ - [ ` GET ` Orderbook] ( #get-orderbook )
17
+ - [ ` GET ` Orders] ( #get-orders )
18
+ - [ ` GET ` Positions] ( #get-positions )
19
+ - [ ` GET ` Perp Position Info] ( #get-position-info-perps-only )
20
+ - [ ` GET ` Transaction Events] ( #get-transaction-events )
21
+ - [ ` GET ` SOL Balance] ( #get-sol-balance )
22
+ - [ ` POST ` Place Orders] ( #place-orders )
23
+ - [ ` PATCH ` Modify Orders] ( #modify-orders )
24
+ - [ ` DELETE ` Cancel Orders] ( #cancel-orders )
25
+ - [ ` PUT ` Atomic Cancel/Modify/Place Orders] ( #atomic-cancelmodifyplace-orders )
26
+ - [ Websocket API] ( #websocket-api )
27
+ - [ Subscribing] ( #subscribing )
28
+ - [ Event Payloads] ( #event-payloads )
29
29
30
30
## Build & Run
31
31
32
32
⚠️ Before starting, ensure a Drift _ user_ account is initialized e.g. via the drift app at https://beta.drift.trade (devnet) or https://app.drift.trade
33
33
34
+ ### From Source
35
+
36
+ Build:
37
+
34
38
supports rust <= 1.76.0
35
39
36
40
``` bash
37
- # build
41
+ # make a release build from source
38
42
cargo build --release
43
+ ```
44
+
45
+ Run:
39
46
47
+ ``` bash
40
48
# configure the gateway signing key
41
49
export DRIFT_GATEWAY_KEY=< /PATH/TO/KEY.json | seedBase58>
42
50
@@ -49,15 +57,32 @@ drift-gateway --dev https://api.devnet.solana.com
49
57
drift-gateway https://rpc-provider.example.com
50
58
```
51
59
52
- with docker
60
+ ### From Docker
61
+
62
+ Build the Docker image:
53
63
54
64
``` bash
55
65
docker build -f Dockerfile . -t drift-gateway
66
+ ```
67
+
68
+ Run the image:
69
+
70
+ ``` bash
56
71
docker run -e DRIFT_GATEWAY_KEY=< BASE58_SEED> -p 8080:8080 drift-gateway https://api.mainnet-beta.solana.com --host 0.0.0.0
57
72
```
58
73
59
74
## Usage
60
75
76
+ ⚠️ Before starting, ensure a Drift _ user_ account is initialized e.g. via the drift app at https://beta.drift.trade (devnet) or https://app.drift.trade
77
+
78
+ ### Environment Variables
79
+
80
+ These runtime environment variables are required:
81
+
82
+ | Variable | Description | Example Value |
83
+ | ---------------------| -------------------------------------------| ------------------------------|
84
+ | ` DRIFT_GATEWAY_KEY ` | Path to your key file or seed in Base58. Transactions will be signed with this keypair | ` </PATH/TO/KEY.json> ` or ` seedBase58 ` |
85
+
61
86
``` bash
62
87
Usage: drift-gateway < rpc_host> [--dev] [--host < host> ] [--port < port> ] [--delegate < delegate> ] [--emulate < emulate> ]
63
88
@@ -332,7 +357,7 @@ get extended position info for perps positions
332
357
$ curl localhost:8080/v2/positionInfo/0
333
358
```
334
359
335
- note:
360
+ note:
336
361
- ` unrealizedPnL ` is based on the oracle price at time of query
337
362
- ` unsettledPnl ` does not include unsettled funding amounts
338
363
@@ -403,9 +428,7 @@ A response for a transaction that was found, but doesn't contain any events for
403
428
```
404
429
405
430
### Get SOL balance
406
-
407
- Return the SOL balance of the transaction signer
408
-
431
+ Return the on-chain SOL balance of the transaction signer (` DRIFT_GATEWAY_KEY ` )
409
432
``` bash
410
433
$ curl localhost:8080/v2/balance
411
434
```
0 commit comments