spot private read tests v3
This commit is contained in:
@@ -17,6 +17,9 @@ export const API_ERROR_CODE = {
|
|||||||
/** This could mean bad request, incorrect value types or even incorrect/missing values */
|
/** This could mean bad request, incorrect value types or even incorrect/missing values */
|
||||||
PARAMS_MISSING_OR_WRONG: 10001,
|
PARAMS_MISSING_OR_WRONG: 10001,
|
||||||
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
||||||
|
ORDER_NOT_FOUND_SPOT_V3: 12213,
|
||||||
|
ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407,
|
||||||
|
QUERY_ACCOUNT_INFO_ERROR: 12602,
|
||||||
ORDER_NOT_FOUND_OR_TOO_LATE: 20001,
|
ORDER_NOT_FOUND_OR_TOO_LATE: 20001,
|
||||||
POSITION_STATUS_NOT_NORMAL: 30013,
|
POSITION_STATUS_NOT_NORMAL: 30013,
|
||||||
CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024,
|
CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { API_ERROR_CODE } from '../src';
|
import { API_ERROR_CODE } from '../src';
|
||||||
|
|
||||||
|
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),
|
||||||
@@ -8,6 +10,15 @@ export function successResponseList(successMsg: string | null = 'OK') {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function successResponseListV3(successMsg: string | null = 'OK') {
|
||||||
|
return {
|
||||||
|
result: {
|
||||||
|
list: expect.any(Array),
|
||||||
|
},
|
||||||
|
...successEmptyResponseObjectV3(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function successResponseObject(successMsg: string | null = 'OK') {
|
export function successResponseObject(successMsg: string | null = 'OK') {
|
||||||
return {
|
return {
|
||||||
result: expect.any(Object),
|
result: expect.any(Object),
|
||||||
@@ -26,9 +37,7 @@ export function successResponseObjectV3() {
|
|||||||
export function successEmptyResponseObjectV3() {
|
export function successEmptyResponseObjectV3() {
|
||||||
return {
|
return {
|
||||||
retCode: API_ERROR_CODE.SUCCESS,
|
retCode: API_ERROR_CODE.SUCCESS,
|
||||||
retMsg: expect.stringMatching(
|
retMsg: expect.stringMatching(SUCCESS_MSG_REGEX),
|
||||||
/OK|SUCCESS|success|success\.|Request accepted|/gim
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +53,16 @@ export function errorResponseObject(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function errorResponseObjectV3(
|
||||||
|
result: null | any = null,
|
||||||
|
retCode: number
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
result,
|
||||||
|
retCode: retCode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function notAuthenticatedError() {
|
export function notAuthenticatedError() {
|
||||||
return new Error('Private endpoints require api and private keys set');
|
return new Error('Private endpoints require api and private keys set');
|
||||||
}
|
}
|
||||||
|
|||||||
89
test/spot/private.v3.read.test.ts
Normal file
89
test/spot/private.v3.read.test.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { API_ERROR_CODE, SpotClientV3 } from '../../src';
|
||||||
|
import {
|
||||||
|
errorResponseObject,
|
||||||
|
errorResponseObjectV3,
|
||||||
|
successEmptyResponseObjectV3,
|
||||||
|
successResponseListV3,
|
||||||
|
successResponseObjectV3,
|
||||||
|
} from '../response.util';
|
||||||
|
|
||||||
|
describe('Private Spot REST API Endpoints', () => {
|
||||||
|
const useLivenet = true;
|
||||||
|
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 SpotClientV3(API_KEY, API_SECRET, useLivenet);
|
||||||
|
|
||||||
|
const symbol = 'BTCUSDT';
|
||||||
|
const interval = '15m';
|
||||||
|
const ltCode = 'BTC3S';
|
||||||
|
|
||||||
|
it('getOrder()', async () => {
|
||||||
|
// No auth error == test pass
|
||||||
|
expect(await api.getOrder({ orderId: '123123' })).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_SPOT_V3,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getOpenOrders()', async () => {
|
||||||
|
expect(await api.getOpenOrders()).toMatchObject(successResponseListV3());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getPastOrders()', async () => {
|
||||||
|
expect(await api.getPastOrders()).toMatchObject(successResponseListV3());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getMyTrades()', async () => {
|
||||||
|
expect(await api.getMyTrades()).toMatchObject(successResponseListV3());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getBalances()', async () => {
|
||||||
|
expect(await api.getBalances()).toMatchObject({
|
||||||
|
result: {
|
||||||
|
balances: expect.any(Array),
|
||||||
|
},
|
||||||
|
...successEmptyResponseObjectV3(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getLeveragedTokenMarketInfo()', async () => {
|
||||||
|
expect(await api.getLeveragedTokenMarketInfo(ltCode)).toMatchObject(
|
||||||
|
successResponseObjectV3()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getLeveragedTokenPRHistory()', async () => {
|
||||||
|
expect(await api.getLeveragedTokenPRHistory()).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_LEVERAGED_TOKEN,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCrossMarginBorrowingInfo()', async () => {
|
||||||
|
expect(await api.getCrossMarginBorrowingInfo()).toMatchObject(
|
||||||
|
successResponseObjectV3()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCrossMarginAccountInfo()', async () => {
|
||||||
|
expect(await api.getCrossMarginAccountInfo()).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.QUERY_ACCOUNT_INFO_ERROR,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCrossMarginInterestQuota()', async () => {
|
||||||
|
expect(await api.getCrossMarginInterestQuota('USDT')).toMatchObject(
|
||||||
|
successResponseObjectV3()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getCrossMarginRepaymentHistory()', async () => {
|
||||||
|
expect(await api.getCrossMarginRepaymentHistory()).toMatchObject(
|
||||||
|
successResponseObjectV3()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user