@drift-labs/sdk 2.36.1-beta.4 → 2.36.1-beta.6
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/dlob/DLOB.d.ts +8 -0
- package/lib/dlob/DLOB.js +15 -0
- package/lib/user.d.ts +6 -0
- package/lib/user.js +14 -0
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +38 -0
- package/src/user.ts +18 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.36.1-beta.
|
|
1
|
+
2.36.1-beta.6
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -154,5 +154,13 @@ export declare class DLOB {
|
|
|
154
154
|
slot: number;
|
|
155
155
|
oraclePriceData: OraclePriceData;
|
|
156
156
|
}): BN;
|
|
157
|
+
getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, }: {
|
|
158
|
+
marketIndex: number;
|
|
159
|
+
marketType: MarketType;
|
|
160
|
+
direction: PositionDirection;
|
|
161
|
+
slot: number;
|
|
162
|
+
oraclePriceData: OraclePriceData;
|
|
163
|
+
numMakers: number;
|
|
164
|
+
}): PublicKey[];
|
|
157
165
|
}
|
|
158
166
|
export {};
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -1063,5 +1063,20 @@ class DLOB {
|
|
|
1063
1063
|
return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData));
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
|
+
getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, }) {
|
|
1067
|
+
const makers = new Map();
|
|
1068
|
+
const generator = (0, __1.isVariant)(direction, 'long')
|
|
1069
|
+
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
1070
|
+
: this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
|
|
1071
|
+
for (const node of generator) {
|
|
1072
|
+
if (!makers.has(node.userAccount.toString())) {
|
|
1073
|
+
makers.set(node.userAccount.toString(), node.userAccount);
|
|
1074
|
+
}
|
|
1075
|
+
if (makers.size === numMakers) {
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return Array.from(makers.values());
|
|
1080
|
+
}
|
|
1066
1081
|
}
|
|
1067
1082
|
exports.DLOB = DLOB;
|
package/lib/user.d.ts
CHANGED
|
@@ -188,6 +188,12 @@ export declare class User {
|
|
|
188
188
|
};
|
|
189
189
|
getTotalLiabilityValue(marginCategory?: MarginCategory): BN;
|
|
190
190
|
getTotalAssetValue(marginCategory?: MarginCategory): BN;
|
|
191
|
+
/**
|
|
192
|
+
* Calculates the all time P&L of the user.
|
|
193
|
+
*
|
|
194
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
195
|
+
*/
|
|
196
|
+
getTotalAllTimePnl(): BN;
|
|
191
197
|
/**
|
|
192
198
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
193
199
|
* for large sizes where imf factor activates, result is a lower bound
|
package/lib/user.js
CHANGED
|
@@ -815,6 +815,20 @@ class User {
|
|
|
815
815
|
getTotalAssetValue(marginCategory) {
|
|
816
816
|
return this.getSpotMarketAssetValue(undefined, marginCategory, true).add(this.getUnrealizedPNL(true, undefined, marginCategory));
|
|
817
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Calculates the all time P&L of the user.
|
|
820
|
+
*
|
|
821
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
822
|
+
*/
|
|
823
|
+
getTotalAllTimePnl() {
|
|
824
|
+
const netBankValue = this.getNetSpotMarketValue();
|
|
825
|
+
const unrealizedPnl = this.getUnrealizedPNL(true, undefined, undefined);
|
|
826
|
+
const netUsdValue = netBankValue.add(unrealizedPnl);
|
|
827
|
+
const totalDeposits = this.getUserAccount().totalDeposits;
|
|
828
|
+
const totalWithdraws = this.getUserAccount().totalWithdraws;
|
|
829
|
+
const totalPnl = netUsdValue.add(totalWithdraws).sub(totalDeposits);
|
|
830
|
+
return totalPnl;
|
|
831
|
+
}
|
|
818
832
|
/**
|
|
819
833
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
820
834
|
* for large sizes where imf factor activates, result is a lower bound
|
package/package.json
CHANGED
package/src/dlob/DLOB.ts
CHANGED
|
@@ -1925,4 +1925,42 @@ export class DLOB {
|
|
|
1925
1925
|
);
|
|
1926
1926
|
}
|
|
1927
1927
|
}
|
|
1928
|
+
|
|
1929
|
+
public getBestMakers({
|
|
1930
|
+
marketIndex,
|
|
1931
|
+
marketType,
|
|
1932
|
+
direction,
|
|
1933
|
+
slot,
|
|
1934
|
+
oraclePriceData,
|
|
1935
|
+
numMakers,
|
|
1936
|
+
}: {
|
|
1937
|
+
marketIndex: number;
|
|
1938
|
+
marketType: MarketType;
|
|
1939
|
+
direction: PositionDirection;
|
|
1940
|
+
slot: number;
|
|
1941
|
+
oraclePriceData: OraclePriceData;
|
|
1942
|
+
numMakers: number;
|
|
1943
|
+
}): PublicKey[] {
|
|
1944
|
+
const makers = new Map<string, PublicKey>();
|
|
1945
|
+
const generator = isVariant(direction, 'long')
|
|
1946
|
+
? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
|
|
1947
|
+
: this.getRestingLimitAsks(
|
|
1948
|
+
marketIndex,
|
|
1949
|
+
slot,
|
|
1950
|
+
marketType,
|
|
1951
|
+
oraclePriceData
|
|
1952
|
+
);
|
|
1953
|
+
|
|
1954
|
+
for (const node of generator) {
|
|
1955
|
+
if (!makers.has(node.userAccount.toString())) {
|
|
1956
|
+
makers.set(node.userAccount.toString(), node.userAccount);
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
if (makers.size === numMakers) {
|
|
1960
|
+
break;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
return Array.from(makers.values());
|
|
1965
|
+
}
|
|
1928
1966
|
}
|
package/src/user.ts
CHANGED
|
@@ -1487,6 +1487,24 @@ export class User {
|
|
|
1487
1487
|
);
|
|
1488
1488
|
}
|
|
1489
1489
|
|
|
1490
|
+
/**
|
|
1491
|
+
* Calculates the all time P&L of the user.
|
|
1492
|
+
*
|
|
1493
|
+
* Net withdraws + Net spot market value + Net unrealized P&L -
|
|
1494
|
+
*/
|
|
1495
|
+
getTotalAllTimePnl(): BN {
|
|
1496
|
+
const netBankValue = this.getNetSpotMarketValue();
|
|
1497
|
+
const unrealizedPnl = this.getUnrealizedPNL(true, undefined, undefined);
|
|
1498
|
+
|
|
1499
|
+
const netUsdValue = netBankValue.add(unrealizedPnl);
|
|
1500
|
+
const totalDeposits = this.getUserAccount().totalDeposits;
|
|
1501
|
+
const totalWithdraws = this.getUserAccount().totalWithdraws;
|
|
1502
|
+
|
|
1503
|
+
const totalPnl = netUsdValue.add(totalWithdraws).sub(totalDeposits);
|
|
1504
|
+
|
|
1505
|
+
return totalPnl;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1490
1508
|
/**
|
|
1491
1509
|
* calculates max allowable leverage exceeding hitting requirement category
|
|
1492
1510
|
* for large sizes where imf factor activates, result is a lower bound
|