@drift-labs/sdk 2.52.0-beta.3 → 2.52.0-beta.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.52.0-beta.3
1
+ 2.52.0-beta.4
@@ -1,5 +1,5 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
- import { PRICE_PRECISION, PhoenixSubscriber } from '../src';
2
+ import { BASE_PRECISION, PRICE_PRECISION, PhoenixSubscriber } from '../src';
3
3
  import { PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
4
4
 
5
5
  export async function listenToBook(): Promise<void> {
@@ -19,9 +19,16 @@ export async function listenToBook(): Promise<void> {
19
19
  await phoenixSubscriber.subscribe();
20
20
 
21
21
  for (let i = 0; i < 10; i++) {
22
- const bid = phoenixSubscriber.getBestBid().toNumber() / PRICE_PRECISION;
23
- const ask = phoenixSubscriber.getBestAsk().toNumber() / PRICE_PRECISION;
24
- console.log(`iter ${i}:`, bid.toFixed(3), '@', ask.toFixed(3));
22
+ const bids = phoenixSubscriber.getL2Levels("bids");
23
+ const asks = phoenixSubscriber.getL2Levels("asks");
24
+ console.log("bids");
25
+ for (const bid of bids) {
26
+ console.log(bid.price.toNumber() / PRICE_PRECISION.toNumber(), bid.size.toNumber() / BASE_PRECISION.toNumber());
27
+ }
28
+ console.log("asks");
29
+ for (const ask of asks) {
30
+ console.log(ask.price.toNumber() / PRICE_PRECISION.toNumber(), ask.size.toNumber() / BASE_PRECISION.toNumber());
31
+ }
25
32
  await new Promise((r) => setTimeout(r, 2000));
26
33
  }
27
34
 
@@ -99,14 +99,18 @@ class PhoenixSubscriber {
99
99
  return this.getL2Levels('asks');
100
100
  }
101
101
  *getL2Levels(side) {
102
- const basePrecision = Math.pow(10, this.market.data.header.baseParams.decimals);
103
- const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
104
- const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
102
+ const tickSize = this.market.data.header
103
+ .tickSizeInQuoteAtomsPerBaseUnit;
104
+ const baseLotsToRawBaseUnits = this.market.baseLotsToRawBaseUnits(1);
105
+ const basePrecision = new anchor_1.BN(Math.pow(10, this.market.data.header.baseParams.decimals) *
106
+ baseLotsToRawBaseUnits);
107
+ const pricePrecision = numericConstants_1.PRICE_PRECISION.div(tickSize);
108
+ const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
105
109
  for (let i = 0; i < ladder[side].length; i++) {
106
- const { price, quantity } = ladder[side][i];
107
- const size = new anchor_1.BN(quantity).mul(new anchor_1.BN(basePrecision));
110
+ const { priceInTicks, sizeInBaseLots } = ladder[side][i];
111
+ const size = sizeInBaseLots.mul(basePrecision);
108
112
  yield {
109
- price: new anchor_1.BN(price).mul(new anchor_1.BN(pricePrecision)),
113
+ price: priceInTicks.mul(new anchor_1.BN(pricePrecision)),
110
114
  size,
111
115
  sources: {
112
116
  phoenix: size,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.52.0-beta.3",
3
+ "version": "2.52.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -6,6 +6,7 @@ import {
6
6
  toNum,
7
7
  getMarketUiLadder,
8
8
  Market,
9
+ getMarketLadder,
9
10
  } from '@ellipsis-labs/phoenix-sdk';
10
11
  import { PRICE_PRECISION } from '../constants/numericConstants';
11
12
  import { BN } from '@coral-xyz/anchor';
@@ -163,13 +164,18 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
163
164
  }
164
165
 
165
166
  *getL2Levels(side: 'bids' | 'asks'): Generator<L2Level> {
166
- const basePrecision = Math.pow(
167
- 10,
168
- this.market.data.header.baseParams.decimals
167
+ const tickSize = this.market.data.header
168
+ .tickSizeInQuoteAtomsPerBaseUnit as BN;
169
+ const baseLotsToRawBaseUnits = this.market.baseLotsToRawBaseUnits(1);
170
+
171
+ const basePrecision = new BN(
172
+ Math.pow(10, this.market.data.header.baseParams.decimals) *
173
+ baseLotsToRawBaseUnits
169
174
  );
170
- const pricePrecision = PRICE_PRECISION.toNumber();
171
175
 
172
- const ladder = getMarketUiLadder(
176
+ const pricePrecision = PRICE_PRECISION.div(tickSize as BN);
177
+
178
+ const ladder = getMarketLadder(
173
179
  this.market,
174
180
  this.lastSlot,
175
181
  this.lastUnixTimestamp,
@@ -177,10 +183,10 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
177
183
  );
178
184
 
179
185
  for (let i = 0; i < ladder[side].length; i++) {
180
- const { price, quantity } = ladder[side][i];
181
- const size = new BN(quantity).mul(new BN(basePrecision));
186
+ const { priceInTicks, sizeInBaseLots } = ladder[side][i];
187
+ const size = sizeInBaseLots.mul(basePrecision);
182
188
  yield {
183
- price: new BN(price).mul(new BN(pricePrecision)),
189
+ price: priceInTicks.mul(new BN(pricePrecision)),
184
190
  size,
185
191
  sources: {
186
192
  phoenix: size,