@reyaxyz/api-sdk 0.103.3 → 0.103.4
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/clients/modules/account/index.js +0 -7
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/conditional-orders/index.js +49 -29
- package/dist/clients/modules/conditional-orders/index.js.map +1 -1
- package/dist/clients/modules/conditional-orders/types.js.map +1 -1
- package/dist/clients/types.js +1 -0
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/conditional-orders/index.d.ts +3 -1
- package/dist/types/clients/modules/conditional-orders/index.d.ts.map +1 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts +10 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +1 -1
- package/dist/types/clients/types.d.ts +1 -0
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/account/index.ts +0 -8
- package/src/clients/modules/conditional-orders/index.ts +57 -25
- package/src/clients/modules/conditional-orders/types.ts +11 -1
- package/src/clients/types.ts +1 -0
|
@@ -81,13 +81,6 @@ var AccountClient = /** @class */ (function (_super) {
|
|
|
81
81
|
})];
|
|
82
82
|
case 1:
|
|
83
83
|
response = _a.sent();
|
|
84
|
-
response.forEach(function (account) {
|
|
85
|
-
account.positions.forEach(function (position) {
|
|
86
|
-
if (Math.random() > 0.5) {
|
|
87
|
-
position.stopLossPrice = Math.random() * 1000;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
84
|
return [2 /*return*/, response];
|
|
92
85
|
}
|
|
93
86
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/account/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,0CAOyB;AAEzB;IAA2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AccountParams,\n GetMarginAccountResult,\n GetMarginAccountsParams,\n GetMarginAccountsResult,\n GetMarginAccountTransactionHistoryParams,\n GetMarginAccountTransactionHistoryResult,\n GetMaxOrderSizeAvailableParams,\n GetMaxOrderSizeAvailableResult,\n GetMaxWithdrawBalanceForAccountParams,\n GetMaxWithdrawBalanceForAccountResult,\n GetPositionsForMarginAccountParams,\n GetPositionsForMarginAccountResult,\n GetTransactionSimulationInitialDataParams,\n GetMarginAccountBalanceChartDataParams,\n GetMarginAccountCollateralsBalanceChartDataParams,\n GetAllMarginAccountsBalanceChartDataParams,\n EditMarginAccountParams,\n CloseMarginAccountParams,\n GetAllMarginAccountsSummaryResult,\n GetAllMarginAccountsSummaryParams,\n GetEditCollateralSimulationInitialDataParams,\n EditMarginAccountResult,\n CloseMarginAccountResult,\n GetIsolatedOrderMaxSizeAvailableParams,\n GetIsolatedOrderMaxSizeAvailableResult,\n GetPositionsHistoryForMarginAccountPaginatedParams,\n GetPositionsHistoryForMarginAccountPaginatedResult,\n GetLiquidationHistoryForOwnerAddressResult,\n GetLiquidationHistoryForOwnerAddressParams,\n} from './types';\nimport {\n EditCollateralSimulationState,\n TradeSimulationState,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetMarginAccountBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n RestClient,\n} from '@reyaxyz/common';\n\nexport default class AccountClient extends RestClient {\n /**\n * Asynchronously retrieves a list of margin accounts associated with a specific address.\n *\n * This method makes a request to the API endpoint to fetch collateral account data. The data is filtered\n * based on the provided Ethereum address. An optional limit can be specified to control the number of\n * collateral accounts returned in the response.\n *\n * @param {GetMarginAccountsParams} params\n * @returns {Promise<GetMarginAccountsResult>} A promise that resolves to the response containing the margin\n * account data.\n * @memberof account\n * */\n\n async getMarginAccounts(\n params: GetMarginAccountsParams,\n ): Promise<GetMarginAccountsResult> {\n const uri = `/api/accounts/${params.address}`;\n const response: GetMarginAccountsResult = await this.get(uri, {\n limit: params.limit,\n });\n\n response.forEach((account) => {\n account.positions.forEach((position) => {\n if (Math.random() > 0.5) {\n position.stopLossPrice = Math.random() * 1000;\n }\n });\n });\n\n return response;\n }\n\n /**\n * Asynchronously retrieves details of a specific collateral account for a given Ethereum address.\n *\n * This method sends a request to the API to obtain detailed information about a specific collateral account\n * associated with the provided Ethereum address. The account is identified using the collateral account number.\n *\n * @param {GetMarginAccountParams} params\n * @returns {Promise<GetMarginAccountResult>} A promise that resolves to the response containing the detailed\n * information of the specified margin account.\n * @memberof account\n */\n\n async getMarginAccount(\n params: GetMarginAccountParams,\n ): Promise<GetMarginAccountResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}`;\n return this.get(uri);\n }\n\n async getPositionsForMarginAccount(\n params: GetPositionsForMarginAccountParams,\n ): Promise<GetPositionsForMarginAccountResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}/positions`;\n return this.get(uri, { limit: params.limit });\n }\n\n async getPositionsHistoryForMarginAccountPaginated(\n params: GetPositionsHistoryForMarginAccountPaginatedParams,\n ): Promise<GetPositionsHistoryForMarginAccountPaginatedResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}/positions/history/paginated`;\n return this.get(uri, {\n type: params.type,\n page: params.page,\n perPage: params.perPage,\n });\n }\n\n async getLiquidationHistoryForOwnerAddress(\n params: GetLiquidationHistoryForOwnerAddressParams,\n ): Promise<GetLiquidationHistoryForOwnerAddressResult> {\n const uri = `/api/accounts/${params.address}/positions/liquidations`;\n return this.get(uri, {\n timestampFromMS: params.timestampFromMS,\n });\n }\n\n async getMaxOrderSizeAvailable(\n params: GetMaxOrderSizeAvailableParams,\n ): Promise<GetMaxOrderSizeAvailableResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-order-size`;\n return this.get(uri, {\n marketId: params.marketId,\n direction: params.direction,\n });\n }\n\n async getIsolatedOrderMaxSizeAvailable(\n params: GetIsolatedOrderMaxSizeAvailableParams,\n ): Promise<GetIsolatedOrderMaxSizeAvailableResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-order-size-isolated`;\n return this.get(uri, {\n marketId: params.marketId,\n direction: params.direction,\n });\n }\n\n async getTransactionSimulationInitialData(\n params: GetTransactionSimulationInitialDataParams,\n ): Promise<TradeSimulationState> {\n const uri = `/api/accounts/${params.marginAccountId}/trade-simulation-data`;\n return this.get(uri, {\n marketId: params.marketId,\n });\n }\n\n async getEditCollateralSimulationInitialData(\n params: GetEditCollateralSimulationInitialDataParams,\n ): Promise<EditCollateralSimulationState> {\n const uri = `/api/accounts/${params.marginAccountId}/edit-collateral-simulation-data`;\n return this.get(uri);\n }\n\n async getMarginAccountTransactionHistory(\n params: GetMarginAccountTransactionHistoryParams,\n ): Promise<GetMarginAccountTransactionHistoryResult> {\n const uri = `/api/accounts/${params.marginAccountId}/transaction-history`;\n return this.get(uri, {\n limit: params.limit,\n });\n }\n\n async getMaxWithdrawBalanceForAccount(\n params: GetMaxWithdrawBalanceForAccountParams,\n ): Promise<GetMaxWithdrawBalanceForAccountResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-withdraw-amount`;\n return this.get(uri, {\n assetAddress: params.tokenAddress,\n });\n }\n\n async getMarginAccountBalanceChartData(\n params: GetMarginAccountBalanceChartDataParams,\n ): Promise<GetMarginAccountBalanceChartDataResult> {\n const uri = `/api/accounts/${params.marginAccountId}/balance-chart-data`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getMarginAccountCollateralsBalanceChartData(\n params: GetMarginAccountCollateralsBalanceChartDataParams,\n ): Promise<GetMarginAccountCollateralsBalanceChartDataResult> {\n const uri = `/api/accounts/${params.marginAccountId}/collaterals-balance-chart-data`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getAllMarginAccountsBalanceChart(\n params: GetAllMarginAccountsBalanceChartDataParams,\n ): Promise<GetAllMarginAccountsBalanceChartDataResult> {\n const uri = `/api/accounts/owner/${params.ownerAddress}/balance`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getAllMarginAccountsSummary(\n params: GetAllMarginAccountsSummaryParams,\n ): Promise<GetAllMarginAccountsSummaryResult> {\n const uri = `/api/accounts/owner/${params.ownerAddress}/summary`;\n return this.get(uri);\n }\n\n // TODO: Milan validate\n async editMarginAccount(\n params: EditMarginAccountParams,\n ): Promise<EditMarginAccountResult> {\n const name = (params.name || '').trim();\n if (!params.id) {\n throw new Error('Missing margin account id');\n }\n if (name.length === 0 || name.length > 25) {\n throw new Error('Max size 25 characters');\n }\n\n const uri = `/api/accounts/${params.id}/edit`;\n return this.put(uri, {\n id: params.id,\n name: params.name,\n });\n }\n async closeMarginAccount(\n params: CloseMarginAccountParams,\n ): Promise<CloseMarginAccountResult> {\n if (!params.id) {\n throw new Error('Missing margin account id');\n }\n\n const uri = `/api/accounts/${params.id}/close`;\n return this.delete(uri, {\n id: params.id,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/account/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,0CAOyB;AAEzB;IAA2C,iCAAU;IAArD;;IAgMA,CAAC;IA/LC;;;;;;;;;;;SAWK;IAEC,yCAAiB,GAAvB,UACE,MAA+B;;;;;;wBAEzB,GAAG,GAAG,wBAAiB,MAAM,CAAC,OAAO,CAAE,CAAC;wBACJ,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;gCAC5D,KAAK,EAAE,MAAM,CAAC,KAAK;6BACpB,CAAC,EAAA;;wBAFI,QAAQ,GAA4B,SAExC;wBAEF,sBAAO,QAAQ,EAAC;;;;KACjB;IAED;;;;;;;;;;OAUG;IAEG,wCAAgB,GAAtB,UACE,MAA8B;;;;gBAExB,GAAG,GAAG,wBAAiB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CAAC,GAAG,EAAE;wBACnB,EAAE,EAAE,MAAM,CAAC,EAAE;wBACb,IAAI,EAAE,MAAM,CAAC,IAAI;qBAClB,CAAC,EAAC;;;KACJ;IACK,0CAAkB,GAAxB,UACE,MAAgC;;;;gBAEhC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;gBAC/C,CAAC;gBAEK,GAAG,GAAG,wBAAiB,MAAM,CAAC,EAAE,WAAQ,CAAC;gBAC/C,sBAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;wBACtB,EAAE,EAAE,MAAM,CAAC,EAAE;qBACd,CAAC,EAAC;;;KACJ;IACH,oBAAC;AAAD,CAAC,AAhMD,CAA2C,mBAAU,GAgMpD","sourcesContent":["import {\n GetMarginAccountParams,\n GetMarginAccountResult,\n GetMarginAccountsParams,\n GetMarginAccountsResult,\n GetMarginAccountTransactionHistoryParams,\n GetMarginAccountTransactionHistoryResult,\n GetMaxOrderSizeAvailableParams,\n GetMaxOrderSizeAvailableResult,\n GetMaxWithdrawBalanceForAccountParams,\n GetMaxWithdrawBalanceForAccountResult,\n GetPositionsForMarginAccountParams,\n GetPositionsForMarginAccountResult,\n GetTransactionSimulationInitialDataParams,\n GetMarginAccountBalanceChartDataParams,\n GetMarginAccountCollateralsBalanceChartDataParams,\n GetAllMarginAccountsBalanceChartDataParams,\n EditMarginAccountParams,\n CloseMarginAccountParams,\n GetAllMarginAccountsSummaryResult,\n GetAllMarginAccountsSummaryParams,\n GetEditCollateralSimulationInitialDataParams,\n EditMarginAccountResult,\n CloseMarginAccountResult,\n GetIsolatedOrderMaxSizeAvailableParams,\n GetIsolatedOrderMaxSizeAvailableResult,\n GetPositionsHistoryForMarginAccountPaginatedParams,\n GetPositionsHistoryForMarginAccountPaginatedResult,\n GetLiquidationHistoryForOwnerAddressResult,\n GetLiquidationHistoryForOwnerAddressParams,\n} from './types';\nimport {\n EditCollateralSimulationState,\n TradeSimulationState,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetMarginAccountBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n RestClient,\n} from '@reyaxyz/common';\n\nexport default class AccountClient extends RestClient {\n /**\n * Asynchronously retrieves a list of margin accounts associated with a specific address.\n *\n * This method makes a request to the API endpoint to fetch collateral account data. The data is filtered\n * based on the provided Ethereum address. An optional limit can be specified to control the number of\n * collateral accounts returned in the response.\n *\n * @param {GetMarginAccountsParams} params\n * @returns {Promise<GetMarginAccountsResult>} A promise that resolves to the response containing the margin\n * account data.\n * @memberof account\n * */\n\n async getMarginAccounts(\n params: GetMarginAccountsParams,\n ): Promise<GetMarginAccountsResult> {\n const uri = `/api/accounts/${params.address}`;\n const response: GetMarginAccountsResult = await this.get(uri, {\n limit: params.limit,\n });\n\n return response;\n }\n\n /**\n * Asynchronously retrieves details of a specific collateral account for a given Ethereum address.\n *\n * This method sends a request to the API to obtain detailed information about a specific collateral account\n * associated with the provided Ethereum address. The account is identified using the collateral account number.\n *\n * @param {GetMarginAccountParams} params\n * @returns {Promise<GetMarginAccountResult>} A promise that resolves to the response containing the detailed\n * information of the specified margin account.\n * @memberof account\n */\n\n async getMarginAccount(\n params: GetMarginAccountParams,\n ): Promise<GetMarginAccountResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}`;\n return this.get(uri);\n }\n\n async getPositionsForMarginAccount(\n params: GetPositionsForMarginAccountParams,\n ): Promise<GetPositionsForMarginAccountResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}/positions`;\n return this.get(uri, { limit: params.limit });\n }\n\n async getPositionsHistoryForMarginAccountPaginated(\n params: GetPositionsHistoryForMarginAccountPaginatedParams,\n ): Promise<GetPositionsHistoryForMarginAccountPaginatedResult> {\n const uri = `/api/accounts/${params.address}/marginAccount/${params.marginAccountId}/positions/history/paginated`;\n return this.get(uri, {\n type: params.type,\n page: params.page,\n perPage: params.perPage,\n });\n }\n\n async getLiquidationHistoryForOwnerAddress(\n params: GetLiquidationHistoryForOwnerAddressParams,\n ): Promise<GetLiquidationHistoryForOwnerAddressResult> {\n const uri = `/api/accounts/${params.address}/positions/liquidations`;\n return this.get(uri, {\n timestampFromMS: params.timestampFromMS,\n });\n }\n\n async getMaxOrderSizeAvailable(\n params: GetMaxOrderSizeAvailableParams,\n ): Promise<GetMaxOrderSizeAvailableResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-order-size`;\n return this.get(uri, {\n marketId: params.marketId,\n direction: params.direction,\n });\n }\n\n async getIsolatedOrderMaxSizeAvailable(\n params: GetIsolatedOrderMaxSizeAvailableParams,\n ): Promise<GetIsolatedOrderMaxSizeAvailableResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-order-size-isolated`;\n return this.get(uri, {\n marketId: params.marketId,\n direction: params.direction,\n });\n }\n\n async getTransactionSimulationInitialData(\n params: GetTransactionSimulationInitialDataParams,\n ): Promise<TradeSimulationState> {\n const uri = `/api/accounts/${params.marginAccountId}/trade-simulation-data`;\n return this.get(uri, {\n marketId: params.marketId,\n });\n }\n\n async getEditCollateralSimulationInitialData(\n params: GetEditCollateralSimulationInitialDataParams,\n ): Promise<EditCollateralSimulationState> {\n const uri = `/api/accounts/${params.marginAccountId}/edit-collateral-simulation-data`;\n return this.get(uri);\n }\n\n async getMarginAccountTransactionHistory(\n params: GetMarginAccountTransactionHistoryParams,\n ): Promise<GetMarginAccountTransactionHistoryResult> {\n const uri = `/api/accounts/${params.marginAccountId}/transaction-history`;\n return this.get(uri, {\n limit: params.limit,\n });\n }\n\n async getMaxWithdrawBalanceForAccount(\n params: GetMaxWithdrawBalanceForAccountParams,\n ): Promise<GetMaxWithdrawBalanceForAccountResult> {\n const uri = `/api/accounts/${params.marginAccountId}/max-withdraw-amount`;\n return this.get(uri, {\n assetAddress: params.tokenAddress,\n });\n }\n\n async getMarginAccountBalanceChartData(\n params: GetMarginAccountBalanceChartDataParams,\n ): Promise<GetMarginAccountBalanceChartDataResult> {\n const uri = `/api/accounts/${params.marginAccountId}/balance-chart-data`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getMarginAccountCollateralsBalanceChartData(\n params: GetMarginAccountCollateralsBalanceChartDataParams,\n ): Promise<GetMarginAccountCollateralsBalanceChartDataResult> {\n const uri = `/api/accounts/${params.marginAccountId}/collaterals-balance-chart-data`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getAllMarginAccountsBalanceChart(\n params: GetAllMarginAccountsBalanceChartDataParams,\n ): Promise<GetAllMarginAccountsBalanceChartDataResult> {\n const uri = `/api/accounts/owner/${params.ownerAddress}/balance`;\n return this.get(uri, {\n timeframeMs: params.filters.timeframeMs,\n granularity: params.filters.granularity,\n });\n }\n\n async getAllMarginAccountsSummary(\n params: GetAllMarginAccountsSummaryParams,\n ): Promise<GetAllMarginAccountsSummaryResult> {\n const uri = `/api/accounts/owner/${params.ownerAddress}/summary`;\n return this.get(uri);\n }\n\n // TODO: Milan validate\n async editMarginAccount(\n params: EditMarginAccountParams,\n ): Promise<EditMarginAccountResult> {\n const name = (params.name || '').trim();\n if (!params.id) {\n throw new Error('Missing margin account id');\n }\n if (name.length === 0 || name.length > 25) {\n throw new Error('Max size 25 characters');\n }\n\n const uri = `/api/accounts/${params.id}/edit`;\n return this.put(uri, {\n id: params.id,\n name: params.name,\n });\n }\n async closeMarginAccount(\n params: CloseMarginAccountParams,\n ): Promise<CloseMarginAccountResult> {\n if (!params.id) {\n throw new Error('Missing margin account id');\n }\n\n const uri = `/api/accounts/${params.id}/close`;\n return this.delete(uri, {\n id: params.id,\n });\n }\n}\n"]}
|
|
@@ -67,7 +67,7 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
67
67
|
return __generator(this, function (_a) {
|
|
68
68
|
switch (_a.label) {
|
|
69
69
|
case 0:
|
|
70
|
-
uri = "/api/conditional-orders/sl/get-orders-by-position/".concat(common_1.StopLossOrderStatus.
|
|
70
|
+
uri = "/api/conditional-orders/sl/get-orders-by-position/".concat(common_1.StopLossOrderStatus.PENDING, "/").concat(params.marketId, "/").concat(params.accountId);
|
|
71
71
|
return [4 /*yield*/, this.get(uri)];
|
|
72
72
|
case 1:
|
|
73
73
|
response = _a.sent();
|
|
@@ -81,22 +81,26 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
-
// todo: need authentication
|
|
85
84
|
ConditionalOrdersClient.prototype.cancelSLOrder = function (params) {
|
|
86
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
var uri;
|
|
86
|
+
var signature, uri;
|
|
88
87
|
return __generator(this, function (_a) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, (0, common_1.signCancelConditionalOrder)(params.signer, params.orderId)];
|
|
90
|
+
case 1:
|
|
91
|
+
signature = _a.sent();
|
|
92
|
+
uri = "/api/conditional-orders/sl/cancel-order";
|
|
93
|
+
return [2 /*return*/, this.put(uri, {}, {
|
|
94
|
+
orderId: params.orderId,
|
|
95
|
+
userSignature: signature,
|
|
96
|
+
})];
|
|
97
|
+
}
|
|
94
98
|
});
|
|
95
99
|
});
|
|
96
100
|
};
|
|
97
101
|
ConditionalOrdersClient.prototype.registerSLOrder = function (params) {
|
|
98
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var position, positionBase, orderPriceLimit, inputs, nonce,
|
|
103
|
+
var position, positionBase, orderPriceLimit, inputs, creationTimestampMs, nonce, deadline, signature, uri, _a, _b;
|
|
100
104
|
var _c;
|
|
101
105
|
return __generator(this, function (_d) {
|
|
102
106
|
switch (_d.label) {
|
|
@@ -107,25 +111,14 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
107
111
|
if (positionBase === 0) {
|
|
108
112
|
throw new Error('Position with no exposure');
|
|
109
113
|
}
|
|
110
|
-
orderPriceLimit = (0, common_1.
|
|
111
|
-
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint256'], [params.stopLossPrice, orderPriceLimit]);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
orderPriceLimit = Number((0, common_1.calculateMaxPriceLimit)(positionBase < 0));
|
|
115
|
+
inputs = ethers_1.AbiCoder.defaultAbiCoder().encode(['uint256', 'uint256'], [(0, common_1.scale)(18)(params.stopLossPrice), orderPriceLimit]);
|
|
116
|
+
creationTimestampMs = Date.now();
|
|
117
|
+
nonce = this.createNonce(params.marginAccountId, params.market.id, creationTimestampMs);
|
|
118
|
+
deadline = Math.pow(10, 18);
|
|
119
|
+
return [4 /*yield*/, (0, common_1.signConditionalOrder)(params.signer, this.reyaChainId, params.marginAccountId, params.market.id, params.market.exchangeId, params.market.counterpartyAccountIds, types_1.ConditionalOrderType.StopLoss, inputs, nonce, deadline)];
|
|
114
120
|
case 2:
|
|
115
121
|
signature = _d.sent();
|
|
116
|
-
if (!position.stopLossPrice) return [3 /*break*/, 5];
|
|
117
|
-
return [4 /*yield*/, this.getPendingSLOrder({
|
|
118
|
-
accountId: params.marginAccountId,
|
|
119
|
-
marketId: params.market.id,
|
|
120
|
-
})];
|
|
121
|
-
case 3:
|
|
122
|
-
order = _d.sent();
|
|
123
|
-
if (!(order != null)) return [3 /*break*/, 5];
|
|
124
|
-
return [4 /*yield*/, this.cancelSLOrder({ orderId: order.orderId })];
|
|
125
|
-
case 4:
|
|
126
|
-
_d.sent();
|
|
127
|
-
_d.label = 5;
|
|
128
|
-
case 5:
|
|
129
122
|
uri = "/api/conditional-orders/sl/create-order";
|
|
130
123
|
_a = this.post;
|
|
131
124
|
_b = [uri,
|
|
@@ -137,15 +130,29 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
137
130
|
stopPrice: params.stopLossPrice
|
|
138
131
|
};
|
|
139
132
|
return [4 /*yield*/, params.signer.getAddress()];
|
|
140
|
-
case
|
|
133
|
+
case 3: return [2 /*return*/, _a.apply(this, _b.concat([(_c.signerWallet = _d.sent(),
|
|
141
134
|
_c.nonce = nonce,
|
|
142
|
-
_c.signature = signature
|
|
143
|
-
_c.
|
|
135
|
+
_c.signature = signature,
|
|
136
|
+
_c.deadline = deadline,
|
|
137
|
+
_c.orderPriceLimit = orderPriceLimit,
|
|
138
|
+
_c.exchangeId = params.market.exchangeId,
|
|
139
|
+
_c.poolId = params.market.counterpartyAccountIds[0],
|
|
140
|
+
_c.timestampMs = creationTimestampMs,
|
|
144
141
|
_c)]))];
|
|
145
142
|
}
|
|
146
143
|
});
|
|
147
144
|
});
|
|
148
145
|
};
|
|
146
|
+
ConditionalOrdersClient.prototype.updateSLOrder = function (params) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0: return [4 /*yield*/, this.registerSLOrder(params)];
|
|
151
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
149
156
|
ConditionalOrdersClient.prototype.getPosition = function (accountId, marketId) {
|
|
150
157
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
158
|
var uri;
|
|
@@ -155,6 +162,19 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
155
162
|
});
|
|
156
163
|
});
|
|
157
164
|
};
|
|
165
|
+
ConditionalOrdersClient.prototype.createNonce = function (accountId, marketId, timestampMs) {
|
|
166
|
+
// Validate the input ranges
|
|
167
|
+
if (marketId < 0 || marketId >= Math.pow(2, 32))
|
|
168
|
+
throw new Error('marketId is out of range');
|
|
169
|
+
if (accountId < BigInt(0) || accountId >= Math.pow(2, 128))
|
|
170
|
+
throw new Error('accountId is out of range');
|
|
171
|
+
if (timestampMs < 0 || timestampMs >= Math.pow(2, 64))
|
|
172
|
+
throw new Error('timestamp is out of range');
|
|
173
|
+
var hashUint256 = (BigInt(accountId) << BigInt(98)) |
|
|
174
|
+
(BigInt(timestampMs) << BigInt(32)) |
|
|
175
|
+
BigInt(marketId);
|
|
176
|
+
return hashUint256.toString();
|
|
177
|
+
};
|
|
158
178
|
return ConditionalOrdersClient;
|
|
159
179
|
}(common_1.RestClient));
|
|
160
180
|
exports.default = ConditionalOrdersClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAUyB;AACzB,iCAAkC;AAClC,iCAUiB;AAEjB;IAAqD,2CAAU;IAG7D,iCAAY,WAAwB,EAAE,IAAY;QAChD,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC;QACZ,KAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;IACjC,CAAC;IAEK,mDAAiB,GAAvB,UACE,MAA+B;;;;;;wBAEzB,GAAG,GAAG,4DAAqD,4BAAmB,CAAC,OAAO,cAAI,MAAM,CAAC,QAAQ,cAAI,MAAM,CAAC,SAAS,CAAE,CAAC;wBACrH,qBAAM,IAAI,CAAC,GAAG,CAA4B,GAAG,CAAC,EAAA;;wBAAzD,QAAQ,GAAG,SAA8C;wBAE/D,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BACxB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;wBACrE,CAAC;wBAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;4BAAE,sB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,IAAI,CAAC,GAAG,CAAiB,GAAG,CAAC,EAAC;;;KACtC;IAEO,6CAAW,GAAnB,UACE,SAAiB,EACjB,QAAgB,EAChB,WAAmB;QAEnB,4BAA4B;QAC5B,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,IAAI,SAAA,CAAC,EAAI,EAAE,CAAA;YACrC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,IAAI,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,IAAI,SAAA,CAAC,EAAI,GAAG,CAAA;YAChD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,IAAI,SAAA,CAAC,EAAI,EAAE,CAAA;YAC3C,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE/C,IAAM,WAAW,GACf,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;YACjC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;YACnC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEnB,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IACH,8BAAC;AAAD,CAAC,AA1ID,CAAqD,mBAAU,GA0I9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n StopLossOrder,\n StopLossOrderStatus,\n scale,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport {\n CancelSLOrderParams,\n CancelSLOrderResult,\n ConditionalOrderType,\n GetPendingSLOrderParams,\n GetPendingSLOrderResult,\n RegisterSLOrderParams,\n RegisterSLOrderResult,\n UpdateSLOrderParams,\n UpdateSLOrderResult,\n} from './types';\n\nexport default class ConditionalOrdersClient extends RestClient {\n private reyaChainId: ReyaChainId;\n\n constructor(reyaChainId: ReyaChainId, host: string) {\n super(host);\n this.reyaChainId = reyaChainId;\n }\n\n async getPendingSLOrder(\n params: GetPendingSLOrderParams,\n ): Promise<GetPendingSLOrderResult> {\n const uri = `/api/conditional-orders/sl/get-orders-by-position/${StopLossOrderStatus.PENDING}/${params.marketId}/${params.accountId}`;\n const response = await this.get<GetPendingSLOrderResult[]>(uri);\n\n if (response.length > 1) {\n throw new Error('Multiple SL pending orders on a single position');\n }\n\n if (response.length === 0) return null;\n\n return response[0];\n }\n\n async cancelSLOrder(\n params: CancelSLOrderParams,\n ): Promise<CancelSLOrderResult> {\n const signature = await signCancelConditionalOrder(\n params.signer,\n params.orderId,\n );\n\n const uri = `/api/conditional-orders/sl/cancel-order`;\n return this.put<StopLossOrder>(\n uri,\n {},\n {\n orderId: params.orderId,\n userSignature: signature,\n },\n );\n }\n\n async registerSLOrder(\n params: RegisterSLOrderParams,\n ): Promise<RegisterSLOrderResult> {\n const position = await this.getPosition(\n params.marginAccountId,\n params.market.id,\n );\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const orderPriceLimit = Number(calculateMaxPriceLimit(positionBase < 0));\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['uint256', 'uint256'],\n [scale(18)(params.stopLossPrice), orderPriceLimit],\n );\n const creationTimestampMs = Date.now();\n const nonce = this.createNonce(\n params.marginAccountId,\n params.market.id,\n creationTimestampMs,\n );\n const deadline = 10 ** 18; // very big number for timestamp in seconds - infinite deadline\n\n const signature = await signConditionalOrder(\n params.signer,\n this.reyaChainId,\n params.marginAccountId,\n params.market.id,\n params.market.exchangeId,\n params.market.counterpartyAccountIds,\n ConditionalOrderType.StopLoss,\n inputs,\n nonce,\n deadline,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/create-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.market.id,\n isLong: positionBase > 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: nonce,\n signature: signature,\n deadline: deadline,\n orderPriceLimit: orderPriceLimit,\n exchangeId: params.market.exchangeId,\n poolId: params.market.counterpartyAccountIds[0],\n timestampMs: creationTimestampMs,\n },\n );\n }\n\n async updateSLOrder(\n params: UpdateSLOrderParams,\n ): Promise<UpdateSLOrderResult> {\n return await this.registerSLOrder(params as RegisterSLOrderParams);\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/account/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private createNonce(\n accountId: number,\n marketId: number,\n timestampMs: number,\n ): string {\n // Validate the input ranges\n if (marketId < 0 || marketId >= 2 ** 32)\n throw new Error('marketId is out of range');\n if (accountId < BigInt(0) || accountId >= 2 ** 128)\n throw new Error('accountId is out of range');\n if (timestampMs < 0 || timestampMs >= 2 ** 64)\n throw new Error('timestamp is out of range');\n\n const hashUint256 =\n (BigInt(accountId) << BigInt(98)) |\n (BigInt(timestampMs) << BigInt(32)) |\n BigInt(marketId);\n\n return hashUint256.toString();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":";;;AAkBA,IAAY,oBAEX;AAFD,WAAY,oBAAoB;IAC9B,uEAAc,CAAA;AAChB,CAAC,EAFW,oBAAoB,oCAApB,oBAAoB,QAE/B","sourcesContent":["import { StopLossOrder } from '@reyaxyz/common';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\nexport type CancelSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: number;\n};\n\nexport type CancelSLOrderResult = StopLossOrder;\n\nexport type GetPendingSLOrderParams = {\n accountId: number;\n marketId: number;\n};\n\nexport type GetPendingSLOrderResult = StopLossOrder | null;\n\nexport enum ConditionalOrderType {\n 'StopLoss' = 0,\n}\n\nexport type ConditionalOrderDetails = {\n accountId: number;\n marketId: number;\n exchangeId: number;\n counterpartyAccountIds: number[];\n orderType: number;\n inputs: string;\n signer: string;\n nonce: string;\n};\n\nexport type MarketParams = {\n id: MarketEntity['id'];\n exchangeId: MarketEntity['orderInfo']['exchangeId'];\n counterpartyAccountIds: MarketEntity['orderInfo']['counterpartyAccountIds'];\n currentPrice: number;\n};\n\nexport type RegisterSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n market: MarketParams;\n};\n\nexport type UpdateSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: number;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n market: MarketParams;\n};\n\nexport type RegisterSLOrderResult = StopLossOrder;\nexport type UpdateSLOrderResult = StopLossOrder;\n"]}
|
package/dist/clients/types.js
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "MarginAccountCollateralsBalanceGranularity", { e
|
|
|
26
26
|
Object.defineProperty(exports, "AllMarginAccountsBalanceGranularity", { enumerable: true, get: function () { return common_1.AllMarginAccountsBalanceGranularity; } });
|
|
27
27
|
Object.defineProperty(exports, "FundingRateHistoryGranularity", { enumerable: true, get: function () { return common_1.FundingRateHistoryGranularity; } });
|
|
28
28
|
__exportStar(require("./modules/account/types"), exports);
|
|
29
|
+
__exportStar(require("./modules/conditional-orders/types"), exports);
|
|
29
30
|
__exportStar(require("./modules/lp/types"), exports);
|
|
30
31
|
__exportStar(require("./modules/markets/types"), exports);
|
|
31
32
|
__exportStar(require("./modules/tokens/types"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,0CA4ByB;AA1BvB,2GAAA,iBAAiB,OAAA;AAYjB,qGAAA,WAAW,OAAA;AACX,2GAAA,iBAAiB,OAAA;AAGjB,8GAAA,oBAAoB,OAAA;AACpB,yHAAA,+BAA+B,OAAA;AAE/B,oIAAA,0CAA0C,OAAA;AAG1C,6HAAA,mCAAmC,OAAA;AAEnC,uHAAA,6BAA6B,OAAA;AAG/B,0DAAwC;AACxC,qDAAmC;AACnC,0DAAwC;AACxC,yDAAuC;AACvC,mEAAiD;AACjD,wDAAsC;AACtC,iFAA+D;AAC/D,4EAA0D;AAC1D,kFAAgE;AAChE,6EAA2D;AAC3D,yEAAuD;AACvD,mFAAiE;AACjE,yFAAuE;AACvE,8EAA4D;AAC5D,+DAA6C;AAC7C,yEAAuD;AACvD,kFAAgE;AAChE,4EAA0D","sourcesContent":["// reexporting what we want to share with integrators\nexport {\n Candle,\n CandlesResolution,\n MarketEntity,\n LpTransactionHistoryEntity,\n TradingHistoryEntity,\n PositionHistoryEntity,\n PositionEntity,\n TransactionHistoryType,\n MarginAccountTransactionHistoryType,\n MarginAccountTransactionHistoryEntity,\n MarginAccountEntity,\n LpPositionEntity,\n LpPoolEntity,\n ReyaChainId,\n MoneyInOutChainId,\n GetLpPoolPerformanceChartDataResult,\n GetLpPoolBalanceChartDataResult,\n LpBalanceGranularity,\n MarginAccountBalanceGranularity,\n GetMarginAccountBalanceChartDataResult,\n MarginAccountCollateralsBalanceGranularity,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n AllMarginAccountsBalanceGranularity,\n GetFundingRateChartDataResult,\n FundingRateHistoryGranularity,\n MoneyInOutConfigurationPerTokenName,\n} from '@reyaxyz/common';\nexport * from './modules/account/types';\nexport * from './modules/lp/types';\nexport * from './modules/markets/types';\nexport * from './modules/tokens/types';\nexport * from './modules/trade.simulation/types';\nexport * from './modules/owner/types';\nexport * from './modules/deposit-existing-MA.simulation/types';\nexport * from './modules/deposit-new-MA.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/edit-collateral.simulation/types';\nexport * from './modules/withdraw-MA.simulation/types';\nexport * from './modules/withdraw-passive-pool.simulation/types';\nexport * from './modules/transfer-margin-between-MAs.simulation/types';\nexport * from './modules/transfer-MA-Pool.simulation/types';\nexport * from './modules/funding-rate/types';\nexport * from './modules/depth-chart.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/isolated-order.simulation/types';\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,0CA4ByB;AA1BvB,2GAAA,iBAAiB,OAAA;AAYjB,qGAAA,WAAW,OAAA;AACX,2GAAA,iBAAiB,OAAA;AAGjB,8GAAA,oBAAoB,OAAA;AACpB,yHAAA,+BAA+B,OAAA;AAE/B,oIAAA,0CAA0C,OAAA;AAG1C,6HAAA,mCAAmC,OAAA;AAEnC,uHAAA,6BAA6B,OAAA;AAG/B,0DAAwC;AACxC,qEAAmD;AACnD,qDAAmC;AACnC,0DAAwC;AACxC,yDAAuC;AACvC,mEAAiD;AACjD,wDAAsC;AACtC,iFAA+D;AAC/D,4EAA0D;AAC1D,kFAAgE;AAChE,6EAA2D;AAC3D,yEAAuD;AACvD,mFAAiE;AACjE,yFAAuE;AACvE,8EAA4D;AAC5D,+DAA6C;AAC7C,yEAAuD;AACvD,kFAAgE;AAChE,4EAA0D","sourcesContent":["// reexporting what we want to share with integrators\nexport {\n Candle,\n CandlesResolution,\n MarketEntity,\n LpTransactionHistoryEntity,\n TradingHistoryEntity,\n PositionHistoryEntity,\n PositionEntity,\n TransactionHistoryType,\n MarginAccountTransactionHistoryType,\n MarginAccountTransactionHistoryEntity,\n MarginAccountEntity,\n LpPositionEntity,\n LpPoolEntity,\n ReyaChainId,\n MoneyInOutChainId,\n GetLpPoolPerformanceChartDataResult,\n GetLpPoolBalanceChartDataResult,\n LpBalanceGranularity,\n MarginAccountBalanceGranularity,\n GetMarginAccountBalanceChartDataResult,\n MarginAccountCollateralsBalanceGranularity,\n GetMarginAccountCollateralsBalanceChartDataResult,\n GetAllMarginAccountsBalanceChartDataResult,\n AllMarginAccountsBalanceGranularity,\n GetFundingRateChartDataResult,\n FundingRateHistoryGranularity,\n MoneyInOutConfigurationPerTokenName,\n} from '@reyaxyz/common';\nexport * from './modules/account/types';\nexport * from './modules/conditional-orders/types';\nexport * from './modules/lp/types';\nexport * from './modules/markets/types';\nexport * from './modules/tokens/types';\nexport * from './modules/trade.simulation/types';\nexport * from './modules/owner/types';\nexport * from './modules/deposit-existing-MA.simulation/types';\nexport * from './modules/deposit-new-MA.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/edit-collateral.simulation/types';\nexport * from './modules/withdraw-MA.simulation/types';\nexport * from './modules/withdraw-passive-pool.simulation/types';\nexport * from './modules/transfer-margin-between-MAs.simulation/types';\nexport * from './modules/transfer-MA-Pool.simulation/types';\nexport * from './modules/funding-rate/types';\nexport * from './modules/depth-chart.simulation/types';\nexport * from './modules/deposit-passive-pool.simulation/types';\nexport * from './modules/isolated-order.simulation/types';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wCAAwC,EACxC,wCAAwC,EACxC,8BAA8B,EAC9B,8BAA8B,EAC9B,qCAAqC,EACrC,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,yCAAyC,EACzC,sCAAsC,EACtC,iDAAiD,EACjD,0CAA0C,EAC1C,uBAAuB,EACvB,wBAAwB,EACxB,iCAAiC,EACjC,iCAAiC,EACjC,4CAA4C,EAC5C,uBAAuB,EACvB,wBAAwB,EACxB,sCAAsC,EACtC,sCAAsC,EACtC,kDAAkD,EAClD,kDAAkD,EAClD,0CAA0C,EAC1C,0CAA0C,EAC3C,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,iDAAiD,EACjD,sCAAsC,EACtC,0CAA0C,EAC1C,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;SAWK;IAEC,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wCAAwC,EACxC,wCAAwC,EACxC,8BAA8B,EAC9B,8BAA8B,EAC9B,qCAAqC,EACrC,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,yCAAyC,EACzC,sCAAsC,EACtC,iDAAiD,EACjD,0CAA0C,EAC1C,uBAAuB,EACvB,wBAAwB,EACxB,iCAAiC,EACjC,iCAAiC,EACjC,4CAA4C,EAC5C,uBAAuB,EACvB,wBAAwB,EACxB,sCAAsC,EACtC,sCAAsC,EACtC,kDAAkD,EAClD,kDAAkD,EAClD,0CAA0C,EAC1C,0CAA0C,EAC3C,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,iDAAiD,EACjD,sCAAsC,EACtC,0CAA0C,EAC1C,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;SAWK;IAEC,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC;IASnC;;;;;;;;;;OAUG;IAEG,gBAAgB,CACpB,MA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import { RestClient, ReyaChainId } from '@reyaxyz/common';
|
|
2
|
-
import { CancelSLOrderParams, CancelSLOrderResult, GetPendingSLOrderParams, GetPendingSLOrderResult, RegisterSLOrderParams, RegisterSLOrderResult } from './types';
|
|
2
|
+
import { CancelSLOrderParams, CancelSLOrderResult, GetPendingSLOrderParams, GetPendingSLOrderResult, RegisterSLOrderParams, RegisterSLOrderResult, UpdateSLOrderParams, UpdateSLOrderResult } from './types';
|
|
3
3
|
export default class ConditionalOrdersClient extends RestClient {
|
|
4
4
|
private reyaChainId;
|
|
5
5
|
constructor(reyaChainId: ReyaChainId, host: string);
|
|
6
6
|
getPendingSLOrder(params: GetPendingSLOrderParams): Promise<GetPendingSLOrderResult>;
|
|
7
7
|
cancelSLOrder(params: CancelSLOrderParams): Promise<CancelSLOrderResult>;
|
|
8
8
|
registerSLOrder(params: RegisterSLOrderParams): Promise<RegisterSLOrderResult>;
|
|
9
|
+
updateSLOrder(params: UpdateSLOrderParams): Promise<UpdateSLOrderResult>;
|
|
9
10
|
private getPosition;
|
|
11
|
+
private createNonce;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,EAMZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EAEnB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,OAAO,CAAC,WAAW,CAAc;gBAErB,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM;IAK5C,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC;IAa7B,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;IAiBzB,eAAe,CACnB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IA4D3B,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;YAIjB,WAAW;IAQzB,OAAO,CAAC,WAAW;CAoBpB"}
|
|
@@ -2,6 +2,7 @@ import { StopLossOrder } from '@reyaxyz/common';
|
|
|
2
2
|
import { Signer, JsonRpcSigner } from 'ethers';
|
|
3
3
|
import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
|
|
4
4
|
export type CancelSLOrderParams = {
|
|
5
|
+
signer: Signer | JsonRpcSigner;
|
|
5
6
|
orderId: number;
|
|
6
7
|
};
|
|
7
8
|
export type CancelSLOrderResult = StopLossOrder;
|
|
@@ -21,7 +22,7 @@ export type ConditionalOrderDetails = {
|
|
|
21
22
|
orderType: number;
|
|
22
23
|
inputs: string;
|
|
23
24
|
signer: string;
|
|
24
|
-
nonce:
|
|
25
|
+
nonce: string;
|
|
25
26
|
};
|
|
26
27
|
export type MarketParams = {
|
|
27
28
|
id: MarketEntity['id'];
|
|
@@ -35,5 +36,13 @@ export type RegisterSLOrderParams = {
|
|
|
35
36
|
stopLossPrice: number;
|
|
36
37
|
market: MarketParams;
|
|
37
38
|
};
|
|
39
|
+
export type UpdateSLOrderParams = {
|
|
40
|
+
signer: Signer | JsonRpcSigner;
|
|
41
|
+
orderId: number;
|
|
42
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
43
|
+
stopLossPrice: number;
|
|
44
|
+
market: MarketParams;
|
|
45
|
+
};
|
|
38
46
|
export type RegisterSLOrderResult = StopLossOrder;
|
|
47
|
+
export type UpdateSLOrderResult = StopLossOrder;
|
|
39
48
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpE,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG,IAAI,CAAC;AAE3D,oBAAY,oBAAoB;IAC9B,UAAU,IAAI;CACf;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,YAAY,EAAE,MAAM,CAAC;C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,YAAY,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC;IACpD,sBAAsB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAC5E,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAClD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Candle, CandlesResolution, MarketEntity, LpTransactionHistoryEntity, TradingHistoryEntity, PositionHistoryEntity, PositionEntity, TransactionHistoryType, MarginAccountTransactionHistoryType, MarginAccountTransactionHistoryEntity, MarginAccountEntity, LpPositionEntity, LpPoolEntity, ReyaChainId, MoneyInOutChainId, GetLpPoolPerformanceChartDataResult, GetLpPoolBalanceChartDataResult, LpBalanceGranularity, MarginAccountBalanceGranularity, GetMarginAccountBalanceChartDataResult, MarginAccountCollateralsBalanceGranularity, GetMarginAccountCollateralsBalanceChartDataResult, GetAllMarginAccountsBalanceChartDataResult, AllMarginAccountsBalanceGranularity, GetFundingRateChartDataResult, FundingRateHistoryGranularity, MoneyInOutConfigurationPerTokenName, } from '@reyaxyz/common';
|
|
2
2
|
export * from './modules/account/types';
|
|
3
|
+
export * from './modules/conditional-orders/types';
|
|
3
4
|
export * from './modules/lp/types';
|
|
4
5
|
export * from './modules/markets/types';
|
|
5
6
|
export * from './modules/tokens/types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,mCAAmC,EACnC,qCAAqC,EACrC,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,+BAA+B,EAC/B,sCAAsC,EACtC,0CAA0C,EAC1C,iDAAiD,EACjD,0CAA0C,EAC1C,mCAAmC,EACnC,6BAA6B,EAC7B,6BAA6B,EAC7B,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,2CAA2C,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,mCAAmC,EACnC,qCAAqC,EACrC,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,+BAA+B,EAC/B,sCAAsC,EACtC,0CAA0C,EAC1C,iDAAiD,EACjD,0CAA0C,EAC1C,mCAAmC,EACnC,6BAA6B,EAC7B,6BAA6B,EAC7B,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,wDAAwD,CAAC;AACvE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,2CAA2C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.103.
|
|
3
|
+
"version": "0.103.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@reyaxyz/common": "0.155.
|
|
36
|
+
"@reyaxyz/common": "0.155.3",
|
|
37
37
|
"bignumber.js": "^9.1.2",
|
|
38
38
|
"ethers": "6.9.0",
|
|
39
39
|
"isomorphic-ws": "^5.0.0",
|
|
40
40
|
"ws": "^8.16.0"
|
|
41
41
|
},
|
|
42
42
|
"packageManager": "pnpm@8.3.1",
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "d588a7b45d04c349ac09d10aff233fbc15c0833e",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/ws": "8.5.10"
|
|
46
46
|
}
|
|
@@ -60,14 +60,6 @@ export default class AccountClient extends RestClient {
|
|
|
60
60
|
limit: params.limit,
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
response.forEach((account) => {
|
|
64
|
-
account.positions.forEach((position) => {
|
|
65
|
-
if (Math.random() > 0.5) {
|
|
66
|
-
position.stopLossPrice = Math.random() * 1000;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
63
|
return response;
|
|
72
64
|
}
|
|
73
65
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
calculateMaxPriceLimit,
|
|
3
3
|
PositionEntity,
|
|
4
4
|
RestClient,
|
|
5
5
|
ReyaChainId,
|
|
6
6
|
signConditionalOrder,
|
|
7
|
+
signCancelConditionalOrder,
|
|
7
8
|
StopLossOrder,
|
|
8
9
|
StopLossOrderStatus,
|
|
10
|
+
scale,
|
|
9
11
|
} from '@reyaxyz/common';
|
|
10
12
|
import { AbiCoder } from 'ethers';
|
|
11
13
|
import {
|
|
@@ -16,6 +18,8 @@ import {
|
|
|
16
18
|
GetPendingSLOrderResult,
|
|
17
19
|
RegisterSLOrderParams,
|
|
18
20
|
RegisterSLOrderResult,
|
|
21
|
+
UpdateSLOrderParams,
|
|
22
|
+
UpdateSLOrderResult,
|
|
19
23
|
} from './types';
|
|
20
24
|
|
|
21
25
|
export default class ConditionalOrdersClient extends RestClient {
|
|
@@ -29,7 +33,7 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
29
33
|
async getPendingSLOrder(
|
|
30
34
|
params: GetPendingSLOrderParams,
|
|
31
35
|
): Promise<GetPendingSLOrderResult> {
|
|
32
|
-
const uri = `/api/conditional-orders/sl/get-orders-by-position/${StopLossOrderStatus.
|
|
36
|
+
const uri = `/api/conditional-orders/sl/get-orders-by-position/${StopLossOrderStatus.PENDING}/${params.marketId}/${params.accountId}`;
|
|
33
37
|
const response = await this.get<GetPendingSLOrderResult[]>(uri);
|
|
34
38
|
|
|
35
39
|
if (response.length > 1) {
|
|
@@ -41,17 +45,21 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
41
45
|
return response[0];
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
// todo: need authentication
|
|
45
48
|
async cancelSLOrder(
|
|
46
49
|
params: CancelSLOrderParams,
|
|
47
50
|
): Promise<CancelSLOrderResult> {
|
|
48
|
-
const
|
|
49
|
-
|
|
51
|
+
const signature = await signCancelConditionalOrder(
|
|
52
|
+
params.signer,
|
|
53
|
+
params.orderId,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const uri = `/api/conditional-orders/sl/cancel-order`;
|
|
57
|
+
return this.put<StopLossOrder>(
|
|
50
58
|
uri,
|
|
51
59
|
{},
|
|
52
60
|
{
|
|
53
61
|
orderId: params.orderId,
|
|
54
|
-
|
|
62
|
+
userSignature: signature,
|
|
55
63
|
},
|
|
56
64
|
);
|
|
57
65
|
}
|
|
@@ -69,16 +77,19 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
69
77
|
throw new Error('Position with no exposure');
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
const orderPriceLimit =
|
|
73
|
-
params.market.currentPrice,
|
|
74
|
-
positionBase,
|
|
75
|
-
);
|
|
80
|
+
const orderPriceLimit = Number(calculateMaxPriceLimit(positionBase < 0));
|
|
76
81
|
|
|
77
82
|
const inputs = AbiCoder.defaultAbiCoder().encode(
|
|
78
83
|
['uint256', 'uint256'],
|
|
79
|
-
[params.stopLossPrice, orderPriceLimit],
|
|
84
|
+
[scale(18)(params.stopLossPrice), orderPriceLimit],
|
|
80
85
|
);
|
|
81
|
-
const
|
|
86
|
+
const creationTimestampMs = Date.now();
|
|
87
|
+
const nonce = this.createNonce(
|
|
88
|
+
params.marginAccountId,
|
|
89
|
+
params.market.id,
|
|
90
|
+
creationTimestampMs,
|
|
91
|
+
);
|
|
92
|
+
const deadline = 10 ** 18; // very big number for timestamp in seconds - infinite deadline
|
|
82
93
|
|
|
83
94
|
const signature = await signConditionalOrder(
|
|
84
95
|
params.signer,
|
|
@@ -90,19 +101,9 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
90
101
|
ConditionalOrderType.StopLoss,
|
|
91
102
|
inputs,
|
|
92
103
|
nonce,
|
|
93
|
-
|
|
104
|
+
deadline,
|
|
94
105
|
);
|
|
95
106
|
|
|
96
|
-
// cancel old order existing order
|
|
97
|
-
if (position.stopLossPrice) {
|
|
98
|
-
const order = await this.getPendingSLOrder({
|
|
99
|
-
accountId: params.marginAccountId,
|
|
100
|
-
marketId: params.market.id,
|
|
101
|
-
});
|
|
102
|
-
if (order != null) {
|
|
103
|
-
await this.cancelSLOrder({ orderId: order.orderId });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
107
|
// create new entry
|
|
107
108
|
const uri = `/api/conditional-orders/sl/create-order`;
|
|
108
109
|
return this.post<StopLossOrder>(
|
|
@@ -115,12 +116,22 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
115
116
|
stopPrice: params.stopLossPrice,
|
|
116
117
|
signerWallet: await params.signer.getAddress(),
|
|
117
118
|
nonce: nonce,
|
|
118
|
-
signature: signature
|
|
119
|
-
|
|
119
|
+
signature: signature,
|
|
120
|
+
deadline: deadline,
|
|
121
|
+
orderPriceLimit: orderPriceLimit,
|
|
122
|
+
exchangeId: params.market.exchangeId,
|
|
123
|
+
poolId: params.market.counterpartyAccountIds[0],
|
|
124
|
+
timestampMs: creationTimestampMs,
|
|
120
125
|
},
|
|
121
126
|
);
|
|
122
127
|
}
|
|
123
128
|
|
|
129
|
+
async updateSLOrder(
|
|
130
|
+
params: UpdateSLOrderParams,
|
|
131
|
+
): Promise<UpdateSLOrderResult> {
|
|
132
|
+
return await this.registerSLOrder(params as RegisterSLOrderParams);
|
|
133
|
+
}
|
|
134
|
+
|
|
124
135
|
private async getPosition(
|
|
125
136
|
accountId: number,
|
|
126
137
|
marketId: number,
|
|
@@ -128,4 +139,25 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
128
139
|
const uri = `/api/account/marginAccount/position/${accountId}/${marketId}`;
|
|
129
140
|
return this.get<PositionEntity>(uri);
|
|
130
141
|
}
|
|
142
|
+
|
|
143
|
+
private createNonce(
|
|
144
|
+
accountId: number,
|
|
145
|
+
marketId: number,
|
|
146
|
+
timestampMs: number,
|
|
147
|
+
): string {
|
|
148
|
+
// Validate the input ranges
|
|
149
|
+
if (marketId < 0 || marketId >= 2 ** 32)
|
|
150
|
+
throw new Error('marketId is out of range');
|
|
151
|
+
if (accountId < BigInt(0) || accountId >= 2 ** 128)
|
|
152
|
+
throw new Error('accountId is out of range');
|
|
153
|
+
if (timestampMs < 0 || timestampMs >= 2 ** 64)
|
|
154
|
+
throw new Error('timestamp is out of range');
|
|
155
|
+
|
|
156
|
+
const hashUint256 =
|
|
157
|
+
(BigInt(accountId) << BigInt(98)) |
|
|
158
|
+
(BigInt(timestampMs) << BigInt(32)) |
|
|
159
|
+
BigInt(marketId);
|
|
160
|
+
|
|
161
|
+
return hashUint256.toString();
|
|
162
|
+
}
|
|
131
163
|
}
|
|
@@ -3,6 +3,7 @@ import { Signer, JsonRpcSigner } from 'ethers';
|
|
|
3
3
|
import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
|
|
4
4
|
|
|
5
5
|
export type CancelSLOrderParams = {
|
|
6
|
+
signer: Signer | JsonRpcSigner;
|
|
6
7
|
orderId: number;
|
|
7
8
|
};
|
|
8
9
|
|
|
@@ -27,7 +28,7 @@ export type ConditionalOrderDetails = {
|
|
|
27
28
|
orderType: number;
|
|
28
29
|
inputs: string;
|
|
29
30
|
signer: string;
|
|
30
|
-
nonce:
|
|
31
|
+
nonce: string;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type MarketParams = {
|
|
@@ -44,4 +45,13 @@ export type RegisterSLOrderParams = {
|
|
|
44
45
|
market: MarketParams;
|
|
45
46
|
};
|
|
46
47
|
|
|
48
|
+
export type UpdateSLOrderParams = {
|
|
49
|
+
signer: Signer | JsonRpcSigner;
|
|
50
|
+
orderId: number;
|
|
51
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
52
|
+
stopLossPrice: number;
|
|
53
|
+
market: MarketParams;
|
|
54
|
+
};
|
|
55
|
+
|
|
47
56
|
export type RegisterSLOrderResult = StopLossOrder;
|
|
57
|
+
export type UpdateSLOrderResult = StopLossOrder;
|
package/src/clients/types.ts
CHANGED
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
MoneyInOutConfigurationPerTokenName,
|
|
30
30
|
} from '@reyaxyz/common';
|
|
31
31
|
export * from './modules/account/types';
|
|
32
|
+
export * from './modules/conditional-orders/types';
|
|
32
33
|
export * from './modules/lp/types';
|
|
33
34
|
export * from './modules/markets/types';
|
|
34
35
|
export * from './modules/tokens/types';
|