From 66dcd09f18f59e2bc3b7fbf32d2733f95cc570a6 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 10 Sep 2022 12:57:00 +0100 Subject: [PATCH] add test coverage for all spot v3 endpoints --- src/constants/enum.ts | 4 +++ test/spot/private.v1.read.test.ts | 3 -- test/spot/private.v3.write.test.ts | 47 +++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/constants/enum.ts b/src/constants/enum.ts index 43c357a..cf7fd6f 100644 --- a/src/constants/enum.ts +++ b/src/constants/enum.ts @@ -17,9 +17,13 @@ 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, + BALANCE_INSUFFICIENT_SPOT_V3: 12131, ORDER_NOT_FOUND_SPOT_V3: 12213, ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407, + EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN: 12409, QUERY_ACCOUNT_INFO_ERROR: 12602, + CROSS_MARGIN_USER_NOT_FOUND: 12607, + CROSS_MARGIN_REPAYMENT_NOT_REQUIRED: 12616, ORDER_NOT_FOUND_OR_TOO_LATE: 20001, POSITION_STATUS_NOT_NORMAL: 30013, CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024, diff --git a/test/spot/private.v1.read.test.ts b/test/spot/private.v1.read.test.ts index 6f61734..bbc6182 100644 --- a/test/spot/private.v1.read.test.ts +++ b/test/spot/private.v1.read.test.ts @@ -18,9 +18,6 @@ describe('Private Spot REST API Endpoints', () => { const api = new SpotClient(API_KEY, API_SECRET, useLivenet); - const symbol = 'BTCUSDT'; - const interval = '15m'; - it('getOrder()', async () => { // No auth error == test pass expect(await api.getOrder({ orderId: '123123' })).toMatchObject( diff --git a/test/spot/private.v3.write.test.ts b/test/spot/private.v3.write.test.ts index 4f3ef5e..b226292 100644 --- a/test/spot/private.v3.write.test.ts +++ b/test/spot/private.v3.write.test.ts @@ -1,5 +1,8 @@ -import { API_ERROR_CODE, SpotClient } from '../../src'; -import { successResponseObject } from '../response.util'; +import { API_ERROR_CODE, SpotClientV3 } from '../../src'; +import { + successResponseObject, + successResponseObjectV3, +} from '../response.util'; describe('Private Inverse-Futures REST API POST Endpoints', () => { const useLivenet = true; @@ -11,10 +14,10 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new SpotClient(API_KEY, API_SECRET, useLivenet); + const api = new SpotClientV3(API_KEY, API_SECRET, useLivenet); - // Warning: if some of these start to fail with 10001 params error, it's probably that this future expired and a newer one exists with a different symbol! const symbol = 'BTCUSDT'; + const ltCode = 'BTC3S'; // These tests are primarily check auth is working by expecting balance or order not found style errors @@ -23,12 +26,11 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { await api.submitOrder({ side: 'Buy', symbol, - qty: 10000, - type: 'MARKET', + orderQty: '10000', + orderType: 'MARKET', }) ).toMatchObject({ - ret_code: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT, - ret_msg: 'Balance insufficient ', + retCode: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT_V3, }); }); @@ -38,8 +40,7 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { orderId: '1231231', }) ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE_SPOT, - ret_msg: 'Order does not exist.', + retCode: API_ERROR_CODE.ORDER_NOT_FOUND_SPOT_V3, }); }); @@ -49,6 +50,30 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { symbol, orderTypes: ['LIMIT', 'LIMIT_MAKER'], }) - ).toMatchObject(successResponseObject()); + ).toMatchObject(successResponseObjectV3()); + }); + + it('purchaseLeveragedToken()', async () => { + expect(await api.purchaseLeveragedToken(ltCode, '1')).toMatchObject({ + retCode: API_ERROR_CODE.EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN, + }); + }); + + it('redeemLeveragedToken()', async () => { + expect(await api.redeemLeveragedToken(ltCode, '1')).toMatchObject({ + retCode: 12426, // unknown error code, not listed in docs yet + }); + }); + + it('borrowCrossMarginLoan()', async () => { + expect(await api.borrowCrossMarginLoan('USDT', '1')).toMatchObject({ + retCode: API_ERROR_CODE.CROSS_MARGIN_USER_NOT_FOUND, + }); + }); + + it('repayCrossMarginLoan()', async () => { + expect(await api.repayCrossMarginLoan('USDT', '1')).toMatchObject({ + retCode: API_ERROR_CODE.CROSS_MARGIN_REPAYMENT_NOT_REQUIRED, + }); }); });