@drift-labs/sdk 2.14.0-beta.0 → 2.15.0-beta.0
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/lib/accounts/bulkAccountLoader.d.ts +0 -1
- package/lib/accounts/bulkAccountLoader.js +3 -3
- package/lib/accounts/fetch.js +2 -2
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/types.d.ts +0 -1
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.js +1 -5
- package/lib/adminClient.js +57 -61
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/dlob/DLOB.js +68 -68
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.js +81 -85
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +9 -9
- package/lib/factory/oracleClient.js +2 -2
- package/lib/idl/drift.json +1 -1
- package/lib/index.js +1 -5
- package/lib/math/amm.js +23 -23
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +5 -5
- package/lib/math/market.js +13 -13
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +23 -23
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +8 -8
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.js +42 -42
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/tokenFaucet.js +1 -5
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/user.js +52 -52
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/package.json +1 -1
- package/src/assert/assert.js +9 -0
- package/src/constants/numericConstants.ts +1 -0
- package/src/constants/perpMarkets.ts +10 -0
- package/src/dlob/DLOB.ts +1 -1
- package/src/idl/drift.json +1 -1
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/user.ts +2 -1
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
package/lib/dlob/DLOB.js
CHANGED
|
@@ -78,10 +78,10 @@ class DLOB {
|
|
|
78
78
|
this.insertOrder(record.order, record.user);
|
|
79
79
|
}
|
|
80
80
|
handleOrderActionRecord(record) {
|
|
81
|
-
if (
|
|
81
|
+
if (__1.isOneOfVariant(record.action, ['place', 'expire'])) {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
if (
|
|
84
|
+
if (__1.isVariant(record.action, 'trigger')) {
|
|
85
85
|
if (record.taker !== null) {
|
|
86
86
|
const takerOrder = this.getOrder(record.takerOrderId, record.taker);
|
|
87
87
|
if (takerOrder) {
|
|
@@ -95,7 +95,7 @@ class DLOB {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
else if (
|
|
98
|
+
else if (__1.isVariant(record.action, 'fill')) {
|
|
99
99
|
if (record.taker !== null) {
|
|
100
100
|
const takerOrder = this.getOrder(record.takerOrderId, record.taker);
|
|
101
101
|
if (takerOrder) {
|
|
@@ -109,7 +109,7 @@ class DLOB {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
else if (
|
|
112
|
+
else if (__1.isVariant(record.action, 'cancel')) {
|
|
113
113
|
if (record.taker !== null) {
|
|
114
114
|
const takerOrder = this.getOrder(record.takerOrderId, record.taker);
|
|
115
115
|
if (takerOrder) {
|
|
@@ -126,20 +126,20 @@ class DLOB {
|
|
|
126
126
|
}
|
|
127
127
|
insertOrder(order, userAccount, onInsert) {
|
|
128
128
|
var _a;
|
|
129
|
-
if (
|
|
129
|
+
if (__1.isVariant(order.status, 'init')) {
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
|
-
if (!
|
|
132
|
+
if (!__1.isOneOfVariant(order.orderType, SUPPORTED_ORDER_TYPES)) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
const marketType =
|
|
135
|
+
const marketType = __1.getVariant(order.marketType);
|
|
136
136
|
if (!this.orderLists.get(marketType).has(order.marketIndex)) {
|
|
137
137
|
this.addOrderList(marketType, order.marketIndex);
|
|
138
138
|
}
|
|
139
|
-
if (
|
|
139
|
+
if (__1.isVariant(order.status, 'open')) {
|
|
140
140
|
this.openOrders
|
|
141
141
|
.get(marketType)
|
|
142
|
-
.add(
|
|
142
|
+
.add(NodeList_1.getOrderSignature(order.orderId, userAccount));
|
|
143
143
|
}
|
|
144
144
|
(_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount);
|
|
145
145
|
if (onInsert) {
|
|
@@ -186,15 +186,15 @@ class DLOB {
|
|
|
186
186
|
}
|
|
187
187
|
trigger(order, userAccount, onTrigger) {
|
|
188
188
|
var _a;
|
|
189
|
-
if (
|
|
189
|
+
if (__1.isVariant(order.status, 'init')) {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
if (
|
|
192
|
+
if (__1.isTriggered(order)) {
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
const marketType =
|
|
195
|
+
const marketType = __1.getVariant(order.marketType);
|
|
196
196
|
const triggerList = this.orderLists.get(marketType).get(order.marketIndex)
|
|
197
|
-
.trigger[
|
|
197
|
+
.trigger[__1.isVariant(order.triggerCondition, 'above') ? 'above' : 'below'];
|
|
198
198
|
triggerList.remove(order, userAccount);
|
|
199
199
|
(_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount);
|
|
200
200
|
if (onTrigger) {
|
|
@@ -203,7 +203,7 @@ class DLOB {
|
|
|
203
203
|
}
|
|
204
204
|
delete(order, userAccount, onDelete) {
|
|
205
205
|
var _a;
|
|
206
|
-
if (
|
|
206
|
+
if (__1.isVariant(order.status, 'init')) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
(_a = this.getListForOrder(order)) === null || _a === void 0 ? void 0 : _a.remove(order, userAccount);
|
|
@@ -212,12 +212,12 @@ class DLOB {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
getListForOrder(order) {
|
|
215
|
-
const isInactiveTriggerOrder =
|
|
215
|
+
const isInactiveTriggerOrder = __1.mustBeTriggered(order) && !__1.isTriggered(order);
|
|
216
216
|
let type;
|
|
217
217
|
if (isInactiveTriggerOrder) {
|
|
218
218
|
type = 'trigger';
|
|
219
219
|
}
|
|
220
|
-
else if (
|
|
220
|
+
else if (__1.isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
|
|
221
221
|
type = 'market';
|
|
222
222
|
}
|
|
223
223
|
else if (order.oraclePriceOffset !== 0) {
|
|
@@ -228,12 +228,12 @@ class DLOB {
|
|
|
228
228
|
}
|
|
229
229
|
let subType;
|
|
230
230
|
if (isInactiveTriggerOrder) {
|
|
231
|
-
subType =
|
|
231
|
+
subType = __1.isVariant(order.triggerCondition, 'above') ? 'above' : 'below';
|
|
232
232
|
}
|
|
233
233
|
else {
|
|
234
|
-
subType =
|
|
234
|
+
subType = __1.isVariant(order.direction, 'long') ? 'bid' : 'ask';
|
|
235
235
|
}
|
|
236
|
-
const marketType =
|
|
236
|
+
const marketType = __1.getVariant(order.marketType);
|
|
237
237
|
if (!this.orderLists.has(marketType)) {
|
|
238
238
|
return undefined;
|
|
239
239
|
}
|
|
@@ -249,10 +249,10 @@ class DLOB {
|
|
|
249
249
|
return undefined;
|
|
250
250
|
}
|
|
251
251
|
findNodesToFill(marketIndex, fallbackBid, fallbackAsk, slot, ts, marketType, oraclePriceData, stateAccount, marketAccount) {
|
|
252
|
-
if (
|
|
252
|
+
if (exchangeStatus_1.fillPaused(stateAccount, marketAccount)) {
|
|
253
253
|
return [];
|
|
254
254
|
}
|
|
255
|
-
const isAmmPaused =
|
|
255
|
+
const isAmmPaused = exchangeStatus_1.ammPaused(stateAccount, marketAccount);
|
|
256
256
|
const marketOrderNodesToFill = this.findMarketNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, fallbackAsk, fallbackBid);
|
|
257
257
|
const limitOrderNodesToFill = this.findLimitOrderNodesToFill(marketIndex, slot, marketType, oraclePriceData, isAmmPaused, fallbackAsk, fallbackBid);
|
|
258
258
|
// get expired market nodes
|
|
@@ -369,15 +369,15 @@ class DLOB {
|
|
|
369
369
|
let nextNode = nodeGenerator.next();
|
|
370
370
|
while (!nextNode.done) {
|
|
371
371
|
const node = nextNode.value;
|
|
372
|
-
if (
|
|
372
|
+
if (__1.isVariant(marketType, 'spot') && ((_a = node.order) === null || _a === void 0 ? void 0 : _a.postOnly)) {
|
|
373
373
|
nextNode = nodeGenerator.next();
|
|
374
374
|
continue;
|
|
375
375
|
}
|
|
376
|
-
const nodePrice =
|
|
376
|
+
const nodePrice = __1.getLimitPrice(node.order, oraclePriceData, slot);
|
|
377
377
|
// order crosses if there is no limit price or it crosses fallback price
|
|
378
378
|
const crosses = doesCross(nodePrice, fallbackPrice);
|
|
379
379
|
// fallback is available if auction is complete or it's a spot order
|
|
380
|
-
const fallbackAvailable =
|
|
380
|
+
const fallbackAvailable = __1.isVariant(marketType, 'spot') || __1.isAuctionComplete(node.order, slot);
|
|
381
381
|
if (crosses && fallbackAvailable) {
|
|
382
382
|
nodesToFill.push({
|
|
383
383
|
node: node,
|
|
@@ -390,7 +390,7 @@ class DLOB {
|
|
|
390
390
|
}
|
|
391
391
|
findExpiredNodesToFill(marketIndex, ts, marketType) {
|
|
392
392
|
const nodesToFill = new Array();
|
|
393
|
-
const marketTypeStr =
|
|
393
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
394
394
|
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
395
395
|
if (!nodeLists) {
|
|
396
396
|
return nodesToFill;
|
|
@@ -408,7 +408,7 @@ class DLOB {
|
|
|
408
408
|
];
|
|
409
409
|
for (const bidGenerator of bidGenerators) {
|
|
410
410
|
for (const bid of bidGenerator) {
|
|
411
|
-
if (
|
|
411
|
+
if (__1.isOrderExpired(bid.order, ts)) {
|
|
412
412
|
nodesToFill.push({
|
|
413
413
|
node: bid,
|
|
414
414
|
});
|
|
@@ -417,7 +417,7 @@ class DLOB {
|
|
|
417
417
|
}
|
|
418
418
|
for (const askGenerator of askGenerators) {
|
|
419
419
|
for (const ask of askGenerator) {
|
|
420
|
-
if (
|
|
420
|
+
if (__1.isOrderExpired(ask.order, ts)) {
|
|
421
421
|
nodesToFill.push({
|
|
422
422
|
node: ask,
|
|
423
423
|
});
|
|
@@ -430,14 +430,14 @@ class DLOB {
|
|
|
430
430
|
const nodesToFill = new Array();
|
|
431
431
|
// Then see if there are orders still in JIT auction
|
|
432
432
|
for (const marketBid of this.getMarketBids(marketIndex, marketType)) {
|
|
433
|
-
if (!
|
|
433
|
+
if (!__1.isAuctionComplete(marketBid.order, slot)) {
|
|
434
434
|
nodesToFill.push({
|
|
435
435
|
node: marketBid,
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
for (const marketAsk of this.getMarketAsks(marketIndex, marketType)) {
|
|
440
|
-
if (!
|
|
440
|
+
if (!__1.isAuctionComplete(marketAsk.order, slot)) {
|
|
441
441
|
nodesToFill.push({
|
|
442
442
|
node: marketAsk,
|
|
443
443
|
});
|
|
@@ -446,7 +446,7 @@ class DLOB {
|
|
|
446
446
|
return nodesToFill;
|
|
447
447
|
}
|
|
448
448
|
*getMarketBids(marketIndex, marketType) {
|
|
449
|
-
const marketTypeStr =
|
|
449
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
450
450
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
451
451
|
if (!orderLists) {
|
|
452
452
|
return;
|
|
@@ -460,7 +460,7 @@ class DLOB {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
*getMarketAsks(marketIndex, marketType) {
|
|
463
|
-
const marketTypeStr =
|
|
463
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
464
464
|
const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
465
465
|
if (!orderLists) {
|
|
466
466
|
return;
|
|
@@ -492,10 +492,10 @@ class DLOB {
|
|
|
492
492
|
const bestValue = bestGenerator.next.value;
|
|
493
493
|
const currentValue = currentGenerator.next.value;
|
|
494
494
|
// always return the market orders first
|
|
495
|
-
if (bestValue.order &&
|
|
495
|
+
if (bestValue.order && __1.isMarketOrder(bestValue.order)) {
|
|
496
496
|
return bestGenerator;
|
|
497
497
|
}
|
|
498
|
-
if (currentValue.order &&
|
|
498
|
+
if (currentValue.order && __1.isMarketOrder(currentValue.order)) {
|
|
499
499
|
return currentGenerator;
|
|
500
500
|
}
|
|
501
501
|
const bestPrice = bestValue.getPrice(oraclePriceData, slot);
|
|
@@ -519,10 +519,10 @@ class DLOB {
|
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
*getLimitAsks(marketIndex, slot, marketType, oraclePriceData) {
|
|
522
|
-
if (
|
|
522
|
+
if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
523
523
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
524
524
|
}
|
|
525
|
-
const marketTypeStr =
|
|
525
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
526
526
|
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
527
527
|
if (!nodeLists) {
|
|
528
528
|
return;
|
|
@@ -553,13 +553,13 @@ class DLOB {
|
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
555
|
isRestingLimitOrder(order, slot) {
|
|
556
|
-
return order.postOnly || new __1.BN(slot).sub(order.slot).gte(new __1.BN(
|
|
556
|
+
return order.postOnly || new __1.BN(slot).sub(order.slot).gte(new __1.BN(45));
|
|
557
557
|
}
|
|
558
558
|
*getLimitBids(marketIndex, slot, marketType, oraclePriceData) {
|
|
559
|
-
if (
|
|
559
|
+
if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
560
560
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
561
561
|
}
|
|
562
|
-
const marketTypeStr =
|
|
562
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
563
563
|
const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
564
564
|
if (!nodeLists) {
|
|
565
565
|
return;
|
|
@@ -590,32 +590,32 @@ class DLOB {
|
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
*getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) {
|
|
593
|
-
if (
|
|
593
|
+
if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
594
594
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
595
595
|
}
|
|
596
596
|
const generatorList = [
|
|
597
597
|
this.getMarketAsks(marketIndex, marketType),
|
|
598
598
|
this.getLimitAsks(marketIndex, slot, marketType, oraclePriceData),
|
|
599
599
|
];
|
|
600
|
-
const marketTypeStr =
|
|
600
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
601
601
|
if (marketTypeStr === 'perp' && fallbackAsk) {
|
|
602
|
-
generatorList.push(
|
|
602
|
+
generatorList.push(NodeList_1.getVammNodeGenerator(fallbackAsk));
|
|
603
603
|
}
|
|
604
604
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestPrice, currentPrice) => {
|
|
605
605
|
return bestPrice.lt(currentPrice);
|
|
606
606
|
});
|
|
607
607
|
}
|
|
608
608
|
*getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData) {
|
|
609
|
-
if (
|
|
609
|
+
if (__1.isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
610
610
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
611
611
|
}
|
|
612
612
|
const generatorList = [
|
|
613
613
|
this.getMarketBids(marketIndex, marketType),
|
|
614
614
|
this.getLimitBids(marketIndex, slot, marketType, oraclePriceData),
|
|
615
615
|
];
|
|
616
|
-
const marketTypeStr =
|
|
616
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
617
617
|
if (marketTypeStr === 'perp' && fallbackBid) {
|
|
618
|
-
generatorList.push(
|
|
618
|
+
generatorList.push(NodeList_1.getVammNodeGenerator(fallbackBid));
|
|
619
619
|
}
|
|
620
620
|
yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestPrice, currentPrice) => {
|
|
621
621
|
return bestPrice.gt(currentPrice);
|
|
@@ -640,10 +640,10 @@ class DLOB {
|
|
|
640
640
|
}
|
|
641
641
|
const { takerNode, makerNode } = this.determineMakerAndTaker(askNode, bidNode);
|
|
642
642
|
// extra guard against bad fills for limit orders where auction is incomplete
|
|
643
|
-
if (!
|
|
643
|
+
if (!__1.isAuctionComplete(takerNode.order, slot)) {
|
|
644
644
|
let bidPrice;
|
|
645
645
|
let askPrice;
|
|
646
|
-
if (
|
|
646
|
+
if (__1.isVariant(takerNode.order.direction, 'long')) {
|
|
647
647
|
bidPrice = __1.BN.min(takerNode.getPrice(oraclePriceData, slot), fallbackAsk || __1.BN_MAX);
|
|
648
648
|
askPrice = makerNode.getPrice(oraclePriceData, slot);
|
|
649
649
|
}
|
|
@@ -715,11 +715,11 @@ class DLOB {
|
|
|
715
715
|
.value.getPrice(oraclePriceData, slot);
|
|
716
716
|
}
|
|
717
717
|
findNodesToTrigger(marketIndex, slot, oraclePrice, marketType, stateAccount) {
|
|
718
|
-
if (
|
|
718
|
+
if (exchangeStatus_1.exchangePaused(stateAccount)) {
|
|
719
719
|
return [];
|
|
720
720
|
}
|
|
721
721
|
const nodesToTrigger = [];
|
|
722
|
-
const marketTypeStr =
|
|
722
|
+
const marketTypeStr = __1.getVariant(marketType);
|
|
723
723
|
const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
|
|
724
724
|
const triggerAboveList = marketNodeLists
|
|
725
725
|
? marketNodeLists.trigger.above
|
|
@@ -727,7 +727,7 @@ class DLOB {
|
|
|
727
727
|
if (triggerAboveList) {
|
|
728
728
|
for (const node of triggerAboveList.getGenerator()) {
|
|
729
729
|
if (oraclePrice.gt(node.order.triggerPrice)) {
|
|
730
|
-
if (
|
|
730
|
+
if (__1.isAuctionComplete(node.order, slot)) {
|
|
731
731
|
nodesToTrigger.push({
|
|
732
732
|
node: node,
|
|
733
733
|
});
|
|
@@ -744,7 +744,7 @@ class DLOB {
|
|
|
744
744
|
if (triggerBelowList) {
|
|
745
745
|
for (const node of triggerBelowList.getGenerator()) {
|
|
746
746
|
if (oraclePrice.lt(node.order.triggerPrice)) {
|
|
747
|
-
if (
|
|
747
|
+
if (__1.isAuctionComplete(node.order, slot)) {
|
|
748
748
|
nodesToTrigger.push({
|
|
749
749
|
node: node,
|
|
750
750
|
});
|
|
@@ -758,46 +758,46 @@ class DLOB {
|
|
|
758
758
|
return nodesToTrigger;
|
|
759
759
|
}
|
|
760
760
|
printTopOfOrderLists(sdkConfig, driftClient, slotSubscriber, marketIndex, marketType) {
|
|
761
|
-
if (
|
|
761
|
+
if (__1.isVariant(marketType, 'perp')) {
|
|
762
762
|
const market = driftClient.getPerpMarketAccount(marketIndex);
|
|
763
763
|
const slot = slotSubscriber.getSlot();
|
|
764
764
|
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
765
|
-
const fallbackAsk =
|
|
766
|
-
const fallbackBid =
|
|
765
|
+
const fallbackAsk = __1.calculateAskPrice(market, oraclePriceData);
|
|
766
|
+
const fallbackBid = __1.calculateBidPrice(market, oraclePriceData);
|
|
767
767
|
const bestAsk = this.getBestAsk(marketIndex, fallbackAsk, slot, marketType, oraclePriceData);
|
|
768
768
|
const bestBid = this.getBestBid(marketIndex, fallbackBid, slot, marketType, oraclePriceData);
|
|
769
769
|
const mid = bestAsk.add(bestBid).div(new __1.BN(2));
|
|
770
|
-
const bidSpread = (
|
|
771
|
-
|
|
770
|
+
const bidSpread = (__1.convertToNumber(bestBid, __1.PRICE_PRECISION) /
|
|
771
|
+
__1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
772
772
|
1) *
|
|
773
773
|
100.0;
|
|
774
|
-
const askSpread = (
|
|
775
|
-
|
|
774
|
+
const askSpread = (__1.convertToNumber(bestAsk, __1.PRICE_PRECISION) /
|
|
775
|
+
__1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
776
776
|
1) *
|
|
777
777
|
100.0;
|
|
778
778
|
console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
|
|
779
|
-
console.log(` Ask`,
|
|
780
|
-
console.log(` Mid`,
|
|
781
|
-
console.log(` Bid`,
|
|
779
|
+
console.log(` Ask`, __1.convertToNumber(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
780
|
+
console.log(` Mid`, __1.convertToNumber(mid, __1.PRICE_PRECISION).toFixed(3));
|
|
781
|
+
console.log(` Bid`, __1.convertToNumber(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
|
|
782
782
|
}
|
|
783
|
-
else if (
|
|
783
|
+
else if (__1.isVariant(marketType, 'spot')) {
|
|
784
784
|
const slot = slotSubscriber.getSlot();
|
|
785
785
|
const oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
|
786
786
|
const bestAsk = this.getBestAsk(marketIndex, undefined, slot, marketType, oraclePriceData);
|
|
787
787
|
const bestBid = this.getBestBid(marketIndex, undefined, slot, marketType, oraclePriceData);
|
|
788
788
|
const mid = bestAsk.add(bestBid).div(new __1.BN(2));
|
|
789
|
-
const bidSpread = (
|
|
790
|
-
|
|
789
|
+
const bidSpread = (__1.convertToNumber(bestBid, __1.PRICE_PRECISION) /
|
|
790
|
+
__1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
791
791
|
1) *
|
|
792
792
|
100.0;
|
|
793
|
-
const askSpread = (
|
|
794
|
-
|
|
793
|
+
const askSpread = (__1.convertToNumber(bestAsk, __1.PRICE_PRECISION) /
|
|
794
|
+
__1.convertToNumber(oraclePriceData.price, __1.PRICE_PRECISION) -
|
|
795
795
|
1) *
|
|
796
796
|
100.0;
|
|
797
797
|
console.log(`Market ${sdkConfig.MARKETS[marketIndex].symbol} Orders`);
|
|
798
|
-
console.log(` Ask`,
|
|
799
|
-
console.log(` Mid`,
|
|
800
|
-
console.log(` Bid`,
|
|
798
|
+
console.log(` Ask`, __1.convertToNumber(bestAsk, __1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
|
|
799
|
+
console.log(` Mid`, __1.convertToNumber(mid, __1.PRICE_PRECISION).toFixed(3));
|
|
800
|
+
console.log(` Bid`, __1.convertToNumber(bestBid, __1.PRICE_PRECISION).toFixed(3), `(${bidSpread.toFixed(4)}%)`);
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
getDLOBOrders() {
|
package/lib/dlob/DLOBNode.js
CHANGED
|
@@ -13,20 +13,20 @@ class OrderNode {
|
|
|
13
13
|
this.sortValue = this.getSortValue(order);
|
|
14
14
|
}
|
|
15
15
|
getLabel() {
|
|
16
|
-
let msg = `Order ${
|
|
17
|
-
msg += ` ${
|
|
18
|
-
msg += `${
|
|
16
|
+
let msg = `Order ${NodeList_1.getOrderSignature(this.order.orderId, this.userAccount)}`;
|
|
17
|
+
msg += ` ${__1.isVariant(this.order.direction, 'long') ? 'LONG' : 'SHORT'} `;
|
|
18
|
+
msg += `${__1.convertToNumber(this.order.baseAssetAmount, __1.AMM_RESERVE_PRECISION).toFixed(3)}`;
|
|
19
19
|
if (this.order.price.gt(__1.ZERO)) {
|
|
20
|
-
msg += ` @ ${
|
|
20
|
+
msg += ` @ ${__1.convertToNumber(this.order.price, __1.PRICE_PRECISION).toFixed(3)}`;
|
|
21
21
|
}
|
|
22
22
|
if (this.order.triggerPrice.gt(__1.ZERO)) {
|
|
23
|
-
msg += ` ${
|
|
24
|
-
msg += ` ${
|
|
23
|
+
msg += ` ${__1.isVariant(this.order.triggerCondition, 'below') ? 'BELOW' : 'ABOVE'}`;
|
|
24
|
+
msg += ` ${__1.convertToNumber(this.order.triggerPrice, __1.PRICE_PRECISION).toFixed(3)}`;
|
|
25
25
|
}
|
|
26
26
|
return msg;
|
|
27
27
|
}
|
|
28
28
|
getPrice(oraclePriceData, slot) {
|
|
29
|
-
return
|
|
29
|
+
return __1.getLimitPrice(this.order, oraclePriceData, slot);
|
|
30
30
|
}
|
|
31
31
|
isBaseFilled() {
|
|
32
32
|
return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
|
package/lib/dlob/NodeList.js
CHANGED
|
@@ -20,10 +20,10 @@ class NodeList {
|
|
|
20
20
|
this.nodeMap.clear();
|
|
21
21
|
}
|
|
22
22
|
insert(order, marketType, userAccount) {
|
|
23
|
-
if (
|
|
23
|
+
if (__1.isVariant(order.status, 'init')) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const newNode =
|
|
26
|
+
const newNode = DLOBNode_1.createNode(this.nodeType, order, userAccount);
|
|
27
27
|
const orderSignature = getOrderSignature(order.orderId, userAccount);
|
|
28
28
|
if (this.nodeMap.has(orderSignature)) {
|
|
29
29
|
return;
|