Skip to content

Commit

Permalink
Merge pull request #419 from JJ-Cro/wsapi
Browse files Browse the repository at this point in the history
feat(): added/updated types with latest documentation changes
  • Loading branch information
tiagosiebler authored Feb 17, 2025
2 parents 0952e5f + b8007f7 commit 91eedd0
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 114 deletions.
204 changes: 106 additions & 98 deletions src/rest-client-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ import {
SpotBorrowCheckResultV5,
SpotLeveragedTokenOrderHistoryV5,
SpotMarginStateV5,
SubAccountAllApiKeysResultV5,
SubMemberV5,
SwitchIsolatedMarginParamsV5,
SwitchPositionModeParamsV5,
Expand All @@ -191,6 +190,7 @@ import {
VipCollateralCoinsV5,
WalletBalanceV5,
WithdrawParamsV5,
WithdrawableAmountV5,
WithdrawalRecordV5,
} from './types';

Expand Down Expand Up @@ -551,7 +551,9 @@ export class RestClientV5 extends BaseRestClient {

cancelAllOrders(
params: CancelAllOrdersParamsV5,
): Promise<APIResponseV3WithTime<{ list: OrderResultV5[] }>> {
): Promise<
APIResponseV3WithTime<{ list: OrderResultV5[]; success: string }>
> {
return this.postPrivate('/v5/order/cancel-all', params);
}

Expand All @@ -566,6 +568,18 @@ export class RestClientV5 extends BaseRestClient {
return this.getPrivate('/v5/order/history', params);
}

/**
* Query users' execution records, sorted by execTime in descending order
*
* Unified account covers: Spot / Linear contract / Options
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*/
getExecutionList(
params: GetExecutionListParamsV5,
): Promise<APIResponseV3WithTime<CategoryCursorListV5<ExecutionV5[]>>> {
return this.getPrivate('/v5/execution/list', params);
}

/**
* This endpoint allows you to place more than one order in a single request.
* Covers: Option (UTA, UTA Pro) / USDT Perpetual, UDSC Perpetual, USDC Futures (UTA Pro)
Expand Down Expand Up @@ -675,7 +689,7 @@ export class RestClientV5 extends BaseRestClient {
* Only for institutional clients!
*/
setDisconnectCancelAllWindowV2(params: {
product: 'OPTION' | 'SPOT' | 'DERIVATIVES';
product?: 'OPTION' | 'SPOT' | 'DERIVATIVES';
timeWindow: number;
}): Promise<APIResponseV3<undefined>> {
return this.postPrivate('/v5/order/disconnected-cancel-all', params);
Expand Down Expand Up @@ -733,6 +747,7 @@ export class RestClientV5 extends BaseRestClient {
}

/**
* @deprecated
* This endpoint sets the take profit/stop loss (TP/SL) mode to full or partial.
*
* Unified account covers: Linear contract; normal account covers: USDT perpetual, inverse perpetual, inverse futures.
Expand Down Expand Up @@ -761,6 +776,7 @@ export class RestClientV5 extends BaseRestClient {
}

/**
* @deprecated
* The risk limit will limit the maximum position value you can hold under different margin requirements.
* If you want to hold a bigger position size, you need more margin.
*
Expand Down Expand Up @@ -811,18 +827,6 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/position/add-margin', params);
}

/**
* Query users' execution records, sorted by execTime in descending order
*
* Unified account covers: Spot / Linear contract / Options
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*/
getExecutionList(
params: GetExecutionListParamsV5,
): Promise<APIResponseV3WithTime<CategoryCursorListV5<ExecutionV5[]>>> {
return this.getPrivate('/v5/execution/list', params);
}

/**
* Query user's closed profit and loss records. The results are sorted by createdTime in descending order.
*
Expand Down Expand Up @@ -1099,6 +1103,19 @@ export class RestClientV5 extends BaseRestClient {
return this.getPrivate('/v5/account/info');
}

/**
* Query the DCP configuration of the account's contracts (USDT perpetual, USDC perpetual and USDC Futures) / spot / options.
*
* Only the configured main / sub account can query information from this API. Calling this API by an account always returns empty.
*
* INFO
* support linear contract (USDT, USDC Perp & USDC Futures) / Spot / Options only
* Unified account only
*/
getDCPInfo(): Promise<APIResponseV3WithTime<{ dcpInfos: DCPInfoV5[] }>> {
return this.getPrivate('/v5/account/query-dcp-info');
}

/**
* Query transaction logs in Unified account.
*/
Expand Down Expand Up @@ -1184,23 +1201,34 @@ export class RestClientV5 extends BaseRestClient {
}

/**
* Query the DCP configuration of the account's contracts (USDT perpetual, USDC perpetual and USDC Futures) / spot / options.
*
* Only the configured main / sub account can query information from this API. Calling this API by an account always returns empty.
****** Asset APIs
*
* INFO
* support linear contract (USDT, USDC Perp & USDC Futures) / Spot / Options only
* Unified account only
*/
getDCPInfo(): Promise<APIResponseV3WithTime<{ dcpInfos: DCPInfoV5[] }>> {
return this.getPrivate('/v5/account/query-dcp-info');
}

/**
* Query option delivery records, sorted by deliveryTime in descending order.
*
****** Asset APIs
* Covers: Option
*/
getDeliveryRecord(
params: GetDeliveryRecordParamsV5,
): Promise<APIResponseV3WithTime<CategoryCursorListV5<DeliveryRecordV5[]>>> {
return this.getPrivate('/v5/asset/delivery-record', params);
}

/**
* Query session settlement records of USDC perpetual
*
* Covers: Linear contract (USDC Perpetual only, Unified Account)
*/
getSettlementRecords(
params: GetSettlementRecordParamsV5,
): Promise<
APIResponseV3WithTime<CategoryCursorListV5<SettlementRecordV5[]>>
> {
return this.getPrivate('/v5/asset/settlement-record', params);
}

/**
* Query the coin exchange records.
Expand All @@ -1217,27 +1245,29 @@ export class RestClientV5 extends BaseRestClient {
}

/**
* Query option delivery records, sorted by deliveryTime in descending order.
*
* Covers: Option
* Query coin information, including chain information, withdraw and deposit status.
*/
getDeliveryRecord(
params: GetDeliveryRecordParamsV5,
): Promise<APIResponseV3WithTime<CategoryCursorListV5<DeliveryRecordV5[]>>> {
return this.getPrivate('/v5/asset/delivery-record', params);
getCoinInfo(
coin?: string,
): Promise<APIResponseV3WithTime<{ rows: CoinInfoV5[] }>> {
return this.getPrivate(
'/v5/asset/coin/query-info',
coin ? { coin } : undefined,
);
}

/**
* Query session settlement records of USDC perpetual
* Query the sub UIDs under a main UID
*
* Covers: Linear contract (USDC Perpetual only, Unified Account)
* CAUTION: Can query by the master UID's api key only
*/
getSettlementRecords(
params: GetSettlementRecordParamsV5,
): Promise<
APIResponseV3WithTime<CategoryCursorListV5<SettlementRecordV5[]>>
getSubUID(): Promise<
APIResponseV3WithTime<{
subMemberIds: string[];
transferableSubMemberIds: string[];
}>
> {
return this.getPrivate('/v5/asset/settlement-record', params);
return this.getPrivate('/v5/asset/transfer/query-sub-member-list');
}

/**
Expand Down Expand Up @@ -1280,6 +1310,15 @@ export class RestClientV5 extends BaseRestClient {
);
}

/**
* Query withdrawable amount.
*/
getWithdrawableAmount(params: {
coin: string;
}): Promise<APIResponseV3<{ rows: WithdrawableAmountV5[] }>> {
return this.getPrivate('/v5/asset/withdraw/withdrawable-amount', params);
}

/**
* Query the transferable coin list between each account type.
*/
Expand Down Expand Up @@ -1327,20 +1366,6 @@ export class RestClientV5 extends BaseRestClient {
);
}

/**
* Query the sub UIDs under a main UID
*
* CAUTION: Can query by the master UID's api key only
*/
getSubUID(): Promise<
APIResponseV3WithTime<{
subMemberIds: string[];
transferableSubMemberIds: string[];
}>
> {
return this.getPrivate('/v5/asset/transfer/query-sub-member-list');
}

/**
* Enable Universal Transfer for Sub UID
*
Expand Down Expand Up @@ -1396,7 +1421,7 @@ export class RestClientV5 extends BaseRestClient {
nextPageCursor: string;
}>
> {
return this.get('/v5/asset/deposit/query-allowed-list', params);
return this.getPrivate('/v5/asset/deposit/query-allowed-list', params);
}

/**
Expand Down Expand Up @@ -1497,6 +1522,7 @@ export class RestClientV5 extends BaseRestClient {
}

/**
* @deprecated - duplicate function, use getSubDepositAddress() instead
* Query the deposit address information of SUB account.
* @deprecated Duplicate endpoint - Use getSubDepositAddress() instead
*
Expand All @@ -1520,18 +1546,6 @@ export class RestClientV5 extends BaseRestClient {
});
}

/**
* Query coin information, including chain information, withdraw and deposit status.
*/
getCoinInfo(
coin?: string,
): Promise<APIResponseV3WithTime<{ rows: CoinInfoV5[] }>> {
return this.getPrivate(
'/v5/asset/coin/query-info',
coin ? { coin } : undefined,
);
}

/**
* Query withdrawal records.
*/
Expand All @@ -1541,15 +1555,6 @@ export class RestClientV5 extends BaseRestClient {
return this.getPrivate('/v5/asset/withdraw/query-record', params);
}

/**
* Query withdrawable amount.
*/
getWithdrawableAmount(params: {
coin: string;
}): Promise<APIResponseV3<{ rows: WithdrawalRecordV5[] }>> {
return this.getPrivate('/v5/asset/withdraw/withdrawable-amount', params);
}

/**
* Get Exchange Entity List.
*
Expand Down Expand Up @@ -1621,7 +1626,7 @@ export class RestClientV5 extends BaseRestClient {
* Query the exchange result by sending quoteTxId.
*/
getConvertStatus(params: {
quoteTxId?: string;
quoteTxId: string;
accountType:
| 'eb_convert_funding'
| 'eb_convert_uta'
Expand Down Expand Up @@ -1701,15 +1706,6 @@ export class RestClientV5 extends BaseRestClient {
return this.getPrivate('/v5/user/submembers', params);
}

/**
* Query all api keys information of a sub UID.
*/
getSubAccountAllApiKeys(
params: GetSubAccountAllApiKeysParamsV5,
): Promise<APIResponseV3WithTime<SubAccountAllApiKeysResultV5>> {
return this.getPrivate('/v5/user/sub-apikeys', params);
}

/**
* Froze sub uid. Use master user's api key only.
*
Expand All @@ -1733,6 +1729,18 @@ export class RestClientV5 extends BaseRestClient {
return this.getPrivate('/v5/user/query-api');
}

/**
* Query all api keys information of a sub UID.
*/
getSubAccountAllApiKeys(params: GetSubAccountAllApiKeysParamsV5): Promise<
APIResponseV3WithTime<{
result: ApiKeyInfoV5[];
nextPageCursor: string;
}>
> {
return this.getPrivate('/v5/user/sub-apikeys', params);
}

getUIDWalletType(params: { memberIds: string }): Promise<
APIResponseV3WithTime<{
accounts: {
Expand All @@ -1741,7 +1749,7 @@ export class RestClientV5 extends BaseRestClient {
}[];
}>
> {
return this.getPrivate('/v5/user/query-api', params);
return this.getPrivate('/v5/user/get-member-type', params);
}

/**
Expand Down Expand Up @@ -1770,6 +1778,19 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/user/update-sub-api', params);
}

/**
* Delete a sub UID. Before deleting the UID, please make sure there are no assets.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
deleteSubMember(
params: DeleteSubMemberParamsV5,
): Promise<APIResponseV3WithTime<{}>> {
return this.postPrivate('/v5/user/del-submember', params);
}

/**
* Delete the api key of master account. Use the api key pending to be delete to call the endpoint. Use master user's api key only.
*
Expand Down Expand Up @@ -1799,19 +1820,6 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/user/delete-sub-api', params);
}

/**
* Delete a sub UID. Before deleting the UID, please make sure there are no assets.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
deleteSubMember(
params: DeleteSubMemberParamsV5,
): Promise<APIResponseV3WithTime<{}>> {
return this.postPrivate('/v5/user/del-submember', params);
}

/**
*
****** Affiliate APIs
Expand Down
Loading

0 comments on commit 91eedd0

Please sign in to comment.