misc fixes for v5 rest client. Add e2e private fetch tests for v5 rest client.
This commit is contained in:
@@ -63,6 +63,7 @@ export const API_ERROR_CODE = {
|
|||||||
CONTRACT_MARGIN_MODE_NOT_MODIFIED: 140026,
|
CONTRACT_MARGIN_MODE_NOT_MODIFIED: 140026,
|
||||||
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS: 140031,
|
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS: 140031,
|
||||||
CONTRACT_SET_LEVERAGE_NOT_MODIFIED: 140043,
|
CONTRACT_SET_LEVERAGE_NOT_MODIFIED: 140043,
|
||||||
|
SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND: 175007,
|
||||||
/** E.g. USDC Options trading, trying to access a symbol that is no longer active */
|
/** E.g. USDC Options trading, trying to access a symbol that is no longer active */
|
||||||
CONTRACT_NAME_NOT_EXIST: 3100111,
|
CONTRACT_NAME_NOT_EXIST: 3100111,
|
||||||
ORDER_NOT_EXIST: 3100136,
|
ORDER_NOT_EXIST: 3100136,
|
||||||
|
|||||||
@@ -601,7 +601,7 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
* Unified account covers: Spot / Linear contract / Options
|
* Unified account covers: Spot / Linear contract / Options
|
||||||
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
|
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
|
||||||
*/
|
*/
|
||||||
getExecutionListV5(
|
getExecutionList(
|
||||||
params: GetExecutionListParamsV5
|
params: GetExecutionListParamsV5
|
||||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<ExecutionV5[]>>> {
|
): Promise<APIResponseV3WithTime<CategoryCursorListV5<ExecutionV5[]>>> {
|
||||||
return this.getPrivate('/v5/execution/list', params);
|
return this.getPrivate('/v5/execution/list', params);
|
||||||
@@ -764,7 +764,7 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
nextPageCursor?: string;
|
nextPageCursor?: string;
|
||||||
}>
|
}>
|
||||||
> {
|
> {
|
||||||
return this.get('/v5/asset/exchange/order-record', params);
|
return this.getPrivate('/v5/asset/exchange/order-record', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -870,7 +870,7 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
* Query the internal transfer records between different account types under the same UID.
|
* Query the internal transfer records between different account types under the same UID.
|
||||||
*/
|
*/
|
||||||
getInternalTransferRecords(
|
getInternalTransferRecords(
|
||||||
params: GetInternalTransferParamsV5
|
params?: GetInternalTransferParamsV5
|
||||||
): Promise<APIResponseV3WithTime<CursorListV5<InternalTransferRecordV5[]>>> {
|
): Promise<APIResponseV3WithTime<CursorListV5<InternalTransferRecordV5[]>>> {
|
||||||
return this.getPrivate(
|
return this.getPrivate(
|
||||||
'/v5/asset/transfer/query-inter-transfer-list',
|
'/v5/asset/transfer/query-inter-transfer-list',
|
||||||
@@ -1014,7 +1014,10 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
getCoinInfo(
|
getCoinInfo(
|
||||||
coin?: string
|
coin?: string
|
||||||
): Promise<APIResponseV3WithTime<{ rows: CoinInfoV5[] }>> {
|
): Promise<APIResponseV3WithTime<{ rows: CoinInfoV5[] }>> {
|
||||||
return this.get('/v5/asset/coin/query-info', coin ? { coin } : undefined);
|
return this.getPrivate(
|
||||||
|
'/v5/asset/coin/query-info',
|
||||||
|
coin ? { coin } : undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { API_ERROR_CODE } from '../src';
|
import { API_ERROR_CODE } from '../src';
|
||||||
|
|
||||||
const SUCCESS_MSG_REGEX = /OK|SUCCESS|success|success\.|Request accepted|/gim;
|
export const SUCCESS_MSG_REGEX =
|
||||||
|
/OK|SUCCESS|success|success\.|Request accepted|/gim;
|
||||||
|
|
||||||
export function successResponseList(successMsg: string | null = 'OK') {
|
export function successResponseList(successMsg: string | null = 'OK') {
|
||||||
return {
|
return {
|
||||||
result: expect.any(Array),
|
result: expect.any(Array),
|
||||||
ret_code: API_ERROR_CODE.SUCCESS,
|
|
||||||
ret_msg: successMsg,
|
ret_msg: successMsg,
|
||||||
|
ret_code: API_ERROR_CODE.SUCCESS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +24,8 @@ export function successResponseListV3() {
|
|||||||
export function successResponseObject() {
|
export function successResponseObject() {
|
||||||
return {
|
return {
|
||||||
result: expect.any(Object),
|
result: expect.any(Object),
|
||||||
ret_code: API_ERROR_CODE.SUCCESS,
|
|
||||||
ret_msg: expect.stringMatching(SUCCESS_MSG_REGEX),
|
ret_msg: expect.stringMatching(SUCCESS_MSG_REGEX),
|
||||||
|
ret_code: API_ERROR_CODE.SUCCESS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
267
test/rest-client-v5/private.read.test.ts
Normal file
267
test/rest-client-v5/private.read.test.ts
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
import { API_ERROR_CODE, RestClientV5 } from '../../src';
|
||||||
|
import { SUCCESS_MSG_REGEX, successResponseObjectV3 } from '../response.util';
|
||||||
|
|
||||||
|
describe('Private V5 REST API Endpoints', () => {
|
||||||
|
const API_KEY = process.env.API_KEY_COM;
|
||||||
|
const API_SECRET = process.env.API_SECRET_COM;
|
||||||
|
|
||||||
|
it('should have api credentials to test with', () => {
|
||||||
|
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||||
|
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||||
|
});
|
||||||
|
|
||||||
|
const api = new RestClientV5({
|
||||||
|
key: API_KEY,
|
||||||
|
secret: API_SECRET,
|
||||||
|
testnet: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const settleCoin = 'USDT';
|
||||||
|
const linearSymbol = 'BTCUSDT';
|
||||||
|
|
||||||
|
describe('misc endpoints', () => {
|
||||||
|
it('fetchServerTime()', async () => {
|
||||||
|
expect(await api.fetchServerTime()).toEqual(expect.any(Number));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Trade APIs', () => {
|
||||||
|
it('getActiveOrders()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getActiveOrders({ category: 'linear', settleCoin })
|
||||||
|
).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getHistoricOrders()', async () => {
|
||||||
|
expect(await api.getHistoricOrders({ category: 'linear' })).toMatchObject(
|
||||||
|
{ ...successResponseObjectV3() }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getSpotBorrowCheck()', async () => {
|
||||||
|
expect(await api.getSpotBorrowCheck(linearSymbol, 'Buy')).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Position APIs', () => {
|
||||||
|
it('getPositionInfo()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getPositionInfo({ category: 'linear', settleCoin })
|
||||||
|
).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getExecutionList()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getExecutionList({ category: 'linear', symbol: linearSymbol })
|
||||||
|
).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getClosedPnL()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getClosedPnL({ category: 'linear', symbol: linearSymbol })
|
||||||
|
).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Account APIs', () => {
|
||||||
|
it('getWalletBalance()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getWalletBalance({ accountType: 'CONTRACT' })
|
||||||
|
).toMatchObject({ ...successResponseObjectV3() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getBorrowHistory()', async () => {
|
||||||
|
expect(await api.getBorrowHistory()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCollateralInfo()', async () => {
|
||||||
|
expect(await api.getCollateralInfo()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Not available on this test account
|
||||||
|
it.skip('getCoinGreeks()', async () => {
|
||||||
|
expect(await api.getCoinGreeks()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
retMsg: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getFeeRate()', async () => {
|
||||||
|
expect(await api.getFeeRate()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fails on this test account, since it's not upgraded
|
||||||
|
it.skip('getAccountInfo()', async () => {
|
||||||
|
expect(await api.getAccountInfo()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
retMsg: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransactionLog()', async () => {
|
||||||
|
expect(await api.getTransactionLog()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Not available on this test account
|
||||||
|
it.skip('getMMPState()', async () => {
|
||||||
|
expect(await api.getMMPState(settleCoin)).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
retMsg: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Asset APIs', () => {
|
||||||
|
it('getCoinExchangeRecords()', async () => {
|
||||||
|
expect(await api.getCoinExchangeRecords()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getDeliveryRecord()', async () => {
|
||||||
|
expect(await api.getDeliveryRecord({ category: 'option' })).toMatchObject(
|
||||||
|
{ ...successResponseObjectV3() }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getSettlementRecords()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getSettlementRecords({ category: 'linear' })
|
||||||
|
).toMatchObject({ ...successResponseObjectV3() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getAssetInfo()', async () => {
|
||||||
|
expect(await api.getAssetInfo({ accountType: 'SPOT' })).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getAllCoinsBalance()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getAllCoinsBalance({ accountType: 'SPOT' })
|
||||||
|
).toMatchObject({ ...successResponseObjectV3() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCoinBalance()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getCoinBalance({ accountType: 'SPOT', coin: settleCoin })
|
||||||
|
).toMatchObject({ ...successResponseObjectV3() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransferableCoinList()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getTransferableCoinList('SPOT', 'CONTRACT')
|
||||||
|
).toMatchObject({ ...successResponseObjectV3() });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getInternalTransferRecords()', async () => {
|
||||||
|
expect(await api.getInternalTransferRecords()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getSubUID()', async () => {
|
||||||
|
expect(await api.getSubUID()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getUniversalTransferRecords()', async () => {
|
||||||
|
expect(await api.getUniversalTransferRecords()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getAllowedDepositCoinInfo()', async () => {
|
||||||
|
expect(await api.getAllowedDepositCoinInfo()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getDepositRecords()', async () => {
|
||||||
|
expect(await api.getDepositRecords()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getSubAccountDepositRecords()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getSubAccountDepositRecords({ subMemberId: 'fakeid' })
|
||||||
|
).toMatchObject({
|
||||||
|
// ...successResponseObjectV3(),
|
||||||
|
// Expected, since sub account ID is fake
|
||||||
|
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getMasterDepositAddress()', async () => {
|
||||||
|
expect(await api.getMasterDepositAddress(settleCoin)).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('querySubMemberAddress()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.querySubMemberAddress(settleCoin, 'TRC20', 'fakeid')
|
||||||
|
).toMatchObject({
|
||||||
|
// ...successResponseObjectV3(),
|
||||||
|
// Expected, since sub account ID is fake
|
||||||
|
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCoinInfo()', async () => {
|
||||||
|
expect(await api.getCoinInfo()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getWithdrawalRecords()', async () => {
|
||||||
|
expect(await api.getWithdrawalRecords()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('User APIs', () => {
|
||||||
|
it('getSubUIDList()', async () => {
|
||||||
|
expect(await api.getSubUIDList()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getQueryApiKey()', async () => {
|
||||||
|
expect(await api.getQueryApiKey()).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Spot Leverage Token APIs', () => {
|
||||||
|
it('getSpotLeveragedTokenOrderHistory()', async () => {
|
||||||
|
expect(await api.getSpotLeveragedTokenOrderHistory()).toMatchObject({
|
||||||
|
// ...successResponseObjectV3(),
|
||||||
|
// retMsg: '',
|
||||||
|
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user