spot private read tests v3
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { API_ERROR_CODE } from '../src';
|
||||
|
||||
const SUCCESS_MSG_REGEX = /OK|SUCCESS|success|success\.|Request accepted|/gim;
|
||||
|
||||
export function successResponseList(successMsg: string | null = 'OK') {
|
||||
return {
|
||||
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') {
|
||||
return {
|
||||
result: expect.any(Object),
|
||||
@@ -26,9 +37,7 @@ export function successResponseObjectV3() {
|
||||
export function successEmptyResponseObjectV3() {
|
||||
return {
|
||||
retCode: API_ERROR_CODE.SUCCESS,
|
||||
retMsg: expect.stringMatching(
|
||||
/OK|SUCCESS|success|success\.|Request accepted|/gim
|
||||
),
|
||||
retMsg: expect.stringMatching(SUCCESS_MSG_REGEX),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,6 +53,16 @@ export function errorResponseObject(
|
||||
};
|
||||
}
|
||||
|
||||
export function errorResponseObjectV3(
|
||||
result: null | any = null,
|
||||
retCode: number
|
||||
) {
|
||||
return {
|
||||
result,
|
||||
retCode: retCode,
|
||||
};
|
||||
}
|
||||
|
||||
export function notAuthenticatedError() {
|
||||
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