@dydxprotocol/v4-client-js 1.1.13 → 1.1.14
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/.eslintrc.js +3 -5
- package/.prettierignore +3 -0
- package/.prettierrc.json +6 -0
- package/.telescope.json +2 -4
- package/.vscode/launch.json +10 -10
- package/README.md +3 -1
- package/__native__/__ios__/v4-native-client.js +2640 -797
- package/__tests__/helpers/constants.ts +10 -8
- package/__tests__/lib/helpers.test.ts +22 -23
- package/__tests__/lib/util.test.ts +2 -8
- package/__tests__/lib/validation.test.ts +23 -26
- package/__tests__/modules/client/Transfers.test.ts +4 -19
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -5
- package/__tests__/modules/client/constants.ts +4 -2
- package/__tests__/modules/onboarding.test.ts +9 -7
- package/build/__tests__/helpers/constants.js +7 -7
- package/build/__tests__/lib/helpers.test.js +2 -6
- package/build/__tests__/lib/util.test.js +1 -1
- package/build/__tests__/lib/validation.test.js +3 -11
- package/build/__tests__/modules/client/Transfers.test.js +1 -1
- package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
- package/build/__tests__/modules/client/constants.js +1 -1
- package/build/__tests__/modules/onboarding.test.js +2 -3
- package/build/examples/account_endpoints.js +4 -3
- package/build/examples/composite_example.js +5 -4
- package/build/examples/constants.js +1 -1
- package/build/examples/faucet_endpoint.js +4 -3
- package/build/examples/long_term_order_cancel_example.js +4 -3
- package/build/examples/markets_endpoints.js +4 -3
- package/build/examples/native_examples.js +4 -3
- package/build/examples/noble_example.js +1 -1
- package/build/examples/optimal_node.js +4 -12
- package/build/examples/short_term_order_cancel_example.js +4 -3
- package/build/examples/short_term_order_composite_example.js +4 -3
- package/build/examples/test.js +5 -4
- package/build/examples/transfer_example_deposit.js +4 -3
- package/build/examples/transfer_example_send.js +1 -1
- package/build/examples/transfer_example_subaccount_transfer.js +4 -3
- package/build/examples/transfer_example_withdraw.js +4 -3
- package/build/examples/transfer_example_withdraw_other.js +1 -1
- package/build/examples/utility_endpoints.js +4 -3
- package/build/examples/validator_get_example.js +15 -9
- package/build/examples/validator_post_example.js +4 -3
- package/build/examples/wallet_address.js +5 -4
- package/build/examples/websocket_example.js +1 -1
- package/build/src/clients/composite-client.d.ts +222 -222
- package/build/src/clients/composite-client.js +234 -228
- package/build/src/clients/constants.d.ts +3 -0
- package/build/src/clients/constants.js +6 -2
- package/build/src/clients/faucet-client.d.ts +4 -4
- package/build/src/clients/faucet-client.js +5 -5
- package/build/src/clients/helpers/chain-helpers.js +1 -1
- package/build/src/clients/helpers/request-helpers.js +5 -4
- package/build/src/clients/indexer-client.js +1 -1
- package/build/src/clients/lib/axios/axiosRequest.js +1 -1
- package/build/src/clients/lib/axios/errors.js +1 -1
- package/build/src/clients/lib/cctpProto.d.ts +2 -2
- package/build/src/clients/lib/cctpProto.js +287 -237
- package/build/src/clients/lib/errors.js +1 -1
- package/build/src/clients/modules/account.js +1 -1
- package/build/src/clients/modules/composer.d.ts +4 -0
- package/build/src/clients/modules/composer.js +39 -3
- package/build/src/clients/modules/get.d.ts +10 -3
- package/build/src/clients/modules/get.js +41 -54
- package/build/src/clients/modules/local-wallet.js +1 -1
- package/build/src/clients/modules/post.d.ts +3 -0
- package/build/src/clients/modules/post.js +34 -18
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/src/clients/modules/rest.js +1 -1
- package/build/src/clients/modules/signer.js +1 -1
- package/build/src/clients/modules/tendermintClient.d.ts +5 -5
- package/build/src/clients/modules/tendermintClient.js +6 -6
- package/build/src/clients/native.js +4 -7
- package/build/src/clients/noble-client.js +1 -1
- package/build/src/clients/socket-client.js +1 -1
- package/build/src/clients/subaccount.js +1 -1
- package/build/src/clients/types.d.ts +1 -1
- package/build/src/clients/types.js +1 -1
- package/build/src/clients/validator-client.d.ts +12 -12
- package/build/src/clients/validator-client.js +13 -13
- package/build/src/lib/errors.js +1 -1
- package/build/src/lib/onboarding.js +1 -1
- package/build/src/lib/utils.js +3 -3
- package/build/src/lib/validation.js +5 -4
- package/build/src/network_optimizer.js +10 -11
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +1 -1
- package/examples/account_endpoints.ts +5 -4
- package/examples/composite_example.ts +12 -7
- package/examples/constants.ts +10 -4
- package/examples/faucet_endpoint.ts +5 -4
- package/examples/human_readable_orders.json +85 -85
- package/examples/human_readable_short_term_orders.json +41 -41
- package/examples/long_term_order_cancel_example.ts +11 -6
- package/examples/markets_endpoints.ts +5 -4
- package/examples/native_examples.ts +8 -7
- package/examples/noble_example.ts +11 -23
- package/examples/optimal_node.ts +4 -14
- package/examples/raw_orders.json +128 -128
- package/examples/short_term_order_cancel_example.ts +7 -8
- package/examples/short_term_order_composite_example.ts +7 -8
- package/examples/test.ts +12 -7
- package/examples/transfer_example_deposit.ts +6 -9
- package/examples/transfer_example_send.ts +2 -10
- package/examples/transfer_example_subaccount_transfer.ts +6 -11
- package/examples/transfer_example_withdraw.ts +6 -9
- package/examples/transfer_example_withdraw_other.ts +1 -5
- package/examples/utility_endpoints.ts +5 -4
- package/examples/validator_get_example.ts +19 -10
- package/examples/validator_post_example.ts +7 -9
- package/examples/wallet_address.ts +6 -5
- package/examples/websocket_example.ts +5 -1
- package/package.json +4 -1
- package/src/clients/composite-client.ts +272 -329
- package/src/clients/constants.ts +38 -26
- package/src/clients/faucet-client.ts +5 -8
- package/src/clients/helpers/chain-helpers.ts +10 -6
- package/src/clients/helpers/request-helpers.ts +6 -5
- package/src/clients/indexer-client.ts +34 -34
- package/src/clients/lib/axios/axiosRequest.ts +4 -7
- package/src/clients/lib/axios/errors.ts +16 -21
- package/src/clients/lib/cctpProto.ts +655 -387
- package/src/clients/lib/errors.ts +8 -17
- package/src/clients/modules/account.ts +4 -12
- package/src/clients/modules/composer.ts +61 -20
- package/src/clients/modules/get.ts +71 -89
- package/src/clients/modules/local-wallet.ts +41 -56
- package/src/clients/modules/post.ts +664 -634
- package/src/clients/modules/proto-includes.ts +1 -0
- package/src/clients/modules/rest.ts +23 -26
- package/src/clients/modules/signer.ts +8 -22
- package/src/clients/modules/tendermintClient.ts +13 -36
- package/src/clients/native.ts +73 -139
- package/src/clients/noble-client.ts +1 -5
- package/src/clients/socket-client.ts +216 -216
- package/src/clients/subaccount.ts +16 -16
- package/src/clients/types.ts +14 -10
- package/src/clients/validator-client.ts +14 -16
- package/src/codegen/helpers.ts +149 -150
- package/src/codegen/index.ts +4 -5
- package/src/lib/errors.ts +3 -9
- package/src/lib/onboarding.ts +7 -2
- package/src/lib/utils.ts +5 -12
- package/src/lib/validation.ts +21 -19
- package/src/network_optimizer.ts +78 -65
- package/src/types.ts +5 -6
- package/tasks.json +15 -15
- package/tsconfig.eslint.json +1 -4
- package/tsconfig.json +2 -6
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
[
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
]
|
|
2
|
+
{
|
|
3
|
+
"timeInForce": "DEFAULT",
|
|
4
|
+
"side": "BUY",
|
|
5
|
+
"price": 40000
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"timeInForce": "DEFAULT",
|
|
9
|
+
"side": "SELL",
|
|
10
|
+
"price": 1000
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"timeInForce": "FOK",
|
|
14
|
+
"side": "BUY",
|
|
15
|
+
"price": 1000
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"timeInForce": "FOK",
|
|
19
|
+
"side": "SELL",
|
|
20
|
+
"price": 40000
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"timeInForce": "IOC",
|
|
24
|
+
"side": "BUY",
|
|
25
|
+
"price": 40000
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"timeInForce": "IOC",
|
|
29
|
+
"side": "SELL",
|
|
30
|
+
"price": 1000
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"timeInForce": "POST_ONLY",
|
|
34
|
+
"side": "BUY",
|
|
35
|
+
"price": 1000
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"timeInForce": "POST_ONLY",
|
|
39
|
+
"side": "SELL",
|
|
40
|
+
"price": 40000
|
|
41
|
+
}
|
|
42
|
+
]
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BECH32_PREFIX, OrderFlags } from '../src';
|
|
2
2
|
import { CompositeClient } from '../src/clients/composite-client';
|
|
3
3
|
import {
|
|
4
|
-
Network,
|
|
4
|
+
Network,
|
|
5
|
+
OrderExecution,
|
|
6
|
+
OrderSide,
|
|
7
|
+
OrderTimeInForce,
|
|
8
|
+
OrderType,
|
|
5
9
|
} from '../src/clients/constants';
|
|
6
10
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
7
11
|
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
@@ -56,7 +60,7 @@ async function test(): Promise<void> {
|
|
|
56
60
|
console.log(error.message);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
await sleep(5000);
|
|
63
|
+
await sleep(5000); // wait for placeOrder to complete
|
|
60
64
|
|
|
61
65
|
try {
|
|
62
66
|
// cancel the long term order
|
|
@@ -76,7 +80,8 @@ async function test(): Promise<void> {
|
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
test()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
test()
|
|
84
|
+
.then(() => {})
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
console.log(error.message);
|
|
87
|
+
});
|
|
@@ -49,7 +49,7 @@ async function test(): Promise<void> {
|
|
|
49
49
|
|
|
50
50
|
const sendTokenPayload = {
|
|
51
51
|
subaccountNumber: 0,
|
|
52
|
-
amount: '10',
|
|
52
|
+
amount: '10', // Dydx Token
|
|
53
53
|
recipient: 'dydx15ndn9c895f8ntck25qughtuck9spv2d9svw5qx',
|
|
54
54
|
};
|
|
55
55
|
const fees = await simulateTransferNativeToken(JSON.stringify(sendTokenPayload));
|
|
@@ -63,7 +63,7 @@ async function test(): Promise<void> {
|
|
|
63
63
|
|
|
64
64
|
const simulatePayload = {
|
|
65
65
|
subaccountNumber: 0,
|
|
66
|
-
amount: 20,
|
|
66
|
+
amount: 20, // In USDC i.e. $20.00
|
|
67
67
|
};
|
|
68
68
|
let stdFee = await simulateWithdraw(JSON.stringify(simulatePayload));
|
|
69
69
|
console.log(stdFee);
|
|
@@ -114,7 +114,7 @@ async function test(): Promise<void> {
|
|
|
114
114
|
}`;
|
|
115
115
|
console.log(squidPayload);
|
|
116
116
|
|
|
117
|
-
const encode = (str: string):string => Buffer.from(str, 'binary').toString('base64');
|
|
117
|
+
const encode = (str: string): string => Buffer.from(str, 'binary').toString('base64');
|
|
118
118
|
const encoded = encode(squidPayload);
|
|
119
119
|
|
|
120
120
|
tx = await withdrawToIBC(0, '13', encoded);
|
|
@@ -124,10 +124,11 @@ async function test(): Promise<void> {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
test()
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
test()
|
|
128
|
+
.then(() => {})
|
|
129
|
+
.catch((error) => {
|
|
130
|
+
console.log(error.message);
|
|
131
|
+
});
|
|
131
132
|
|
|
132
133
|
const error = new UserError('client is not connected. Call connectClient() first');
|
|
133
134
|
const text = wrappedError(error);
|
|
@@ -10,18 +10,10 @@ import { sleep } from '../src/lib/utils';
|
|
|
10
10
|
import { DYDX_TEST_MNEMONIC } from './constants';
|
|
11
11
|
|
|
12
12
|
async function test(): Promise<void> {
|
|
13
|
-
const dydxClient = await ValidatorClient.connect(
|
|
14
|
-
Network.testnet().validatorConfig,
|
|
15
|
-
);
|
|
13
|
+
const dydxClient = await ValidatorClient.connect(Network.testnet().validatorConfig);
|
|
16
14
|
|
|
17
|
-
const dydxWallet = await LocalWallet.fromMnemonic(
|
|
18
|
-
|
|
19
|
-
BECH32_PREFIX,
|
|
20
|
-
);
|
|
21
|
-
const nobleWallet = await LocalWallet.fromMnemonic(
|
|
22
|
-
DYDX_TEST_MNEMONIC,
|
|
23
|
-
NOBLE_BECH32_PREFIX,
|
|
24
|
-
);
|
|
15
|
+
const dydxWallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
|
|
16
|
+
const nobleWallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, NOBLE_BECH32_PREFIX);
|
|
25
17
|
|
|
26
18
|
const client = new NobleClient('https://rpc.testnet.noble.strange.love', 'Noble example');
|
|
27
19
|
await client.connect(nobleWallet);
|
|
@@ -38,21 +30,17 @@ async function test(): Promise<void> {
|
|
|
38
30
|
sourcePort: 'transfer',
|
|
39
31
|
sourceChannel: 'channel-0',
|
|
40
32
|
token: {
|
|
41
|
-
denom:
|
|
42
|
-
'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
33
|
+
denom: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
43
34
|
amount: '1000000',
|
|
44
35
|
},
|
|
45
36
|
sender: dydxWallet.address,
|
|
46
37
|
receiver: nobleWallet.address,
|
|
47
|
-
timeoutTimestamp: Long.fromNumber(
|
|
48
|
-
Math.floor(Date.now() / 1000) * 1e9 + 10 * 60 * 1e9,
|
|
49
|
-
),
|
|
38
|
+
timeoutTimestamp: Long.fromNumber(Math.floor(Date.now() / 1000) * 1e9 + 10 * 60 * 1e9),
|
|
50
39
|
},
|
|
51
40
|
};
|
|
52
41
|
|
|
53
42
|
const msgs = [ibcToNobleMsg];
|
|
54
|
-
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs)
|
|
55
|
-
);
|
|
43
|
+
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
|
|
56
44
|
|
|
57
45
|
await dydxClient.post.send(
|
|
58
46
|
dydxWallet,
|
|
@@ -84,15 +72,15 @@ async function test(): Promise<void> {
|
|
|
84
72
|
},
|
|
85
73
|
sender: nobleWallet.address,
|
|
86
74
|
receiver: dydxWallet.address,
|
|
87
|
-
timeoutTimestamp: Long.fromNumber(
|
|
88
|
-
Math.floor(Date.now() / 1000) * 1e9 + 10 * 60 * 1e9,
|
|
89
|
-
),
|
|
75
|
+
timeoutTimestamp: Long.fromNumber(Math.floor(Date.now() / 1000) * 1e9 + 10 * 60 * 1e9),
|
|
90
76
|
},
|
|
91
77
|
};
|
|
92
78
|
const fee = await client.simulateTransaction([ibcFromNobleMsg]);
|
|
93
79
|
|
|
94
|
-
ibcFromNobleMsg.value.token.amount = (
|
|
95
|
-
|
|
80
|
+
ibcFromNobleMsg.value.token.amount = (
|
|
81
|
+
parseInt(ibcFromNobleMsg.value.token.amount, 10) -
|
|
82
|
+
Math.floor(parseInt(fee.amount[0].amount, 10) * 1.4)
|
|
83
|
+
).toString();
|
|
96
84
|
|
|
97
85
|
await client.send([ibcFromNobleMsg]);
|
|
98
86
|
} catch (error) {
|
package/examples/optimal_node.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TESTNET_CHAIN_ID,
|
|
3
|
-
} from '../src/clients/constants';
|
|
1
|
+
import { TESTNET_CHAIN_ID } from '../src/clients/constants';
|
|
4
2
|
import { NetworkOptimizer } from '../src/network_optimizer';
|
|
5
3
|
|
|
6
4
|
async function testNodes(): Promise<void> {
|
|
@@ -37,10 +35,7 @@ async function testNodes(): Promise<void> {
|
|
|
37
35
|
|
|
38
36
|
try {
|
|
39
37
|
const optimizer = new NetworkOptimizer();
|
|
40
|
-
const endpoints = [
|
|
41
|
-
'https://example.com',
|
|
42
|
-
'https://example.org',
|
|
43
|
-
];
|
|
38
|
+
const endpoints = ['https://example.com', 'https://example.org'];
|
|
44
39
|
const optimal = await optimizer.findOptimalNode(endpoints, TESTNET_CHAIN_ID);
|
|
45
40
|
console.log(optimal);
|
|
46
41
|
} catch (error) {
|
|
@@ -52,9 +47,7 @@ async function testIndexers(): Promise<void> {
|
|
|
52
47
|
// all valid endpoints
|
|
53
48
|
try {
|
|
54
49
|
const optimizer = new NetworkOptimizer();
|
|
55
|
-
const endpoints = [
|
|
56
|
-
'https://indexer.v4testnet2.dydx.exchange',
|
|
57
|
-
];
|
|
50
|
+
const endpoints = ['https://indexer.v4testnet2.dydx.exchange'];
|
|
58
51
|
const optimal = await optimizer.findOptimalIndexer(endpoints);
|
|
59
52
|
console.log(optimal);
|
|
60
53
|
} catch (error) {
|
|
@@ -65,10 +58,7 @@ async function testIndexers(): Promise<void> {
|
|
|
65
58
|
|
|
66
59
|
try {
|
|
67
60
|
const optimizer = new NetworkOptimizer();
|
|
68
|
-
const endpoints = [
|
|
69
|
-
'https://example.com',
|
|
70
|
-
'https://example.org',
|
|
71
|
-
];
|
|
61
|
+
const endpoints = ['https://example.com', 'https://example.org'];
|
|
72
62
|
const optimal = await optimizer.findOptimalIndexer(endpoints);
|
|
73
63
|
console.log(optimal);
|
|
74
64
|
} catch (error) {
|
package/examples/raw_orders.json
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
1
|
[
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
2
|
+
{
|
|
3
|
+
"timeInForce": 0,
|
|
4
|
+
"reduceOnly": false,
|
|
5
|
+
"orderFlags": 64,
|
|
6
|
+
"side": 1,
|
|
7
|
+
"quantums": 10000000,
|
|
8
|
+
"subticks": 40000000000
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"timeInForce": 2,
|
|
12
|
+
"reduceOnly": false,
|
|
13
|
+
"orderFlags": 64,
|
|
14
|
+
"side": 1,
|
|
15
|
+
"quantums": 10000000,
|
|
16
|
+
"subticks": 40000000000
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"timeInForce": 0,
|
|
20
|
+
"reduceOnly": true,
|
|
21
|
+
"orderFlags": 64,
|
|
22
|
+
"side": 1,
|
|
23
|
+
"quantums": 10000000,
|
|
24
|
+
"subticks": 40000000000
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"timeInForce": 2,
|
|
28
|
+
"reduceOnly": true,
|
|
29
|
+
"orderFlags": 64,
|
|
30
|
+
"side": 1,
|
|
31
|
+
"quantums": 10000000,
|
|
32
|
+
"subticks": 40000000000
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"timeInForce": 1,
|
|
36
|
+
"reduceOnly": false,
|
|
37
|
+
"orderFlags": 0,
|
|
38
|
+
"side": 1,
|
|
39
|
+
"quantums": 10000000,
|
|
40
|
+
"subticks": 40000000000
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"timeInForce": 1,
|
|
44
|
+
"reduceOnly": true,
|
|
45
|
+
"orderFlags": 0,
|
|
46
|
+
"side": 1,
|
|
47
|
+
"quantums": 10000000,
|
|
48
|
+
"subticks": 40000000000
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"timeInForce": 3,
|
|
52
|
+
"reduceOnly": false,
|
|
53
|
+
"orderFlags": 0,
|
|
54
|
+
"side": 1,
|
|
55
|
+
"quantums": 10000000,
|
|
56
|
+
"subticks": 40000000000
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"timeInForce": 3,
|
|
60
|
+
"reduceOnly": true,
|
|
61
|
+
"orderFlags": 0,
|
|
62
|
+
"side": 1,
|
|
63
|
+
"quantums": 10000000,
|
|
64
|
+
"subticks": 40000000000
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"timeInForce": 0,
|
|
68
|
+
"reduceOnly": false,
|
|
69
|
+
"orderFlags": 64,
|
|
70
|
+
"side": 2,
|
|
71
|
+
"quantums": 10000000,
|
|
72
|
+
"subticks": 1000000000
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"timeInForce": 2,
|
|
76
|
+
"reduceOnly": false,
|
|
77
|
+
"orderFlags": 64,
|
|
78
|
+
"side": 2,
|
|
79
|
+
"quantums": 10000000,
|
|
80
|
+
"subticks": 1000000000
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"timeInForce": 0,
|
|
84
|
+
"reduceOnly": true,
|
|
85
|
+
"orderFlags": 64,
|
|
86
|
+
"side": 2,
|
|
87
|
+
"quantums": 10000000,
|
|
88
|
+
"subticks": 1000000000
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"timeInForce": 2,
|
|
92
|
+
"reduceOnly": true,
|
|
93
|
+
"orderFlags": 64,
|
|
94
|
+
"side": 2,
|
|
95
|
+
"quantums": 10000000,
|
|
96
|
+
"subticks": 1000000000
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"timeInForce": 1,
|
|
100
|
+
"reduceOnly": false,
|
|
101
|
+
"orderFlags": 0,
|
|
102
|
+
"side": 2,
|
|
103
|
+
"quantums": 10000000,
|
|
104
|
+
"subticks": 1000000000
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"timeInForce": 1,
|
|
108
|
+
"reduceOnly": true,
|
|
109
|
+
"orderFlags": 0,
|
|
110
|
+
"side": 2,
|
|
111
|
+
"quantums": 10000000,
|
|
112
|
+
"subticks": 1000000000
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"timeInForce": 3,
|
|
116
|
+
"reduceOnly": false,
|
|
117
|
+
"orderFlags": 0,
|
|
118
|
+
"side": 2,
|
|
119
|
+
"quantums": 10000000,
|
|
120
|
+
"subticks": 1000000000
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"timeInForce": 3,
|
|
124
|
+
"reduceOnly": true,
|
|
125
|
+
"orderFlags": 0,
|
|
126
|
+
"side": 2,
|
|
127
|
+
"quantums": 10000000,
|
|
128
|
+
"subticks": 1000000000
|
|
129
|
+
}
|
|
130
130
|
]
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { BECH32_PREFIX, OrderFlags, Order_TimeInForce } from '../src';
|
|
2
2
|
import { CompositeClient } from '../src/clients/composite-client';
|
|
3
|
-
import {
|
|
4
|
-
Network, OrderSide,
|
|
5
|
-
} from '../src/clients/constants';
|
|
3
|
+
import { Network, OrderSide } from '../src/clients/constants';
|
|
6
4
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
7
5
|
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
8
6
|
import { randomInt, sleep } from '../src/lib/utils';
|
|
@@ -43,7 +41,7 @@ async function test(): Promise<void> {
|
|
|
43
41
|
console.log(error.message);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
await sleep(5000);
|
|
44
|
+
await sleep(5000); // wait for placeOrder to complete
|
|
47
45
|
|
|
48
46
|
try {
|
|
49
47
|
// cancel the short term order
|
|
@@ -63,7 +61,8 @@ async function test(): Promise<void> {
|
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
test()
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
test()
|
|
65
|
+
.then(() => {})
|
|
66
|
+
.catch((error) => {
|
|
67
|
+
console.log(error.message);
|
|
68
|
+
});
|
|
@@ -2,9 +2,7 @@ import { Order_TimeInForce } from '@dydxprotocol/v4-proto/src/codegen/dydxprotoc
|
|
|
2
2
|
|
|
3
3
|
import { BECH32_PREFIX } from '../src';
|
|
4
4
|
import { CompositeClient } from '../src/clients/composite-client';
|
|
5
|
-
import {
|
|
6
|
-
Network, OrderExecution, OrderSide,
|
|
7
|
-
} from '../src/clients/constants';
|
|
5
|
+
import { Network, OrderExecution, OrderSide } from '../src/clients/constants';
|
|
8
6
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
9
7
|
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
10
8
|
import { randomInt } from '../src/lib/utils';
|
|
@@ -56,7 +54,7 @@ async function test(): Promise<void> {
|
|
|
56
54
|
console.log(error.message);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
await sleep(5000);
|
|
57
|
+
await sleep(5000); // wait for placeOrder to complete
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
|
|
@@ -75,7 +73,8 @@ function orderExecutionToTimeInForce(orderExecution: string): Order_TimeInForce
|
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
test()
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
test()
|
|
77
|
+
.then(() => {})
|
|
78
|
+
.catch((error) => {
|
|
79
|
+
console.log(error.message);
|
|
80
|
+
});
|
package/examples/test.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BECH32_PREFIX } from '../src';
|
|
2
2
|
import { CompositeClient } from '../src/clients/composite-client';
|
|
3
3
|
import {
|
|
4
|
-
Network,
|
|
4
|
+
Network,
|
|
5
|
+
OrderExecution,
|
|
6
|
+
OrderSide,
|
|
7
|
+
OrderTimeInForce,
|
|
8
|
+
OrderType,
|
|
5
9
|
} from '../src/clients/constants';
|
|
6
10
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
7
11
|
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
@@ -28,7 +32,7 @@ async function test(): Promise<void> {
|
|
|
28
32
|
const timeInForceString = orderParams.timeInForce ?? 'GTT';
|
|
29
33
|
const timeInForce = OrderTimeInForce[timeInForceString as keyof typeof OrderTimeInForce];
|
|
30
34
|
const price = orderParams.price ?? 1350;
|
|
31
|
-
const timeInForceSeconds =
|
|
35
|
+
const timeInForceSeconds = timeInForce === OrderTimeInForce.GTT ? 60 : 0;
|
|
32
36
|
const postOnly = orderParams.postOnly ?? false;
|
|
33
37
|
const tx = await client.placeOrder(
|
|
34
38
|
subaccount,
|
|
@@ -50,11 +54,12 @@ async function test(): Promise<void> {
|
|
|
50
54
|
console.log(error.message);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
await sleep(5000);
|
|
57
|
+
await sleep(5000); // wait for placeOrder to complete
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
test()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
test()
|
|
62
|
+
.then(() => {})
|
|
63
|
+
.catch((error) => {
|
|
64
|
+
console.log(error.message);
|
|
65
|
+
});
|