@d8x/perpetuals-sdk 0.1.5 → 0.1.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/dist/marketData.d.ts +4 -4
- package/dist/marketData.js +5 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/marketData.ts +6 -26
- package/src/version.ts +1 -1
- package/abi/Multicall.json +0 -86
package/dist/marketData.d.ts
CHANGED
|
@@ -161,14 +161,14 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
161
161
|
*/
|
|
162
162
|
getWalletBalance(address: string, symbol: string): Promise<number>;
|
|
163
163
|
/**
|
|
164
|
-
* Gets the maximal order size
|
|
164
|
+
* Gets the maximal order size to open positions (increase size),
|
|
165
|
+
* considering the existing position, state of the perpetual
|
|
166
|
+
* Ignores users wallet balance.
|
|
165
167
|
* @param side BUY or SELL
|
|
166
168
|
* @param positionRisk Current position risk (as seen in positionRisk)
|
|
167
|
-
* @param perpetualState Current perpetual state (as seen in exchangeInfo)
|
|
168
|
-
* @param walletBalance Optional wallet balance to consider in the calculation
|
|
169
169
|
* @returns Maximal trade size, not signed
|
|
170
170
|
*/
|
|
171
|
-
maxOrderSizeForTrader(side: string, positionRisk: MarginAccount
|
|
171
|
+
maxOrderSizeForTrader(side: string, positionRisk: MarginAccount): Promise<number>;
|
|
172
172
|
/**
|
|
173
173
|
* Uses the Oracle(s) in the exchange to get the latest price of a given index in a given currency, if a route exists.
|
|
174
174
|
* @param {string} base Index name, e.g. ETH.
|
package/dist/marketData.js
CHANGED
|
@@ -433,25 +433,18 @@ class MarketData extends perpetualDataHandler_1.default {
|
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
435
|
/**
|
|
436
|
-
* Gets the maximal order size
|
|
436
|
+
* Gets the maximal order size to open positions (increase size),
|
|
437
|
+
* considering the existing position, state of the perpetual
|
|
438
|
+
* Ignores users wallet balance.
|
|
437
439
|
* @param side BUY or SELL
|
|
438
440
|
* @param positionRisk Current position risk (as seen in positionRisk)
|
|
439
|
-
* @param perpetualState Current perpetual state (as seen in exchangeInfo)
|
|
440
|
-
* @param walletBalance Optional wallet balance to consider in the calculation
|
|
441
441
|
* @returns Maximal trade size, not signed
|
|
442
442
|
*/
|
|
443
|
-
maxOrderSizeForTrader(side, positionRisk
|
|
443
|
+
maxOrderSizeForTrader(side, positionRisk) {
|
|
444
444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
445
|
-
if (walletBalance != undefined) {
|
|
446
|
-
positionRisk = yield this.positionRiskOnCollateralAction(walletBalance, positionRisk);
|
|
447
|
-
}
|
|
448
|
-
let initialMarginRate = this.symbolToPerpStaticInfo.get(positionRisk.symbol).initialMarginRate;
|
|
449
|
-
// fees not considered here
|
|
450
|
-
let maxPosition = (0, d8XMath_1.getMaxSignedPositionSize)(positionRisk.collateralCC, positionRisk.positionNotionalBaseCCY, positionRisk.entryPrice * positionRisk.positionNotionalBaseCCY, side == nodeSDKTypes_1.BUY_SIDE ? 1 : -1, perpetualState.markPrice, initialMarginRate, 0, perpetualState.markPrice, perpetualState.indexPrice, perpetualState.collToQuoteIndexPrice);
|
|
451
445
|
let curPosition = side == nodeSDKTypes_1.BUY_SIDE ? positionRisk.positionNotionalBaseCCY : -positionRisk.positionNotionalBaseCCY;
|
|
452
|
-
let tradeAmount = maxPosition - curPosition;
|
|
453
446
|
let perpId = this.getPerpIdFromSymbol(positionRisk.symbol);
|
|
454
|
-
let perpMaxPositionABK = yield this.proxyContract.
|
|
447
|
+
let perpMaxPositionABK = yield this.proxyContract.getMaxSignedOpenTradeSizeForPos(perpId, (0, d8XMath_1.floatToABK64x64)(curPosition), side == nodeSDKTypes_1.BUY_SIDE);
|
|
455
448
|
return (0, d8XMath_1.ABK64x64ToFloat)(perpMaxPositionABK.abs());
|
|
456
449
|
});
|
|
457
450
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const D8X_SDK_VERSION = "0.1.
|
|
1
|
+
export declare const D8X_SDK_VERSION = "0.1.6";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/src/marketData.ts
CHANGED
|
@@ -516,43 +516,23 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
/**
|
|
519
|
-
* Gets the maximal order size
|
|
519
|
+
* Gets the maximal order size to open positions (increase size),
|
|
520
|
+
* considering the existing position, state of the perpetual
|
|
521
|
+
* Ignores users wallet balance.
|
|
520
522
|
* @param side BUY or SELL
|
|
521
523
|
* @param positionRisk Current position risk (as seen in positionRisk)
|
|
522
|
-
* @param perpetualState Current perpetual state (as seen in exchangeInfo)
|
|
523
|
-
* @param walletBalance Optional wallet balance to consider in the calculation
|
|
524
524
|
* @returns Maximal trade size, not signed
|
|
525
525
|
*/
|
|
526
526
|
public async maxOrderSizeForTrader(
|
|
527
527
|
side: string,
|
|
528
|
-
positionRisk: MarginAccount
|
|
529
|
-
perpetualState: PerpetualState,
|
|
530
|
-
walletBalance?: number
|
|
528
|
+
positionRisk: MarginAccount
|
|
531
529
|
): Promise<number> {
|
|
532
|
-
if (walletBalance != undefined) {
|
|
533
|
-
positionRisk = await this.positionRiskOnCollateralAction(walletBalance, positionRisk);
|
|
534
|
-
}
|
|
535
|
-
let initialMarginRate = this.symbolToPerpStaticInfo.get(positionRisk.symbol)!.initialMarginRate;
|
|
536
|
-
// fees not considered here
|
|
537
|
-
let maxPosition = getMaxSignedPositionSize(
|
|
538
|
-
positionRisk.collateralCC,
|
|
539
|
-
positionRisk.positionNotionalBaseCCY,
|
|
540
|
-
positionRisk.entryPrice * positionRisk.positionNotionalBaseCCY,
|
|
541
|
-
side == BUY_SIDE ? 1 : -1,
|
|
542
|
-
perpetualState.markPrice,
|
|
543
|
-
initialMarginRate,
|
|
544
|
-
0,
|
|
545
|
-
perpetualState.markPrice,
|
|
546
|
-
perpetualState.indexPrice,
|
|
547
|
-
perpetualState.collToQuoteIndexPrice
|
|
548
|
-
);
|
|
549
530
|
let curPosition = side == BUY_SIDE ? positionRisk.positionNotionalBaseCCY : -positionRisk.positionNotionalBaseCCY;
|
|
550
|
-
let tradeAmount = maxPosition - curPosition;
|
|
551
531
|
let perpId = this.getPerpIdFromSymbol(positionRisk.symbol);
|
|
552
|
-
let perpMaxPositionABK = await this.proxyContract!.
|
|
532
|
+
let perpMaxPositionABK = await this.proxyContract!.getMaxSignedOpenTradeSizeForPos(
|
|
553
533
|
perpId,
|
|
554
534
|
floatToABK64x64(curPosition),
|
|
555
|
-
|
|
535
|
+
side == BUY_SIDE
|
|
556
536
|
);
|
|
557
537
|
return ABK64x64ToFloat(perpMaxPositionABK.abs());
|
|
558
538
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const D8X_SDK_VERSION = "0.1.
|
|
1
|
+
export const D8X_SDK_VERSION = "0.1.6";
|
package/abi/Multicall.json
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"constant": true,
|
|
4
|
-
"inputs": [],
|
|
5
|
-
"name": "getCurrentBlockTimestamp",
|
|
6
|
-
"outputs": [{ "name": "timestamp", "type": "uint256" }],
|
|
7
|
-
"payable": false,
|
|
8
|
-
"stateMutability": "view",
|
|
9
|
-
"type": "function"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"constant": false,
|
|
13
|
-
"inputs": [
|
|
14
|
-
{
|
|
15
|
-
"components": [
|
|
16
|
-
{ "name": "target", "type": "address" },
|
|
17
|
-
{ "name": "callData", "type": "bytes" }
|
|
18
|
-
],
|
|
19
|
-
"name": "calls",
|
|
20
|
-
"type": "tuple[]"
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
"name": "aggregate",
|
|
24
|
-
"outputs": [
|
|
25
|
-
{ "name": "blockNumber", "type": "uint256" },
|
|
26
|
-
{ "name": "returnData", "type": "bytes[]" }
|
|
27
|
-
],
|
|
28
|
-
"payable": false,
|
|
29
|
-
"stateMutability": "nonpayable",
|
|
30
|
-
"type": "function"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"constant": true,
|
|
34
|
-
"inputs": [],
|
|
35
|
-
"name": "getLastBlockHash",
|
|
36
|
-
"outputs": [{ "name": "blockHash", "type": "bytes32" }],
|
|
37
|
-
"payable": false,
|
|
38
|
-
"stateMutability": "view",
|
|
39
|
-
"type": "function"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"constant": true,
|
|
43
|
-
"inputs": [{ "name": "addr", "type": "address" }],
|
|
44
|
-
"name": "getEthBalance",
|
|
45
|
-
"outputs": [{ "name": "balance", "type": "uint256" }],
|
|
46
|
-
"payable": false,
|
|
47
|
-
"stateMutability": "view",
|
|
48
|
-
"type": "function"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"constant": true,
|
|
52
|
-
"inputs": [],
|
|
53
|
-
"name": "getCurrentBlockDifficulty",
|
|
54
|
-
"outputs": [{ "name": "difficulty", "type": "uint256" }],
|
|
55
|
-
"payable": false,
|
|
56
|
-
"stateMutability": "view",
|
|
57
|
-
"type": "function"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"constant": true,
|
|
61
|
-
"inputs": [],
|
|
62
|
-
"name": "getCurrentBlockGasLimit",
|
|
63
|
-
"outputs": [{ "name": "gaslimit", "type": "uint256" }],
|
|
64
|
-
"payable": false,
|
|
65
|
-
"stateMutability": "view",
|
|
66
|
-
"type": "function"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"constant": true,
|
|
70
|
-
"inputs": [],
|
|
71
|
-
"name": "getCurrentBlockCoinbase",
|
|
72
|
-
"outputs": [{ "name": "coinbase", "type": "address" }],
|
|
73
|
-
"payable": false,
|
|
74
|
-
"stateMutability": "view",
|
|
75
|
-
"type": "function"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"constant": true,
|
|
79
|
-
"inputs": [{ "name": "blockNumber", "type": "uint256" }],
|
|
80
|
-
"name": "getBlockHash",
|
|
81
|
-
"outputs": [{ "name": "blockHash", "type": "bytes32" }],
|
|
82
|
-
"payable": false,
|
|
83
|
-
"stateMutability": "view",
|
|
84
|
-
"type": "function"
|
|
85
|
-
}
|
|
86
|
-
]
|