@d8x/perpetuals-sdk 0.0.16 → 0.0.18
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 +7 -17
- package/dist/marketData.js +13 -18
- package/dist/perpetualDataHandler.js +9 -8
- package/dist/writeAccessHandler.d.ts +3 -2
- package/dist/writeAccessHandler.js +9 -3
- package/package.json +1 -1
- package/src/marketData.ts +12 -18
- package/src/perpetualDataHandler.ts +3 -3
- package/src/writeAccessHandler.ts +8 -3
package/dist/marketData.d.ts
CHANGED
|
@@ -29,7 +29,13 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
29
29
|
*
|
|
30
30
|
*/
|
|
31
31
|
constructor(config: NodeSDKConfig);
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the marketData-Class with this function
|
|
34
|
+
* to create instance of D8X perpetual contract and gather information
|
|
35
|
+
* about perpetual currencies
|
|
36
|
+
* @param provider optional provider
|
|
37
|
+
*/
|
|
38
|
+
createProxyInstance(provider?: ethers.providers.JsonRpcProvider): Promise<void>;
|
|
33
39
|
/**
|
|
34
40
|
* Get contract instance. Useful for event listening.
|
|
35
41
|
* @example
|
|
@@ -73,14 +79,6 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
73
79
|
* @param {string} traderAddr Address of the trader for which we get the open orders.
|
|
74
80
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
75
81
|
* @example
|
|
76
|
-
* // Setup
|
|
77
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
78
|
-
* let mktData = new MarketData(config);
|
|
79
|
-
* await mktData.createProxyInstance();
|
|
80
|
-
* // Get all open orders for a trader/symbol
|
|
81
|
-
* let opOrder = await mktData.openOrders("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
82
|
-
* "ETH-USD-MATIC");
|
|
83
|
-
* @example
|
|
84
82
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
85
83
|
* async function main() {
|
|
86
84
|
* console.log(MarketData);
|
|
@@ -106,14 +104,6 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
106
104
|
* @param {string} traderAddr Address of the trader for which we get the position risk.
|
|
107
105
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
108
106
|
* @example
|
|
109
|
-
* // Setup
|
|
110
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
111
|
-
* let mktData = new MarketData(config);
|
|
112
|
-
* await mktData.createProxyInstance();
|
|
113
|
-
* // Get position risk info
|
|
114
|
-
* let posRisk = await mktData.positionRisk("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
115
|
-
* "ETH-USD-MATIC");
|
|
116
|
-
* @example
|
|
117
107
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
118
108
|
* async function main() {
|
|
119
109
|
* console.log(MarketData);
|
package/dist/marketData.js
CHANGED
|
@@ -46,9 +46,20 @@ class MarketData extends perpetualDataHandler_1.default {
|
|
|
46
46
|
constructor(config) {
|
|
47
47
|
super(config);
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Initialize the marketData-Class with this function
|
|
51
|
+
* to create instance of D8X perpetual contract and gather information
|
|
52
|
+
* about perpetual currencies
|
|
53
|
+
* @param provider optional provider
|
|
54
|
+
*/
|
|
55
|
+
createProxyInstance(provider) {
|
|
50
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
|
|
57
|
+
if (provider == undefined) {
|
|
58
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider(this.nodeURL);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.provider = provider;
|
|
62
|
+
}
|
|
52
63
|
yield this.initContractsAndData(this.provider);
|
|
53
64
|
});
|
|
54
65
|
}
|
|
@@ -107,14 +118,6 @@ class MarketData extends perpetualDataHandler_1.default {
|
|
|
107
118
|
* @param {string} traderAddr Address of the trader for which we get the open orders.
|
|
108
119
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
109
120
|
* @example
|
|
110
|
-
* // Setup
|
|
111
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
112
|
-
* let mktData = new MarketData(config);
|
|
113
|
-
* await mktData.createProxyInstance();
|
|
114
|
-
* // Get all open orders for a trader/symbol
|
|
115
|
-
* let opOrder = await mktData.openOrders("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
116
|
-
* "ETH-USD-MATIC");
|
|
117
|
-
* @example
|
|
118
121
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
119
122
|
* async function main() {
|
|
120
123
|
* console.log(MarketData);
|
|
@@ -147,14 +150,6 @@ class MarketData extends perpetualDataHandler_1.default {
|
|
|
147
150
|
* @param {string} traderAddr Address of the trader for which we get the position risk.
|
|
148
151
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
149
152
|
* @example
|
|
150
|
-
* // Setup
|
|
151
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
152
|
-
* let mktData = new MarketData(config);
|
|
153
|
-
* await mktData.createProxyInstance();
|
|
154
|
-
* // Get position risk info
|
|
155
|
-
* let posRisk = await mktData.positionRisk("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
156
|
-
* "ETH-USD-MATIC");
|
|
157
|
-
* @example
|
|
158
153
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
159
154
|
* async function main() {
|
|
160
155
|
* console.log(MarketData);
|
|
@@ -416,8 +416,6 @@ class PerpetualDataHandler {
|
|
|
416
416
|
}
|
|
417
417
|
let iDeadline = order.deadline == undefined ? Date.now() / 1000 + nodeSDKTypes_1.ORDER_MAX_DURATION_SEC : order.deadline;
|
|
418
418
|
let fTriggerPrice = order.stopPrice == undefined ? ethers_1.BigNumber.from(0) : (0, d8XMath_1.floatToABK64x64)(order.stopPrice);
|
|
419
|
-
if (order.reduceOnly != undefined && order.reduceOnly == true) {
|
|
420
|
-
}
|
|
421
419
|
let smOrder = {
|
|
422
420
|
flags: flags,
|
|
423
421
|
iPerpetualId: ethers_1.BigNumber.from(perpetualId),
|
|
@@ -436,15 +434,17 @@ class PerpetualDataHandler {
|
|
|
436
434
|
return smOrder;
|
|
437
435
|
}
|
|
438
436
|
static _flagToOrderType(order) {
|
|
439
|
-
let
|
|
440
|
-
let
|
|
441
|
-
|
|
437
|
+
let flag = ethers_1.BigNumber.from(order.flags);
|
|
438
|
+
let isLimit = (0, utils_1.containsFlag)(flag, nodeSDKTypes_1.MASK_LIMIT_ORDER);
|
|
439
|
+
let hasLimit = !ethers_1.BigNumber.from(order.fLimitPrice).eq(0) || !ethers_1.BigNumber.from(order.fLimitPrice).eq(nodeSDKTypes_1.MAX_64x64);
|
|
440
|
+
let isStop = (0, utils_1.containsFlag)(flag, nodeSDKTypes_1.MASK_STOP_ORDER);
|
|
441
|
+
if (isStop && hasLimit) {
|
|
442
442
|
return nodeSDKTypes_1.ORDER_TYPE_STOP_LIMIT;
|
|
443
443
|
}
|
|
444
|
-
else if (
|
|
444
|
+
else if (isStop && !hasLimit) {
|
|
445
445
|
return nodeSDKTypes_1.ORDER_TYPE_STOP_MARKET;
|
|
446
446
|
}
|
|
447
|
-
else if (
|
|
447
|
+
else if (isLimit && !isStop) {
|
|
448
448
|
return nodeSDKTypes_1.ORDER_TYPE_LIMIT;
|
|
449
449
|
}
|
|
450
450
|
else {
|
|
@@ -459,6 +459,7 @@ class PerpetualDataHandler {
|
|
|
459
459
|
*/
|
|
460
460
|
static _orderTypeToFlag(order) {
|
|
461
461
|
let flag;
|
|
462
|
+
order.type = order.type.toUpperCase();
|
|
462
463
|
switch (order.type) {
|
|
463
464
|
case nodeSDKTypes_1.ORDER_TYPE_LIMIT:
|
|
464
465
|
flag = nodeSDKTypes_1.MASK_LIMIT_ORDER;
|
|
@@ -491,7 +492,7 @@ class PerpetualDataHandler {
|
|
|
491
492
|
if ((order.type == nodeSDKTypes_1.ORDER_TYPE_MARKET || order.type == nodeSDKTypes_1.ORDER_TYPE_LIMIT) && order.stopPrice != undefined) {
|
|
492
493
|
throw Error(`Order type ${order.type} has no trigger price.`);
|
|
493
494
|
}
|
|
494
|
-
if (order.type != nodeSDKTypes_1.
|
|
495
|
+
if (order.type != nodeSDKTypes_1.ORDER_TYPE_STOP_LIMIT && order.type != nodeSDKTypes_1.ORDER_TYPE_STOP_MARKET && order.stopPrice != undefined) {
|
|
495
496
|
throw Error(`Order type ${order.type} has no trigger price.`);
|
|
496
497
|
}
|
|
497
498
|
return flag;
|
|
@@ -21,11 +21,12 @@ export default class WriteAccessHandler extends PerpetualDataHandler {
|
|
|
21
21
|
*/
|
|
22
22
|
constructor(config: NodeSDKConfig, privateKey: string);
|
|
23
23
|
/**
|
|
24
|
-
* Initialize the
|
|
24
|
+
* Initialize the writeAccessHandler-Class with this function
|
|
25
25
|
* to create instance of D8X perpetual contract and gather information
|
|
26
26
|
* about perpetual currencies
|
|
27
|
+
* @param provider optional provider
|
|
27
28
|
*/
|
|
28
|
-
createProxyInstance(): Promise<void>;
|
|
29
|
+
createProxyInstance(provider?: ethers.providers.JsonRpcProvider): Promise<void>;
|
|
29
30
|
/**
|
|
30
31
|
* Set allowance for ar margin token (e.g., MATIC, ETH, USDC)
|
|
31
32
|
* @param symbol token in 'long-form' such as MATIC, symbol also fine (ETH-USD-MATIC)
|
|
@@ -42,13 +42,19 @@ class WriteAccessHandler extends perpetualDataHandler_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Initialize the
|
|
45
|
+
* Initialize the writeAccessHandler-Class with this function
|
|
46
46
|
* to create instance of D8X perpetual contract and gather information
|
|
47
47
|
* about perpetual currencies
|
|
48
|
+
* @param provider optional provider
|
|
48
49
|
*/
|
|
49
|
-
createProxyInstance() {
|
|
50
|
+
createProxyInstance(provider) {
|
|
50
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
|
|
52
|
+
if (provider == undefined) {
|
|
53
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider(this.nodeURL);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.provider = provider;
|
|
57
|
+
}
|
|
52
58
|
const wallet = new ethers_1.ethers.Wallet(this.privateKey);
|
|
53
59
|
this.signer = wallet.connect(this.provider);
|
|
54
60
|
yield this.initContractsAndData(this.signer);
|
package/package.json
CHANGED
package/src/marketData.ts
CHANGED
|
@@ -45,8 +45,18 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
45
45
|
super(config);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Initialize the marketData-Class with this function
|
|
50
|
+
* to create instance of D8X perpetual contract and gather information
|
|
51
|
+
* about perpetual currencies
|
|
52
|
+
* @param provider optional provider
|
|
53
|
+
*/
|
|
54
|
+
public async createProxyInstance(provider?: ethers.providers.JsonRpcProvider) {
|
|
55
|
+
if (provider == undefined) {
|
|
56
|
+
this.provider = new ethers.providers.JsonRpcProvider(this.nodeURL);
|
|
57
|
+
} else {
|
|
58
|
+
this.provider = provider;
|
|
59
|
+
}
|
|
50
60
|
await this.initContractsAndData(this.provider);
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -105,14 +115,6 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
105
115
|
* @param {string} traderAddr Address of the trader for which we get the open orders.
|
|
106
116
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
107
117
|
* @example
|
|
108
|
-
* // Setup
|
|
109
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
110
|
-
* let mktData = new MarketData(config);
|
|
111
|
-
* await mktData.createProxyInstance();
|
|
112
|
-
* // Get all open orders for a trader/symbol
|
|
113
|
-
* let opOrder = await mktData.openOrders("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
114
|
-
* "ETH-USD-MATIC");
|
|
115
|
-
* @example
|
|
116
118
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
117
119
|
* async function main() {
|
|
118
120
|
* console.log(MarketData);
|
|
@@ -144,14 +146,6 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
144
146
|
* @param {string} traderAddr Address of the trader for which we get the position risk.
|
|
145
147
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
146
148
|
* @example
|
|
147
|
-
* // Setup
|
|
148
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
149
|
-
* let mktData = new MarketData(config);
|
|
150
|
-
* await mktData.createProxyInstance();
|
|
151
|
-
* // Get position risk info
|
|
152
|
-
* let posRisk = await mktData.positionRisk("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
153
|
-
* "ETH-USD-MATIC");
|
|
154
|
-
* @example
|
|
155
149
|
* import { MarketData, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
156
150
|
* async function main() {
|
|
157
151
|
* console.log(MarketData);
|
|
@@ -502,8 +502,7 @@ export default class PerpetualDataHandler {
|
|
|
502
502
|
|
|
503
503
|
let iDeadline = order.deadline == undefined ? Date.now() / 1000 + ORDER_MAX_DURATION_SEC : order.deadline;
|
|
504
504
|
let fTriggerPrice = order.stopPrice == undefined ? BigNumber.from(0) : floatToABK64x64(order.stopPrice);
|
|
505
|
-
|
|
506
|
-
}
|
|
505
|
+
|
|
507
506
|
let smOrder: SmartContractOrder = {
|
|
508
507
|
flags: flags,
|
|
509
508
|
iPerpetualId: BigNumber.from(perpetualId),
|
|
@@ -547,6 +546,7 @@ export default class PerpetualDataHandler {
|
|
|
547
546
|
*/
|
|
548
547
|
private static _orderTypeToFlag(order: Order): BigNumber {
|
|
549
548
|
let flag: BigNumber;
|
|
549
|
+
order.type = order.type.toUpperCase();
|
|
550
550
|
switch (order.type) {
|
|
551
551
|
case ORDER_TYPE_LIMIT:
|
|
552
552
|
flag = MASK_LIMIT_ORDER;
|
|
@@ -579,7 +579,7 @@ export default class PerpetualDataHandler {
|
|
|
579
579
|
if ((order.type == ORDER_TYPE_MARKET || order.type == ORDER_TYPE_LIMIT) && order.stopPrice != undefined) {
|
|
580
580
|
throw Error(`Order type ${order.type} has no trigger price.`);
|
|
581
581
|
}
|
|
582
|
-
if (order.type !=
|
|
582
|
+
if (order.type != ORDER_TYPE_STOP_LIMIT && order.type != ORDER_TYPE_STOP_MARKET && order.stopPrice != undefined) {
|
|
583
583
|
throw Error(`Order type ${order.type} has no trigger price.`);
|
|
584
584
|
}
|
|
585
585
|
return flag;
|
|
@@ -31,12 +31,17 @@ export default class WriteAccessHandler extends PerpetualDataHandler {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Initialize the
|
|
34
|
+
* Initialize the writeAccessHandler-Class with this function
|
|
35
35
|
* to create instance of D8X perpetual contract and gather information
|
|
36
36
|
* about perpetual currencies
|
|
37
|
+
* @param provider optional provider
|
|
37
38
|
*/
|
|
38
|
-
public async createProxyInstance() {
|
|
39
|
-
|
|
39
|
+
public async createProxyInstance(provider?: ethers.providers.JsonRpcProvider) {
|
|
40
|
+
if (provider == undefined) {
|
|
41
|
+
this.provider = new ethers.providers.JsonRpcProvider(this.nodeURL);
|
|
42
|
+
} else {
|
|
43
|
+
this.provider = provider;
|
|
44
|
+
}
|
|
40
45
|
const wallet = new ethers.Wallet(this.privateKey);
|
|
41
46
|
this.signer = wallet.connect(this.provider);
|
|
42
47
|
await this.initContractsAndData(this.signer);
|