@drift-labs/sdk 2.30.0-beta.0 → 2.30.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dlob_read.ts DELETED
@@ -1,155 +0,0 @@
1
- import { Connection, Keypair, PublicKey } from '@solana/web3.js';
2
- import {
3
- BASE_PRECISION,
4
- BulkAccountLoader,
5
- configs,
6
- convertToNumber,
7
- DLOBSubscriber,
8
- DriftClient,
9
- getMarketsAndOraclesForSubscription,
10
- MarketType,
11
- PRICE_PRECISION,
12
- SlotSubscriber,
13
- UserMap,
14
- Wallet,
15
- } from './src/index';
16
- import {
17
- DLOBApiClient,
18
- } from './src/dlob/DLOBApiClient';
19
-
20
- async function main() {
21
-
22
- const driftConfig = configs['mainnet-beta'];
23
- const connection = new Connection('https://api.mainnet-beta.solana.com');
24
-
25
- const accountLoader = new BulkAccountLoader(
26
- connection,
27
- 'confirmed',
28
- 10000
29
- );
30
-
31
- const { perpMarketIndexes, spotMarketIndexes, oracleInfos } = getMarketsAndOraclesForSubscription('mainnet-beta');
32
-
33
-
34
- const driftClient = new DriftClient({
35
- connection: connection,
36
- wallet: new Wallet(new Keypair()),
37
- programID: new PublicKey(driftConfig.DRIFT_PROGRAM_ID),
38
- accountSubscription: {
39
- type: 'polling',
40
- accountLoader: accountLoader,
41
- },
42
- perpMarketIndexes,
43
- spotMarketIndexes,
44
- oracleInfos,
45
- userStats: true,
46
- env: 'mainnet-beta',
47
- });
48
- console.log(`driftClientSubscribed: ${await driftClient.subscribe()}`);
49
-
50
- const slotSubscriber = new SlotSubscriber(connection);
51
- await slotSubscriber.subscribe();
52
-
53
-
54
- // Alternatively, you can also use the UserMap class, which loads the DLOB via RPC calls.
55
- // const userMap = new UserMap(driftClient, driftClient.userAccountSubscriptionConfig, false);
56
-
57
- // This loads the DLOB from a server hosted by Drift.
58
- const dlobAPI = new DLOBApiClient({
59
- url: 'https://dlob.drift.trade/orders/idlWithSlot',
60
- });
61
-
62
- const dlobSubscriber = new DLOBSubscriber({
63
- dlobSource: dlobAPI,
64
- slotSource: slotSubscriber,
65
- driftClient: driftClient,
66
- updateFrequency: 10000,
67
- });
68
- await dlobSubscriber.subscribe();
69
-
70
- const l2 = dlobSubscriber.getL2({
71
- marketIndex: 0,
72
- marketType: MarketType.PERP,
73
- });
74
- console.log("Level 2 order book:");
75
-
76
- console.log("Asks:");
77
- const asks = l2.asks.slice().reverse();
78
- for (let i = 0; i < asks.length; i++) {
79
- const ask = asks[i];
80
- console.log(` [${asks.length - i - 1}] ${convertToNumber(ask.size, BASE_PRECISION)} @ $${convertToNumber(ask.price, PRICE_PRECISION)}`);
81
- }
82
-
83
- console.log("Bids:");
84
- const bids = l2.bids;
85
- for (let i = 0; i < bids.length; i++) {
86
- const bid = bids[i];
87
- console.log(` [${i}] ${convertToNumber(bid.size, BASE_PRECISION)} @ $${convertToNumber(bid.price, PRICE_PRECISION)}`);
88
- }
89
- console.log("");
90
- console.log("");
91
-
92
- /**
93
- Level 2 order book:
94
- Asks:
95
- [9] 664.8 @ $21.3248
96
- [8] 3.5 @ $21.288301
97
- [7] 3.5 @ $21.287237
98
- [6] 3.5 @ $21.283129
99
- [5] 0.1 @ $21.2825
100
- [4] 1937.6 @ $21.2748
101
- [3] 1 @ $21.26
102
- [2] 2015 @ $21.2589
103
- [1] 503.7 @ $21.2483
104
- [0] 377.8 @ $21.243
105
- Bids:
106
- [0] 1168.2 @ $21.2464
107
- [1] 136.7 @ $21.2461
108
- [2] 2570.2 @ $21.2426
109
- [3] 0.1 @ $21.2419
110
- [4] 47 @ $21.216188
111
- [5] 327.8 @ $21.211
112
- [6] 437 @ $21.2057
113
- [7] 47 @ $21.205592
114
- [8] 1748.3 @ $21.1951
115
- [9] 187 @ $21.1792
116
- */
117
-
118
- const l3 = dlobSubscriber.getL3({
119
- marketIndex: 0,
120
- marketType: MarketType.PERP,
121
- });
122
-
123
- console.log("Level 3 order book:");
124
- console.log("Asks:");
125
- const l3asks = l3.asks.slice().reverse();
126
- for (let i = 0; i < l3asks.length; i++) {
127
- const ask = l3asks[i];
128
- console.log(` [${l3asks.length - i - 1}] ${ask.maker.toBase58()} ${convertToNumber(ask.size, BASE_PRECISION)} @ $${convertToNumber(ask.price, PRICE_PRECISION)}`);
129
- }
130
-
131
- console.log("Bids:");
132
- const l3bids = l3.bids;
133
- for (let i = 0; i < l3bids.length; i++) {
134
- const bid = l3bids[i];
135
- console.log(` [${i}] ${bid.maker.toBase58()} ${convertToNumber(bid.size, BASE_PRECISION)} @ $${convertToNumber(bid.price, PRICE_PRECISION)}`);
136
- }
137
-
138
- /**
139
- Level 3 order book:
140
- Asks:
141
- ...
142
- [3] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 1 @ $21.26
143
- [2] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 2015 @ $21.2589
144
- [1] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 503.7 @ $21.2483
145
- [0] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 377.8 @ $21.243
146
- Bids:
147
- [0] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 1168.2 @ $21.2464
148
- [1] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 2570.2 @ $21.2464
149
- [2] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 136.7 @ $21.2461
150
- [3] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 2570.2 @ $21.2426
151
- ...
152
- */
153
- }
154
-
155
- main().catch(console.error);