@dydxprotocol/v4-client-js 3.4.0 → 3.5.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/.nvmrc +1 -1
- package/__native__/__ios__/v4-native-client.js +109 -29
- package/__tests__/modules/client/AccountEndpoints.test.ts +68 -0
- package/build/cjs/__tests__/modules/client/AccountEndpoints.test.js +47 -1
- package/build/cjs/examples/account_endpoints.js +15 -1
- package/build/cjs/src/clients/composite-client.js +14 -7
- package/build/cjs/src/clients/constants.js +3 -1
- package/build/cjs/src/clients/helpers/chain-helpers.js +8 -1
- package/build/cjs/src/clients/modules/account.js +10 -1
- package/build/cjs/src/clients/types.js +3 -1
- package/build/cjs/src/lib/validation.js +5 -3
- package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/esm/__tests__/modules/client/AccountEndpoints.test.js +47 -1
- package/build/esm/examples/account_endpoints.js +15 -1
- package/build/esm/src/clients/composite-client.d.ts +9 -3
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +14 -7
- package/build/esm/src/clients/constants.d.ts +3 -1
- package/build/esm/src/clients/constants.d.ts.map +1 -1
- package/build/esm/src/clients/constants.js +3 -1
- package/build/esm/src/clients/helpers/chain-helpers.d.ts.map +1 -1
- package/build/esm/src/clients/helpers/chain-helpers.js +8 -1
- package/build/esm/src/clients/modules/account.d.ts +2 -0
- package/build/esm/src/clients/modules/account.d.ts.map +1 -1
- package/build/esm/src/clients/modules/account.js +10 -1
- package/build/esm/src/clients/types.d.ts +3 -1
- package/build/esm/src/clients/types.d.ts.map +1 -1
- package/build/esm/src/clients/types.js +3 -1
- package/build/esm/src/lib/validation.d.ts.map +1 -1
- package/build/esm/src/lib/validation.js +5 -3
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/examples/account_endpoints.ts +14 -0
- package/package.json +1 -1
- package/scripts/publish-if-not-exists.sh +33 -14
- package/src/clients/composite-client.ts +17 -2
- package/src/clients/constants.ts +2 -0
- package/src/clients/helpers/chain-helpers.ts +11 -0
- package/src/clients/modules/account.ts +26 -0
- package/src/clients/types.ts +2 -0
- package/src/lib/validation.ts +4 -2
- package/CHANGELOG.md +0 -6
|
@@ -120,6 +120,20 @@ async function test(): Promise<void> {
|
|
|
120
120
|
} catch (error) {
|
|
121
121
|
console.log(error.message);
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
// Get trade history
|
|
125
|
+
try {
|
|
126
|
+
const response = await client.account.getSubaccountTradeHistory(address, 0);
|
|
127
|
+
console.log(response);
|
|
128
|
+
const trades = response.tradeHistory;
|
|
129
|
+
console.log(trades);
|
|
130
|
+
if (trades.length > 0) {
|
|
131
|
+
const trade0 = trades[0];
|
|
132
|
+
console.log(trade0);
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.log(error.message);
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
test()
|
package/package.json
CHANGED
|
@@ -1,21 +1,40 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
3
|
|
|
4
|
-
VERSION=$(
|
|
5
|
-
NAME=$(
|
|
4
|
+
VERSION=$(jq -r '.version' package.json)
|
|
5
|
+
NAME=$(jq -r '.name' package.json)
|
|
6
|
+
TAG="v${VERSION}"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
if [ $? -eq 0 ]; then
|
|
9
|
-
set -e
|
|
8
|
+
echo "Checking npm registry for ${NAME}@${VERSION}..."
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
set +e
|
|
11
|
+
VIEW_OUTPUT=$(npm view "${NAME}@${VERSION}" 2>&1)
|
|
12
|
+
VIEW_EXIT=$?
|
|
13
|
+
set -e
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if [ $VIEW_EXIT -eq 0 ]; then
|
|
16
|
+
echo "Skipping publish: ${NAME}@${VERSION} already exists"
|
|
17
|
+
exit 0
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
if ! echo "$VIEW_OUTPUT" | grep -qiE 'E404|not found|No matching version'; then
|
|
21
|
+
echo "Registry check failed unexpectedly:"
|
|
22
|
+
echo "$VIEW_OUTPUT"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
echo "Version not found. Proceeding with release."
|
|
27
|
+
|
|
28
|
+
git fetch --tags --quiet
|
|
29
|
+
git config user.email "ci@dydx.exchange"
|
|
30
|
+
git config user.name "github_actions"
|
|
31
|
+
|
|
32
|
+
if git show-ref --tags --verify --quiet "refs/tags/$TAG"; then
|
|
33
|
+
echo "Tag $TAG already exists"
|
|
19
34
|
else
|
|
20
|
-
|
|
35
|
+
git tag -a "$TAG" -m "Release $TAG"
|
|
36
|
+
git push origin "$TAG"
|
|
21
37
|
fi
|
|
38
|
+
|
|
39
|
+
unset NODE_AUTH_TOKEN
|
|
40
|
+
npm publish --provenance --access public
|
|
@@ -321,6 +321,8 @@ export class CompositeClient {
|
|
|
321
321
|
* @param timeInForce The time in force of the order to place
|
|
322
322
|
* @param goodTilBlock The goodTilBlock of the order to place
|
|
323
323
|
* @param reduceOnly The reduceOnly of the order to place
|
|
324
|
+
* @param builderCodeParameters The builder code parameters of the order to place.
|
|
325
|
+
* @param orderRouterAddress The order router address of the order to place.
|
|
324
326
|
*
|
|
325
327
|
*
|
|
326
328
|
* @throws UnexpectedClientError if a malformed response is returned with no GRPC error
|
|
@@ -338,6 +340,8 @@ export class CompositeClient {
|
|
|
338
340
|
timeInForce: Order_TimeInForce,
|
|
339
341
|
reduceOnly: boolean,
|
|
340
342
|
memo?: string,
|
|
343
|
+
builderCodeParameters?: IBuilderCodeParameters,
|
|
344
|
+
orderRouterAddress?: string,
|
|
341
345
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
342
346
|
const msgs: Promise<EncodeObject[]> = new Promise((resolve, reject) => {
|
|
343
347
|
const msg = this.placeShortTermOrderMessage(
|
|
@@ -350,6 +354,8 @@ export class CompositeClient {
|
|
|
350
354
|
goodTilBlock,
|
|
351
355
|
timeInForce,
|
|
352
356
|
reduceOnly,
|
|
357
|
+
builderCodeParameters,
|
|
358
|
+
orderRouterAddress,
|
|
353
359
|
);
|
|
354
360
|
msg
|
|
355
361
|
.then((it) => {
|
|
@@ -400,7 +406,10 @@ export class CompositeClient {
|
|
|
400
406
|
* trip to Indexer API will be made.
|
|
401
407
|
* @param currentHeight Current block height. This can be obtained from ValidatorClient.
|
|
402
408
|
* If set to null, additional round trip to ValidatorClient will be made.
|
|
403
|
-
*
|
|
409
|
+
* @param goodTilBlock The goodTilBlock of the order to place.
|
|
410
|
+
* @param twapParameters The twap parameters of the order to place.
|
|
411
|
+
* @param builderCodeParameters The builder code parameters of the order to place.
|
|
412
|
+
* @param orderRouterAddress The order router address of the order to place.
|
|
404
413
|
*
|
|
405
414
|
* @throws UnexpectedClientError if a malformed response is returned with no GRPC error
|
|
406
415
|
* at any point.
|
|
@@ -615,7 +624,8 @@ export class CompositeClient {
|
|
|
615
624
|
* @param timeInForce The time in force of the order to place
|
|
616
625
|
* @param goodTilBlock The goodTilBlock of the order to place
|
|
617
626
|
* @param reduceOnly The reduceOnly of the order to place
|
|
618
|
-
*
|
|
627
|
+
* @param builderCodeParameters The builder code parameters of the order to place.
|
|
628
|
+
* @param orderRouterAddress The order router address of the order to place.
|
|
619
629
|
*
|
|
620
630
|
* @throws UnexpectedClientError if a malformed response is returned with no GRPC error
|
|
621
631
|
* at any point.
|
|
@@ -631,6 +641,8 @@ export class CompositeClient {
|
|
|
631
641
|
goodTilBlock: number,
|
|
632
642
|
timeInForce: Order_TimeInForce,
|
|
633
643
|
reduceOnly: boolean,
|
|
644
|
+
builderCodeParameters?: IBuilderCodeParameters,
|
|
645
|
+
orderRouterAddress?: string,
|
|
634
646
|
): Promise<EncodeObject> {
|
|
635
647
|
await this.validateGoodTilBlock(goodTilBlock);
|
|
636
648
|
|
|
@@ -666,6 +678,9 @@ export class CompositeClient {
|
|
|
666
678
|
0, // Client metadata is 0 for short term orders.
|
|
667
679
|
Order_ConditionType.CONDITION_TYPE_UNSPECIFIED, // Short term orders cannot be conditional.
|
|
668
680
|
Long.fromInt(0), // Short term orders cannot be conditional.
|
|
681
|
+
undefined,
|
|
682
|
+
builderCodeParameters,
|
|
683
|
+
orderRouterAddress,
|
|
669
684
|
);
|
|
670
685
|
}
|
|
671
686
|
|
package/src/clients/constants.ts
CHANGED
|
@@ -144,6 +144,8 @@ export enum OrderType {
|
|
|
144
144
|
TAKE_PROFIT_LIMIT = 'TAKE_PROFIT',
|
|
145
145
|
STOP_MARKET = 'STOP_MARKET',
|
|
146
146
|
TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET',
|
|
147
|
+
TWAP = 'TWAP',
|
|
148
|
+
TWAP_SUBORDER = 'TWAP_SUBORDER',
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
// ------------ Order Side ------------
|
|
@@ -45,6 +45,7 @@ export function calculateSubticks(
|
|
|
45
45
|
return Long.fromNumber(result);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
|
|
48
49
|
export function calculateSide(side: OrderSide): Order_Side {
|
|
49
50
|
return side === OrderSide.BUY ? Order_Side.SIDE_BUY : Order_Side.SIDE_SELL;
|
|
50
51
|
}
|
|
@@ -133,6 +134,10 @@ export function calculateTimeInForce(
|
|
|
133
134
|
throw new Error('Unexpected code path: timeInForce');
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
case OrderType.TWAP:
|
|
138
|
+
case OrderType.TWAP_SUBORDER:
|
|
139
|
+
return Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED;
|
|
140
|
+
|
|
136
141
|
default:
|
|
137
142
|
throw new Error('Unexpected code path: timeInForce');
|
|
138
143
|
}
|
|
@@ -159,6 +164,12 @@ export function calculateOrderFlags(type: OrderType, timeInForce?: OrderTimeInFo
|
|
|
159
164
|
case OrderType.TAKE_PROFIT_MARKET:
|
|
160
165
|
return OrderFlags.CONDITIONAL;
|
|
161
166
|
|
|
167
|
+
case OrderType.TWAP:
|
|
168
|
+
return OrderFlags.TWAP;
|
|
169
|
+
|
|
170
|
+
case OrderType.TWAP_SUBORDER:
|
|
171
|
+
return OrderFlags.TWAP_SUBORDER;
|
|
172
|
+
|
|
162
173
|
default:
|
|
163
174
|
throw new Error('Unexpected code path: orderFlags');
|
|
164
175
|
}
|
|
@@ -385,4 +385,30 @@ export default class AccountClient extends RestClient {
|
|
|
385
385
|
const uri = `/v4/fundingPayments/parentSubaccount`;
|
|
386
386
|
return this.get(uri, { address, parentSubaccountNumber, limit, ticker, afterOrAt, page });
|
|
387
387
|
}
|
|
388
|
+
|
|
389
|
+
// ------ Trade History ------ //
|
|
390
|
+
|
|
391
|
+
async getSubaccountTradeHistory(
|
|
392
|
+
address: string,
|
|
393
|
+
subaccountNumber: number,
|
|
394
|
+
market?: string,
|
|
395
|
+
marketType?: string,
|
|
396
|
+
limit?: number,
|
|
397
|
+
page?: number,
|
|
398
|
+
): Promise<Data> {
|
|
399
|
+
const uri = `/v4/tradeHistory`;
|
|
400
|
+
return this.get(uri, { address, subaccountNumber, market, marketType, limit, page });
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
async getParentSubaccountNumberTradeHistory(
|
|
404
|
+
address: string,
|
|
405
|
+
parentSubaccountNumber: number,
|
|
406
|
+
market?: string,
|
|
407
|
+
marketType?: string,
|
|
408
|
+
limit?: number,
|
|
409
|
+
page?: number,
|
|
410
|
+
): Promise<Data> {
|
|
411
|
+
const uri = `/v4/tradeHistory/parentSubaccountNumber`;
|
|
412
|
+
return this.get(uri, { address, parentSubaccountNumber, market, marketType, limit, page });
|
|
413
|
+
}
|
|
388
414
|
}
|
package/src/clients/types.ts
CHANGED
package/src/lib/validation.ts
CHANGED
|
@@ -173,12 +173,14 @@ export function verifyOrderFlags(orderFlags: OrderFlags): boolean {
|
|
|
173
173
|
return (
|
|
174
174
|
orderFlags === OrderFlags.SHORT_TERM ||
|
|
175
175
|
orderFlags === OrderFlags.LONG_TERM ||
|
|
176
|
-
orderFlags === OrderFlags.CONDITIONAL
|
|
176
|
+
orderFlags === OrderFlags.CONDITIONAL ||
|
|
177
|
+
orderFlags === OrderFlags.TWAP ||
|
|
178
|
+
orderFlags === OrderFlags.TWAP_SUBORDER
|
|
177
179
|
);
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
export function isStatefulOrder(orderFlags: OrderFlags): boolean {
|
|
181
|
-
return orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL;
|
|
183
|
+
return orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL || orderFlags === OrderFlags.TWAP || orderFlags === OrderFlags.TWAP_SUBORDER;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
function verifyIsBech32(address: string): Error | undefined {
|
package/CHANGELOG.md
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# [3.4.0](https://github.com/dydxprotocol/v4-clients/compare/v4-client-js@3.3.0...v4-client-js@3.4.0) (2025-12-17)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Features
|
|
5
|
-
|
|
6
|
-
* order router revshare params ([#465](https://github.com/dydxprotocol/v4-clients/issues/465)) ([42edaed](https://github.com/dydxprotocol/v4-clients/commit/42edaed38c3fd6b094406e94996a714c2973101e))
|