@reyaxyz/api-sdk 0.110.3 → 0.111.1
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/README.md +1 -1
- package/dist/clients/modules/conditional-orders/index.js +24 -0
- package/dist/clients/modules/conditional-orders/index.js.map +1 -1
- package/dist/clients/modules/conditional-orders/types.js.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 +17 -1
- package/dist/types/clients/modules/conditional-orders/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/conditional-orders/index.ts +27 -0
- package/src/clients/modules/conditional-orders/types.ts +21 -1
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -62,6 +62,30 @@ var ConditionalOrdersClient = /** @class */ (function (_super) {
|
|
|
62
62
|
_this.reyaChainId = reyaChainId;
|
|
63
63
|
return _this;
|
|
64
64
|
}
|
|
65
|
+
// ------ Conditional Orders History ---
|
|
66
|
+
ConditionalOrdersClient.prototype.getConditionalOrdersHistoryForMarginAccount = function (params) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var uri;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
uri = "/api/conditional-orders/get-orders-by-account/".concat(params.marginAccountId);
|
|
71
|
+
return [2 /*return*/, this.get(uri, {
|
|
72
|
+
limit: params.limit,
|
|
73
|
+
})];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
ConditionalOrdersClient.prototype.getConditionalOrdersHistoryForMarginAccountPaginated = function (params) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var uri;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
uri = "/api/conditional-orders/get-orders-by-account/".concat(params.marginAccountId, "/paginated");
|
|
82
|
+
return [2 /*return*/, this.get(uri, {
|
|
83
|
+
page: params.page,
|
|
84
|
+
perPage: params.perPage,
|
|
85
|
+
})];
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
65
89
|
ConditionalOrdersClient.prototype.alreadyGaveTradePermissions = function (params) {
|
|
66
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
67
91
|
var uri, response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAWyB;AACzB,iCAAkC;AAElC,iCAYiB;AACjB,iCAAsC;AAEtC;IAAqD,2CAAU;IAG7D,iCAAY,WAAwB,EAAE,IAAY;QAChD,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC;QACZ,KAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;IACjC,CAAC;IAEK,6DAA2B,GAAjC,UACE,MAAwC;;;;;;wBAElC,GAAG,GAAG,wDAAiD,MAAM,CAAC,SAAS,CAAE,CAAC;wBAC/D,qBAAM,IAAI,CAAC,GAAG,CAAU,GAAG,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBAE7C,sBAAO;gCACL,eAAe,EAAE,QAAQ;6BAC1B,EAAC;;;;KACH;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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AI,CAAC,WAAW,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,4BAAoB,CAAC,QAAQ,EAC7B,MAAM,EACN,KAAK,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,YAAY,cAAA;gCACZ,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AAvLD,CAAqD,mBAAU,GAuL9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n StopLossOrder,\n StopLossOrderStatus,\n scale,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport {\n AlreadyGaveTradePermissionParams,\n AlreadyGaveTradePermissionResult,\n CancelSLOrderParams,\n CancelSLOrderResult,\n ConditionalOrderType,\n GetPendingSLOrderParams,\n GetPendingSLOrderResult,\n RegisterSLOrderParams,\n RegisterSLOrderResult,\n UpdateSLOrderParams,\n UpdateSLOrderResult,\n} from './types';\nimport { createNonce } from './utils';\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 alreadyGaveTradePermissions(\n params: AlreadyGaveTradePermissionParams,\n ): Promise<AlreadyGaveTradePermissionResult> {\n const uri = `/api/conditional-orders/gave-trade-permission/${params.accountId}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\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 inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\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.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n async updateSLOrder(\n params: UpdateSLOrderParams,\n ): Promise<UpdateSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/update-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private async parseSlOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n stopLossPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const isLongOrder = positionBase < 0;\n const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],\n );\n const creationTimestampMs = Date.now();\n const nonce = createNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signConditionalOrder(\n signer,\n this.reyaChainId,\n accountId,\n marketId,\n exchangeId,\n counterpartyAccountIds,\n ConditionalOrderType.StopLoss,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n positionBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAsB,EACtB,4BAAoB,CAAC,QAAQ,EAC7B,MAAM,EACN,KAAK,EACL,uCAA8B,CAC/B,EAAA;;wBAXK,SAAS,GAAG,SAWjB;wBAED,sBAAO;gCACL,SAAS,WAAA;gCACT,YAAY,cAAA;gCACZ,eAAe,iBAAA;gCACf,KAAK,OAAA;gCACL,QAAQ,EAAE,uCAA8B;gCACxC,mBAAmB,qBAAA;6BACpB,EAAC;;;;KACH;IACH,8BAAC;AAAD,CAAC,AA9MD,CAAqD,mBAAU,GA8M9D","sourcesContent":["import {\n calculateMaxPriceLimit,\n PositionEntity,\n RestClient,\n ReyaChainId,\n signConditionalOrder,\n signCancelConditionalOrder,\n StopLossOrder,\n StopLossOrderStatus,\n scale,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n} from '@reyaxyz/common';\nimport { AbiCoder } from 'ethers';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport {\n AlreadyGaveTradePermissionParams,\n AlreadyGaveTradePermissionResult,\n CancelSLOrderParams,\n CancelSLOrderResult,\n ConditionalOrderType,\n GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n GetConditionalOrdersHistoryForMarginAccountPaginatedResult,\n GetConditionalOrdersHistoryForMarginAccountParams,\n GetConditionalOrdersHistoryForMarginAccountResult,\n GetPendingSLOrderParams,\n GetPendingSLOrderResult,\n RegisterSLOrderParams,\n RegisterSLOrderResult,\n UpdateSLOrderParams,\n UpdateSLOrderResult,\n} from './types';\nimport { createNonce } from './utils';\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 // ------ Conditional Orders History ---\n async getConditionalOrdersHistoryForMarginAccount(\n params: GetConditionalOrdersHistoryForMarginAccountParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {\n limit: params.limit,\n });\n }\n\n async getConditionalOrdersHistoryForMarginAccountPaginated(\n params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams,\n ): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult> {\n const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}/paginated`;\n return this.get<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>(\n uri,\n {\n page: params.page,\n perPage: params.perPage,\n },\n );\n }\n\n async alreadyGaveTradePermissions(\n params: AlreadyGaveTradePermissionParams,\n ): Promise<AlreadyGaveTradePermissionResult> {\n const uri = `/api/conditional-orders/gave-trade-permission/${params.accountId}`;\n const response = await this.get<boolean>(uri);\n\n return {\n permissionGiven: response,\n };\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 inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\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.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n async updateSLOrder(\n params: UpdateSLOrderParams,\n ): Promise<UpdateSLOrderResult> {\n const inputs = await this.parseSlOrderInputs(\n params.signer,\n params.marginAccountId,\n params.marketId,\n params.stopLossPrice,\n params.supportingParams.exchangeId,\n params.supportingParams.counterpartyAccountIds,\n );\n\n // create new entry\n const uri = `/api/conditional-orders/sl/update-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: params.marginAccountId,\n marketId: params.marketId,\n isLong: inputs.positionBase < 0,\n stopPrice: params.stopLossPrice,\n signerWallet: await params.signer.getAddress(),\n nonce: inputs.nonce.toString(),\n signature: inputs.signature,\n deadline: inputs.deadline,\n orderPriceLimit: inputs.orderPriceLimit.toString(),\n exchangeId: params.supportingParams.exchangeId,\n poolId: params.supportingParams.counterpartyAccountIds[0],\n timestampMs: inputs.creationTimestampMs,\n },\n );\n }\n\n private async getPosition(\n accountId: number,\n marketId: number,\n ): Promise<PositionEntity> {\n const uri = `/api/accounts/marginAccount/position/${accountId}/${marketId}`;\n return this.get<PositionEntity>(uri);\n }\n\n private async parseSlOrderInputs(\n signer: Signer | JsonRpcSigner,\n accountId: number,\n marketId: number,\n stopLossPrice: number,\n exchangeId: number,\n counterpartyAccountIds: number[],\n ): Promise<{\n signature: string;\n positionBase: number;\n orderPriceLimit: bigint;\n nonce: bigint;\n deadline: number;\n creationTimestampMs: number;\n }> {\n const position = await this.getPosition(accountId, marketId);\n const positionBase = position.base;\n\n if (positionBase === 0) {\n throw new Error('Position with no exposure');\n }\n\n const isLongOrder = positionBase < 0;\n const orderPriceLimit = calculateMaxPriceLimit(isLongOrder);\n\n const inputs = AbiCoder.defaultAbiCoder().encode(\n ['bool', 'uint256', 'uint256'],\n [isLongOrder, scale(18)(stopLossPrice), orderPriceLimit],\n );\n const creationTimestampMs = Date.now();\n const nonce = createNonce(accountId, marketId, creationTimestampMs);\n\n const signature = await signConditionalOrder(\n signer,\n this.reyaChainId,\n accountId,\n marketId,\n exchangeId,\n counterpartyAccountIds,\n ConditionalOrderType.StopLoss,\n inputs,\n nonce,\n CONDITIONAL_ORDER_SIG_DEADLINE,\n );\n\n return {\n signature,\n positionBase,\n orderPriceLimit,\n nonce,\n deadline: CONDITIONAL_ORDER_SIG_DEADLINE,\n creationTimestampMs,\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
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: string;\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: bigint;\n};\n\nexport type OrderSupportingParams = {\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 marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type UpdateSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type RegisterSLOrderResult = StopLossOrder;\nexport type UpdateSLOrderResult = StopLossOrder;\n\nexport type AlreadyGaveTradePermissionParams = {\n accountId: number;\n};\n\nexport type AlreadyGaveTradePermissionResult = {\n permissionGiven: boolean;\n};\n"]}
|
|
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, UnifiedConditionalOrderType } from '@reyaxyz/common';\nimport { Signer, JsonRpcSigner } from 'ethers';\nimport { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';\n\nexport type CancelSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n orderId: string;\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: bigint;\n};\n\nexport type OrderSupportingParams = {\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 marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type UpdateSLOrderParams = {\n signer: Signer | JsonRpcSigner;\n marginAccountId: MarginAccountEntity['id'];\n stopLossPrice: number;\n marketId: number;\n supportingParams: OrderSupportingParams;\n};\n\nexport type RegisterSLOrderResult = StopLossOrder;\nexport type UpdateSLOrderResult = StopLossOrder;\n\nexport type AlreadyGaveTradePermissionParams = {\n accountId: number;\n};\n\nexport type AlreadyGaveTradePermissionResult = {\n permissionGiven: boolean;\n};\n\n// ---- Conditional Orders History ---\nexport type GetConditionalOrdersHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n page: number;\n perPage: number;\n};\n\nexport type GetConditionalOrdersHistoryForMarginAccountResult =\n UnifiedConditionalOrderType[];\nexport type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {\n data: UnifiedConditionalOrderType[];\n totalCount: number;\n};\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { RestClient, ReyaChainId } from '@reyaxyz/common';
|
|
2
|
-
import { AlreadyGaveTradePermissionParams, AlreadyGaveTradePermissionResult, CancelSLOrderParams, CancelSLOrderResult, GetPendingSLOrderParams, GetPendingSLOrderResult, RegisterSLOrderParams, RegisterSLOrderResult, UpdateSLOrderParams, UpdateSLOrderResult } from './types';
|
|
2
|
+
import { AlreadyGaveTradePermissionParams, AlreadyGaveTradePermissionResult, CancelSLOrderParams, CancelSLOrderResult, GetConditionalOrdersHistoryForMarginAccountPaginatedParams, GetConditionalOrdersHistoryForMarginAccountPaginatedResult, GetConditionalOrdersHistoryForMarginAccountParams, GetConditionalOrdersHistoryForMarginAccountResult, 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
|
+
getConditionalOrdersHistoryForMarginAccount(params: GetConditionalOrdersHistoryForMarginAccountParams): Promise<GetConditionalOrdersHistoryForMarginAccountResult>;
|
|
7
|
+
getConditionalOrdersHistoryForMarginAccountPaginated(params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>;
|
|
6
8
|
alreadyGaveTradePermissions(params: AlreadyGaveTradePermissionParams): Promise<AlreadyGaveTradePermissionResult>;
|
|
7
9
|
getPendingSLOrder(params: GetPendingSLOrderParams): Promise<GetPendingSLOrderResult>;
|
|
8
10
|
cancelSLOrder(params: CancelSLOrderParams): Promise<CancelSLOrderResult>;
|
|
@@ -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,EAOZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,EAEnB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,OAAO,CAAC,WAAW,CAAc;gBAErB,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,WAAW,EAOZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,EAEnB,0DAA0D,EAC1D,0DAA0D,EAC1D,iDAAiD,EACjD,iDAAiD,EACjD,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAAU;IAC7D,OAAO,CAAC,WAAW,CAAc;gBAErB,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM;IAM5C,2CAA2C,CAC/C,MAAM,EAAE,iDAAiD,GACxD,OAAO,CAAC,iDAAiD,CAAC;IAOvD,oDAAoD,CACxD,MAAM,EAAE,0DAA0D,GACjE,OAAO,CAAC,0DAA0D,CAAC;IAWhE,2BAA2B,CAC/B,MAAM,EAAE,gCAAgC,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAStC,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;IAgC3B,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;YAgCjB,WAAW;YAQX,kBAAkB;CAsDjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StopLossOrder } from '@reyaxyz/common';
|
|
1
|
+
import { StopLossOrder, UnifiedConditionalOrderType } from '@reyaxyz/common';
|
|
2
2
|
import { Signer, JsonRpcSigner } from 'ethers';
|
|
3
3
|
import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
|
|
4
4
|
export type CancelSLOrderParams = {
|
|
@@ -51,4 +51,20 @@ export type AlreadyGaveTradePermissionParams = {
|
|
|
51
51
|
export type AlreadyGaveTradePermissionResult = {
|
|
52
52
|
permissionGiven: boolean;
|
|
53
53
|
};
|
|
54
|
+
export type GetConditionalOrdersHistoryForMarginAccountParams = {
|
|
55
|
+
address: string;
|
|
56
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
57
|
+
limit?: number;
|
|
58
|
+
};
|
|
59
|
+
export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
|
|
60
|
+
address: string;
|
|
61
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
62
|
+
page: number;
|
|
63
|
+
perPage: number;
|
|
64
|
+
};
|
|
65
|
+
export type GetConditionalOrdersHistoryForMarginAccountResult = UnifiedConditionalOrderType[];
|
|
66
|
+
export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
|
|
67
|
+
data: UnifiedConditionalOrderType[];
|
|
68
|
+
totalCount: number;
|
|
69
|
+
};
|
|
54
70
|
//# 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;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/conditional-orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,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,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,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;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CACnB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,iDAAiD,GAAG;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,MAAM,MAAM,0DAA0D,GAAG;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iDAAiD,GAC3D,2BAA2B,EAAE,CAAC;AAChC,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,2BAA2B,EAAE,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.111.1",
|
|
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.
|
|
36
|
+
"@reyaxyz/common": "0.163.1",
|
|
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": "f1076b6346a0c654708443a2d773d802f4e4f1d3",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/ws": "8.5.10"
|
|
46
46
|
}
|
|
@@ -18,6 +18,10 @@ import {
|
|
|
18
18
|
CancelSLOrderParams,
|
|
19
19
|
CancelSLOrderResult,
|
|
20
20
|
ConditionalOrderType,
|
|
21
|
+
GetConditionalOrdersHistoryForMarginAccountPaginatedParams,
|
|
22
|
+
GetConditionalOrdersHistoryForMarginAccountPaginatedResult,
|
|
23
|
+
GetConditionalOrdersHistoryForMarginAccountParams,
|
|
24
|
+
GetConditionalOrdersHistoryForMarginAccountResult,
|
|
21
25
|
GetPendingSLOrderParams,
|
|
22
26
|
GetPendingSLOrderResult,
|
|
23
27
|
RegisterSLOrderParams,
|
|
@@ -35,6 +39,29 @@ export default class ConditionalOrdersClient extends RestClient {
|
|
|
35
39
|
this.reyaChainId = reyaChainId;
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
// ------ Conditional Orders History ---
|
|
43
|
+
async getConditionalOrdersHistoryForMarginAccount(
|
|
44
|
+
params: GetConditionalOrdersHistoryForMarginAccountParams,
|
|
45
|
+
): Promise<GetConditionalOrdersHistoryForMarginAccountResult> {
|
|
46
|
+
const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}`;
|
|
47
|
+
return this.get<GetConditionalOrdersHistoryForMarginAccountResult>(uri, {
|
|
48
|
+
limit: params.limit,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async getConditionalOrdersHistoryForMarginAccountPaginated(
|
|
53
|
+
params: GetConditionalOrdersHistoryForMarginAccountPaginatedParams,
|
|
54
|
+
): Promise<GetConditionalOrdersHistoryForMarginAccountPaginatedResult> {
|
|
55
|
+
const uri = `/api/conditional-orders/get-orders-by-account/${params.marginAccountId}/paginated`;
|
|
56
|
+
return this.get<GetConditionalOrdersHistoryForMarginAccountPaginatedResult>(
|
|
57
|
+
uri,
|
|
58
|
+
{
|
|
59
|
+
page: params.page,
|
|
60
|
+
perPage: params.perPage,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
38
65
|
async alreadyGaveTradePermissions(
|
|
39
66
|
params: AlreadyGaveTradePermissionParams,
|
|
40
67
|
): Promise<AlreadyGaveTradePermissionResult> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StopLossOrder } from '@reyaxyz/common';
|
|
1
|
+
import { StopLossOrder, UnifiedConditionalOrderType } from '@reyaxyz/common';
|
|
2
2
|
import { Signer, JsonRpcSigner } from 'ethers';
|
|
3
3
|
import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
|
|
4
4
|
|
|
@@ -63,3 +63,23 @@ export type AlreadyGaveTradePermissionParams = {
|
|
|
63
63
|
export type AlreadyGaveTradePermissionResult = {
|
|
64
64
|
permissionGiven: boolean;
|
|
65
65
|
};
|
|
66
|
+
|
|
67
|
+
// ---- Conditional Orders History ---
|
|
68
|
+
export type GetConditionalOrdersHistoryForMarginAccountParams = {
|
|
69
|
+
address: string;
|
|
70
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
71
|
+
limit?: number;
|
|
72
|
+
};
|
|
73
|
+
export type GetConditionalOrdersHistoryForMarginAccountPaginatedParams = {
|
|
74
|
+
address: string;
|
|
75
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
76
|
+
page: number;
|
|
77
|
+
perPage: number;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type GetConditionalOrdersHistoryForMarginAccountResult =
|
|
81
|
+
UnifiedConditionalOrderType[];
|
|
82
|
+
export type GetConditionalOrdersHistoryForMarginAccountPaginatedResult = {
|
|
83
|
+
data: UnifiedConditionalOrderType[];
|
|
84
|
+
totalCount: number;
|
|
85
|
+
};
|