diff --git a/src/constants/enum.ts b/src/constants/enum.ts index 3ef8f6b..43c357a 100644 --- a/src/constants/enum.ts +++ b/src/constants/enum.ts @@ -17,6 +17,9 @@ export const API_ERROR_CODE = { /** This could mean bad request, incorrect value types or even incorrect/missing values */ PARAMS_MISSING_OR_WRONG: 10001, 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, POSITION_STATUS_NOT_NORMAL: 30013, CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024, diff --git a/test/response.util.ts b/test/response.util.ts index b9bc320..760e352 100644 --- a/test/response.util.ts +++ b/test/response.util.ts @@ -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'); } diff --git a/test/spot/private.v3.read.test.ts b/test/spot/private.v3.read.test.ts new file mode 100644 index 0000000..003b2dc --- /dev/null +++ b/test/spot/private.v3.read.test.ts @@ -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() + ); + }); +});