@drift-labs/sdk 2.115.0-beta.5 → 2.115.0-beta.7
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 +1 -1
- package/lib/browser/driftClient.js +2 -2
- package/lib/browser/openbook/openbookV2Subscriber.d.ts +2 -0
- package/lib/browser/openbook/openbookV2Subscriber.js +16 -6
- package/lib/browser/phoenix/phoenixSubscriber.d.ts +2 -0
- package/lib/browser/phoenix/phoenixSubscriber.js +19 -10
- package/lib/node/driftClient.js +2 -2
- package/lib/node/openbook/openbookV2Subscriber.d.ts +2 -0
- package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
- package/lib/node/openbook/openbookV2Subscriber.js +16 -6
- package/lib/node/phoenix/phoenixSubscriber.d.ts +2 -0
- package/lib/node/phoenix/phoenixSubscriber.d.ts.map +1 -1
- package/lib/node/phoenix/phoenixSubscriber.js +19 -10
- package/package.json +1 -1
- package/src/driftClient.ts +2 -2
- package/src/openbook/openbookV2Subscriber.ts +20 -10
- package/src/phoenix/phoenixSubscriber.ts +28 -16
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.115.0-beta.
|
|
1
|
+
2.115.0-beta.7
|
|
@@ -3418,7 +3418,7 @@ class DriftClient {
|
|
|
3418
3418
|
async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex) {
|
|
3419
3419
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3420
3420
|
userAccounts: [takerInfo.takerUserAccount],
|
|
3421
|
-
useMarketLastSlotCache:
|
|
3421
|
+
useMarketLastSlotCache: false,
|
|
3422
3422
|
readablePerpMarketIndex: marketIndex,
|
|
3423
3423
|
});
|
|
3424
3424
|
const messageLengthBuffer = Buffer.alloc(2);
|
|
@@ -3460,7 +3460,7 @@ class DriftClient {
|
|
|
3460
3460
|
this.getUserAccount(subAccountId),
|
|
3461
3461
|
takerInfo.takerUserAccount,
|
|
3462
3462
|
],
|
|
3463
|
-
useMarketLastSlotCache:
|
|
3463
|
+
useMarketLastSlotCache: false,
|
|
3464
3464
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
3465
3465
|
});
|
|
3466
3466
|
if (referrerInfo) {
|
|
@@ -31,6 +31,8 @@ export declare class OpenbookV2Subscriber implements L2OrderBookGenerator {
|
|
|
31
31
|
getBestAsk(): BN | undefined;
|
|
32
32
|
getL2Bids(): Generator<L2Level>;
|
|
33
33
|
getL2Asks(): Generator<L2Level>;
|
|
34
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInLots: BN): BN;
|
|
35
|
+
convertPriceInLotsToPricePrecision(priceInLots: BN): BN;
|
|
34
36
|
getL2Levels(side: 'bids' | 'asks'): Generator<L2Level>;
|
|
35
37
|
unsubscribe(): Promise<void>;
|
|
36
38
|
}
|
|
@@ -56,7 +56,7 @@ class OpenbookV2Subscriber {
|
|
|
56
56
|
if (bestBid === undefined) {
|
|
57
57
|
return undefined;
|
|
58
58
|
}
|
|
59
|
-
return
|
|
59
|
+
return this.convertPriceInLotsToPricePrecision(bestBid.priceLots);
|
|
60
60
|
}
|
|
61
61
|
getBestAsk() {
|
|
62
62
|
var _a;
|
|
@@ -64,7 +64,7 @@ class OpenbookV2Subscriber {
|
|
|
64
64
|
if (bestAsk === undefined) {
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return this.convertPriceInLotsToPricePrecision(bestAsk.priceLots);
|
|
68
68
|
}
|
|
69
69
|
getL2Bids() {
|
|
70
70
|
return this.getL2Levels('bids');
|
|
@@ -72,13 +72,23 @@ class OpenbookV2Subscriber {
|
|
|
72
72
|
getL2Asks() {
|
|
73
73
|
return this.getL2Levels('asks');
|
|
74
74
|
}
|
|
75
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInLots) {
|
|
76
|
+
return sizeInLots.mul(this.market.account.baseLotSize);
|
|
77
|
+
}
|
|
78
|
+
convertPriceInLotsToPricePrecision(priceInLots) {
|
|
79
|
+
const adjPrice = priceInLots
|
|
80
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
81
|
+
.muln(10 **
|
|
82
|
+
(this.market.account.baseDecimals - this.market.account.quoteDecimals))
|
|
83
|
+
.mul(this.market.account.quoteLotSize)
|
|
84
|
+
.div(this.market.account.baseLotSize);
|
|
85
|
+
return adjPrice;
|
|
86
|
+
}
|
|
75
87
|
*getL2Levels(side) {
|
|
76
|
-
const basePrecision = Math.ceil(1 / this.market.baseNativeFactor.toNumber());
|
|
77
|
-
const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
|
|
78
88
|
const levels = side === 'bids' ? this.market.bids : this.market.asks;
|
|
79
89
|
for (const order of levels === null || levels === void 0 ? void 0 : levels.items()) {
|
|
80
|
-
const size =
|
|
81
|
-
const price =
|
|
90
|
+
const size = this.convertSizeInBaseLotsToMarketPrecision(order.sizeLots);
|
|
91
|
+
const price = this.convertPriceInLotsToPricePrecision(order.priceLots);
|
|
82
92
|
yield {
|
|
83
93
|
price,
|
|
84
94
|
size,
|
|
@@ -34,6 +34,8 @@ export declare class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
34
34
|
subscribe(): Promise<void>;
|
|
35
35
|
getBestBid(): BN | undefined;
|
|
36
36
|
getBestAsk(): BN | undefined;
|
|
37
|
+
convertPriceInTicksToPricePrecision(priceInTicks: BN): BN;
|
|
38
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots: BN): BN;
|
|
37
39
|
getL2Bids(): Generator<L2Level>;
|
|
38
40
|
getL2Asks(): Generator<L2Level>;
|
|
39
41
|
getL2Levels(side: 'bids' | 'asks'): Generator<L2Level>;
|
|
@@ -90,20 +90,31 @@ class PhoenixSubscriber {
|
|
|
90
90
|
this.subscribed = true;
|
|
91
91
|
}
|
|
92
92
|
getBestBid() {
|
|
93
|
-
const ladder = (0, phoenix_sdk_1.
|
|
93
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
94
94
|
const bestBid = ladder.bids[0];
|
|
95
95
|
if (!bestBid) {
|
|
96
96
|
return undefined;
|
|
97
97
|
}
|
|
98
|
-
return
|
|
98
|
+
return this.convertPriceInTicksToPricePrecision(bestBid.priceInTicks);
|
|
99
99
|
}
|
|
100
100
|
getBestAsk() {
|
|
101
|
-
const ladder = (0, phoenix_sdk_1.
|
|
101
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
102
102
|
const bestAsk = ladder.asks[0];
|
|
103
103
|
if (!bestAsk) {
|
|
104
104
|
return undefined;
|
|
105
105
|
}
|
|
106
|
-
return
|
|
106
|
+
return this.convertPriceInTicksToPricePrecision(bestAsk.priceInTicks);
|
|
107
|
+
}
|
|
108
|
+
convertPriceInTicksToPricePrecision(priceInTicks) {
|
|
109
|
+
const quotePrecision = new anchor_1.BN(Math.pow(10, this.market.data.header.quoteParams.decimals));
|
|
110
|
+
const denom = quotePrecision.muln(this.market.data.header.rawBaseUnitsPerBaseUnit);
|
|
111
|
+
const price = priceInTicks
|
|
112
|
+
.muln(this.market.data.quoteLotsPerBaseUnitPerTick)
|
|
113
|
+
.muln((0, phoenix_sdk_1.toNum)(this.market.data.header.quoteLotSize));
|
|
114
|
+
return price.mul(numericConstants_1.PRICE_PRECISION).div(denom);
|
|
115
|
+
}
|
|
116
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots) {
|
|
117
|
+
return sizeInBaseLots.muln((0, phoenix_sdk_1.toNum)(this.market.data.header.baseLotSize));
|
|
107
118
|
}
|
|
108
119
|
getL2Bids() {
|
|
109
120
|
return this.getL2Levels('bids');
|
|
@@ -112,14 +123,12 @@ class PhoenixSubscriber {
|
|
|
112
123
|
return this.getL2Levels('asks');
|
|
113
124
|
}
|
|
114
125
|
*getL2Levels(side) {
|
|
115
|
-
const
|
|
116
|
-
const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
|
|
117
|
-
const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
|
|
126
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
|
|
118
127
|
for (let i = 0; i < ladder[side].length; i++) {
|
|
119
|
-
const {
|
|
128
|
+
const { priceInTicks, sizeInBaseLots } = ladder[side][i];
|
|
120
129
|
try {
|
|
121
|
-
const size =
|
|
122
|
-
const updatedPrice =
|
|
130
|
+
const size = this.convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots);
|
|
131
|
+
const updatedPrice = this.convertPriceInTicksToPricePrecision(priceInTicks);
|
|
123
132
|
yield {
|
|
124
133
|
price: updatedPrice,
|
|
125
134
|
size,
|
package/lib/node/driftClient.js
CHANGED
|
@@ -3418,7 +3418,7 @@ class DriftClient {
|
|
|
3418
3418
|
async getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, marketIndex, takerInfo, precedingIxs = [], overrideCustomIxIndex) {
|
|
3419
3419
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3420
3420
|
userAccounts: [takerInfo.takerUserAccount],
|
|
3421
|
-
useMarketLastSlotCache:
|
|
3421
|
+
useMarketLastSlotCache: false,
|
|
3422
3422
|
readablePerpMarketIndex: marketIndex,
|
|
3423
3423
|
});
|
|
3424
3424
|
const messageLengthBuffer = Buffer.alloc(2);
|
|
@@ -3460,7 +3460,7 @@ class DriftClient {
|
|
|
3460
3460
|
this.getUserAccount(subAccountId),
|
|
3461
3461
|
takerInfo.takerUserAccount,
|
|
3462
3462
|
],
|
|
3463
|
-
useMarketLastSlotCache:
|
|
3463
|
+
useMarketLastSlotCache: false,
|
|
3464
3464
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
3465
3465
|
});
|
|
3466
3466
|
if (referrerInfo) {
|
|
@@ -31,6 +31,8 @@ export declare class OpenbookV2Subscriber implements L2OrderBookGenerator {
|
|
|
31
31
|
getBestAsk(): BN | undefined;
|
|
32
32
|
getL2Bids(): Generator<L2Level>;
|
|
33
33
|
getL2Asks(): Generator<L2Level>;
|
|
34
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInLots: BN): BN;
|
|
35
|
+
convertPriceInLotsToPricePrecision(priceInLots: BN): BN;
|
|
34
36
|
getL2Levels(side: 'bids' | 'asks'): Generator<L2Level>;
|
|
35
37
|
unsubscribe(): Promise<void>;
|
|
36
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openbookV2Subscriber.d.ts","sourceRoot":"","sources":["../../../src/openbook/openbookV2Subscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAkB,EAAE,EAAwB,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,MAAM,MAAM,0BAA0B,GAAG;IACxC,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,mBAAmB,EAChB;QAEA,IAAI,EAAE,SAAS,CAAC;QAChB,aAAa,EAAE,iBAAiB,CAAC;KAChC,GACD;QACA,IAAI,EAAE,WAAW,CAAC;KACjB,CAAC;CACL,CAAC;AAEF,qBAAa,oBAAqB,YAAW,oBAAoB;IAChE,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,gBAAgB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC1C,aAAa,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC;gBAEN,MAAM,EAAE,0BAA0B;IAaxC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAkDhC,UAAU,IAAI,EAAE,GAAG,SAAS;IAU5B,UAAU,IAAI,EAAE,GAAG,SAAS;IAU5B,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;IAI/B,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"openbookV2Subscriber.d.ts","sourceRoot":"","sources":["../../../src/openbook/openbookV2Subscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAkB,EAAE,EAAwB,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,MAAM,MAAM,0BAA0B,GAAG;IACxC,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,mBAAmB,EAChB;QAEA,IAAI,EAAE,SAAS,CAAC;QAChB,aAAa,EAAE,iBAAiB,CAAC;KAChC,GACD;QACA,IAAI,EAAE,WAAW,CAAC;KACjB,CAAC;CACL,CAAC;AAEF,qBAAa,oBAAqB,YAAW,oBAAoB;IAChE,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,gBAAgB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC1C,aAAa,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC;gBAEN,MAAM,EAAE,0BAA0B;IAaxC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAkDhC,UAAU,IAAI,EAAE,GAAG,SAAS;IAU5B,UAAU,IAAI,EAAE,GAAG,SAAS;IAU5B,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;IAI/B,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;IAI/B,sCAAsC,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE;IAI1D,kCAAkC,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE;IAY7D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;IAe1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAkBzC"}
|
|
@@ -56,7 +56,7 @@ class OpenbookV2Subscriber {
|
|
|
56
56
|
if (bestBid === undefined) {
|
|
57
57
|
return undefined;
|
|
58
58
|
}
|
|
59
|
-
return
|
|
59
|
+
return this.convertPriceInLotsToPricePrecision(bestBid.priceLots);
|
|
60
60
|
}
|
|
61
61
|
getBestAsk() {
|
|
62
62
|
var _a;
|
|
@@ -64,7 +64,7 @@ class OpenbookV2Subscriber {
|
|
|
64
64
|
if (bestAsk === undefined) {
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return this.convertPriceInLotsToPricePrecision(bestAsk.priceLots);
|
|
68
68
|
}
|
|
69
69
|
getL2Bids() {
|
|
70
70
|
return this.getL2Levels('bids');
|
|
@@ -72,13 +72,23 @@ class OpenbookV2Subscriber {
|
|
|
72
72
|
getL2Asks() {
|
|
73
73
|
return this.getL2Levels('asks');
|
|
74
74
|
}
|
|
75
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInLots) {
|
|
76
|
+
return sizeInLots.mul(this.market.account.baseLotSize);
|
|
77
|
+
}
|
|
78
|
+
convertPriceInLotsToPricePrecision(priceInLots) {
|
|
79
|
+
const adjPrice = priceInLots
|
|
80
|
+
.mul(numericConstants_1.PRICE_PRECISION)
|
|
81
|
+
.muln(10 **
|
|
82
|
+
(this.market.account.baseDecimals - this.market.account.quoteDecimals))
|
|
83
|
+
.mul(this.market.account.quoteLotSize)
|
|
84
|
+
.div(this.market.account.baseLotSize);
|
|
85
|
+
return adjPrice;
|
|
86
|
+
}
|
|
75
87
|
*getL2Levels(side) {
|
|
76
|
-
const basePrecision = Math.ceil(1 / this.market.baseNativeFactor.toNumber());
|
|
77
|
-
const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
|
|
78
88
|
const levels = side === 'bids' ? this.market.bids : this.market.asks;
|
|
79
89
|
for (const order of levels === null || levels === void 0 ? void 0 : levels.items()) {
|
|
80
|
-
const size =
|
|
81
|
-
const price =
|
|
90
|
+
const size = this.convertSizeInBaseLotsToMarketPrecision(order.sizeLots);
|
|
91
|
+
const price = this.convertPriceInLotsToPricePrecision(order.priceLots);
|
|
82
92
|
yield {
|
|
83
93
|
price,
|
|
84
94
|
size,
|
|
@@ -34,6 +34,8 @@ export declare class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
34
34
|
subscribe(): Promise<void>;
|
|
35
35
|
getBestBid(): BN | undefined;
|
|
36
36
|
getBestAsk(): BN | undefined;
|
|
37
|
+
convertPriceInTicksToPricePrecision(priceInTicks: BN): BN;
|
|
38
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots: BN): BN;
|
|
37
39
|
getL2Bids(): Generator<L2Level>;
|
|
38
40
|
getL2Asks(): Generator<L2Level>;
|
|
39
41
|
getL2Levels(side: 'bids' | 'asks'): Generator<L2Level>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoenixSubscriber.d.ts","sourceRoot":"","sources":["../../../src/phoenix/phoenixSubscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAuB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACN,MAAM,
|
|
1
|
+
{"version":3,"file":"phoenixSubscriber.d.ts","sourceRoot":"","sources":["../../../src/phoenix/phoenixSubscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAuB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACN,MAAM,EAGN,MAAM,EAEN,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAGxE,MAAM,MAAM,6BAA6B,GAAG;IAC3C,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,mBAAmB,EAChB;QAEA,IAAI,EAAE,SAAS,CAAC;QAChB,aAAa,EAAE,iBAAiB,CAAC;KAChC,GACD;QACA,IAAI,EAAE,WAAW,CAAC;KACjB,CAAC;IACL,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,qBAAa,iBAAkB,YAAW,oBAAoB;IAC7D,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,gBAAgB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC1C,aAAa,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;IAEjC,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;gBAEP,MAAM,EAAE,6BAA6B;IAe3C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA8EhC,UAAU,IAAI,EAAE,GAAG,SAAS;IAc5B,UAAU,IAAI,EAAE,GAAG,SAAS;IAe5B,mCAAmC,CAAC,YAAY,EAAE,EAAE,GAAG,EAAE;IAazD,sCAAsC,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE;IAI9D,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;IAI/B,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC;IAIrC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;IA2B1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CA0BzC"}
|
|
@@ -90,20 +90,31 @@ class PhoenixSubscriber {
|
|
|
90
90
|
this.subscribed = true;
|
|
91
91
|
}
|
|
92
92
|
getBestBid() {
|
|
93
|
-
const ladder = (0, phoenix_sdk_1.
|
|
93
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
94
94
|
const bestBid = ladder.bids[0];
|
|
95
95
|
if (!bestBid) {
|
|
96
96
|
return undefined;
|
|
97
97
|
}
|
|
98
|
-
return
|
|
98
|
+
return this.convertPriceInTicksToPricePrecision(bestBid.priceInTicks);
|
|
99
99
|
}
|
|
100
100
|
getBestAsk() {
|
|
101
|
-
const ladder = (0, phoenix_sdk_1.
|
|
101
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
|
|
102
102
|
const bestAsk = ladder.asks[0];
|
|
103
103
|
if (!bestAsk) {
|
|
104
104
|
return undefined;
|
|
105
105
|
}
|
|
106
|
-
return
|
|
106
|
+
return this.convertPriceInTicksToPricePrecision(bestAsk.priceInTicks);
|
|
107
|
+
}
|
|
108
|
+
convertPriceInTicksToPricePrecision(priceInTicks) {
|
|
109
|
+
const quotePrecision = new anchor_1.BN(Math.pow(10, this.market.data.header.quoteParams.decimals));
|
|
110
|
+
const denom = quotePrecision.muln(this.market.data.header.rawBaseUnitsPerBaseUnit);
|
|
111
|
+
const price = priceInTicks
|
|
112
|
+
.muln(this.market.data.quoteLotsPerBaseUnitPerTick)
|
|
113
|
+
.muln((0, phoenix_sdk_1.toNum)(this.market.data.header.quoteLotSize));
|
|
114
|
+
return price.mul(numericConstants_1.PRICE_PRECISION).div(denom);
|
|
115
|
+
}
|
|
116
|
+
convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots) {
|
|
117
|
+
return sizeInBaseLots.muln((0, phoenix_sdk_1.toNum)(this.market.data.header.baseLotSize));
|
|
107
118
|
}
|
|
108
119
|
getL2Bids() {
|
|
109
120
|
return this.getL2Levels('bids');
|
|
@@ -112,14 +123,12 @@ class PhoenixSubscriber {
|
|
|
112
123
|
return this.getL2Levels('asks');
|
|
113
124
|
}
|
|
114
125
|
*getL2Levels(side) {
|
|
115
|
-
const
|
|
116
|
-
const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
|
|
117
|
-
const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
|
|
126
|
+
const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
|
|
118
127
|
for (let i = 0; i < ladder[side].length; i++) {
|
|
119
|
-
const {
|
|
128
|
+
const { priceInTicks, sizeInBaseLots } = ladder[side][i];
|
|
120
129
|
try {
|
|
121
|
-
const size =
|
|
122
|
-
const updatedPrice =
|
|
130
|
+
const size = this.convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots);
|
|
131
|
+
const updatedPrice = this.convertPriceInTicksToPricePrecision(priceInTicks);
|
|
123
132
|
yield {
|
|
124
133
|
price: updatedPrice,
|
|
125
134
|
size,
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -6408,7 +6408,7 @@ export class DriftClient {
|
|
|
6408
6408
|
): Promise<TransactionInstruction[]> {
|
|
6409
6409
|
const remainingAccounts = this.getRemainingAccounts({
|
|
6410
6410
|
userAccounts: [takerInfo.takerUserAccount],
|
|
6411
|
-
useMarketLastSlotCache:
|
|
6411
|
+
useMarketLastSlotCache: false,
|
|
6412
6412
|
readablePerpMarketIndex: marketIndex,
|
|
6413
6413
|
});
|
|
6414
6414
|
|
|
@@ -6526,7 +6526,7 @@ export class DriftClient {
|
|
|
6526
6526
|
this.getUserAccount(subAccountId),
|
|
6527
6527
|
takerInfo.takerUserAccount,
|
|
6528
6528
|
],
|
|
6529
|
-
useMarketLastSlotCache:
|
|
6529
|
+
useMarketLastSlotCache: false,
|
|
6530
6530
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
6531
6531
|
});
|
|
6532
6532
|
|
|
@@ -102,7 +102,7 @@ export class OpenbookV2Subscriber implements L2OrderBookGenerator {
|
|
|
102
102
|
return undefined;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
return
|
|
105
|
+
return this.convertPriceInLotsToPricePrecision(bestBid.priceLots);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
public getBestAsk(): BN | undefined {
|
|
@@ -112,7 +112,7 @@ export class OpenbookV2Subscriber implements L2OrderBookGenerator {
|
|
|
112
112
|
return undefined;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
return
|
|
115
|
+
return this.convertPriceInLotsToPricePrecision(bestAsk.priceLots);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
public getL2Bids(): Generator<L2Level> {
|
|
@@ -123,17 +123,27 @@ export class OpenbookV2Subscriber implements L2OrderBookGenerator {
|
|
|
123
123
|
return this.getL2Levels('asks');
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
const pricePrecision = PRICE_PRECISION.toNumber();
|
|
126
|
+
public convertSizeInBaseLotsToMarketPrecision(sizeInLots: BN): BN {
|
|
127
|
+
return sizeInLots.mul(this.market.account.baseLotSize);
|
|
128
|
+
}
|
|
131
129
|
|
|
132
|
-
|
|
130
|
+
public convertPriceInLotsToPricePrecision(priceInLots: BN): BN {
|
|
131
|
+
const adjPrice = priceInLots
|
|
132
|
+
.mul(PRICE_PRECISION)
|
|
133
|
+
.muln(
|
|
134
|
+
10 **
|
|
135
|
+
(this.market.account.baseDecimals - this.market.account.quoteDecimals)
|
|
136
|
+
)
|
|
137
|
+
.mul(this.market.account.quoteLotSize)
|
|
138
|
+
.div(this.market.account.baseLotSize);
|
|
139
|
+
return adjPrice;
|
|
140
|
+
}
|
|
133
141
|
|
|
142
|
+
*getL2Levels(side: 'bids' | 'asks'): Generator<L2Level> {
|
|
143
|
+
const levels = side === 'bids' ? this.market.bids : this.market.asks;
|
|
134
144
|
for (const order of levels?.items()) {
|
|
135
|
-
const size =
|
|
136
|
-
const price =
|
|
145
|
+
const size = this.convertSizeInBaseLotsToMarketPrecision(order.sizeLots);
|
|
146
|
+
const price = this.convertPriceInLotsToPricePrecision(order.priceLots);
|
|
137
147
|
yield {
|
|
138
148
|
price,
|
|
139
149
|
size,
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
Client,
|
|
5
5
|
deserializeClockData,
|
|
6
6
|
toNum,
|
|
7
|
-
getMarketUiLadder,
|
|
8
7
|
Market,
|
|
8
|
+
getMarketLadder,
|
|
9
9
|
} from '@ellipsis-labs/phoenix-sdk';
|
|
10
10
|
import { PRICE_PRECISION } from '../constants/numericConstants';
|
|
11
11
|
import { BN } from '@coral-xyz/anchor';
|
|
@@ -138,7 +138,7 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
public getBestBid(): BN | undefined {
|
|
141
|
-
const ladder =
|
|
141
|
+
const ladder = getMarketLadder(
|
|
142
142
|
this.market,
|
|
143
143
|
this.lastSlot,
|
|
144
144
|
this.lastUnixTimestamp,
|
|
@@ -148,11 +148,11 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
148
148
|
if (!bestBid) {
|
|
149
149
|
return undefined;
|
|
150
150
|
}
|
|
151
|
-
return
|
|
151
|
+
return this.convertPriceInTicksToPricePrecision(bestBid.priceInTicks);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
public getBestAsk(): BN | undefined {
|
|
155
|
-
const ladder =
|
|
155
|
+
const ladder = getMarketLadder(
|
|
156
156
|
this.market,
|
|
157
157
|
this.lastSlot,
|
|
158
158
|
this.lastUnixTimestamp,
|
|
@@ -163,7 +163,24 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
163
163
|
if (!bestAsk) {
|
|
164
164
|
return undefined;
|
|
165
165
|
}
|
|
166
|
-
return
|
|
166
|
+
return this.convertPriceInTicksToPricePrecision(bestAsk.priceInTicks);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public convertPriceInTicksToPricePrecision(priceInTicks: BN): BN {
|
|
170
|
+
const quotePrecision = new BN(
|
|
171
|
+
Math.pow(10, this.market.data.header.quoteParams.decimals)
|
|
172
|
+
);
|
|
173
|
+
const denom = quotePrecision.muln(
|
|
174
|
+
this.market.data.header.rawBaseUnitsPerBaseUnit
|
|
175
|
+
);
|
|
176
|
+
const price = priceInTicks
|
|
177
|
+
.muln(this.market.data.quoteLotsPerBaseUnitPerTick)
|
|
178
|
+
.muln(toNum(this.market.data.header.quoteLotSize));
|
|
179
|
+
return price.mul(PRICE_PRECISION).div(denom);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots: BN): BN {
|
|
183
|
+
return sizeInBaseLots.muln(toNum(this.market.data.header.baseLotSize));
|
|
167
184
|
}
|
|
168
185
|
|
|
169
186
|
public getL2Bids(): Generator<L2Level> {
|
|
@@ -175,14 +192,7 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
*getL2Levels(side: 'bids' | 'asks'): Generator<L2Level> {
|
|
178
|
-
const
|
|
179
|
-
10,
|
|
180
|
-
this.market.data.header.baseParams.decimals
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const pricePrecision = PRICE_PRECISION.toNumber();
|
|
184
|
-
|
|
185
|
-
const ladder = getMarketUiLadder(
|
|
195
|
+
const ladder = getMarketLadder(
|
|
186
196
|
this.market,
|
|
187
197
|
this.lastSlot,
|
|
188
198
|
this.lastUnixTimestamp,
|
|
@@ -190,10 +200,12 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
|
|
|
190
200
|
);
|
|
191
201
|
|
|
192
202
|
for (let i = 0; i < ladder[side].length; i++) {
|
|
193
|
-
const {
|
|
203
|
+
const { priceInTicks, sizeInBaseLots } = ladder[side][i];
|
|
194
204
|
try {
|
|
195
|
-
const size =
|
|
196
|
-
|
|
205
|
+
const size =
|
|
206
|
+
this.convertSizeInBaseLotsToMarketPrecision(sizeInBaseLots);
|
|
207
|
+
const updatedPrice =
|
|
208
|
+
this.convertPriceInTicksToPricePrecision(priceInTicks);
|
|
197
209
|
yield {
|
|
198
210
|
price: updatedPrice,
|
|
199
211
|
size,
|