add test coverage for all spot v3 endpoints

This commit is contained in:
tiagosiebler
2022-09-10 12:57:00 +01:00
parent 1c9c6aa1e2
commit 66dcd09f18
3 changed files with 40 additions and 14 deletions

View File

@@ -17,9 +17,13 @@ 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,
BALANCE_INSUFFICIENT_SPOT_V3: 12131,
ORDER_NOT_FOUND_SPOT_V3: 12213, ORDER_NOT_FOUND_SPOT_V3: 12213,
ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407, ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407,
EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN: 12409,
QUERY_ACCOUNT_INFO_ERROR: 12602, QUERY_ACCOUNT_INFO_ERROR: 12602,
CROSS_MARGIN_USER_NOT_FOUND: 12607,
CROSS_MARGIN_REPAYMENT_NOT_REQUIRED: 12616,
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,

View File

@@ -18,9 +18,6 @@ describe('Private Spot REST API Endpoints', () => {
const api = new SpotClient(API_KEY, API_SECRET, useLivenet); const api = new SpotClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTCUSDT';
const interval = '15m';
it('getOrder()', async () => { it('getOrder()', async () => {
// No auth error == test pass // No auth error == test pass
expect(await api.getOrder({ orderId: '123123' })).toMatchObject( expect(await api.getOrder({ orderId: '123123' })).toMatchObject(

View File

@@ -1,5 +1,8 @@
import { API_ERROR_CODE, SpotClient } from '../../src'; import { API_ERROR_CODE, SpotClientV3 } from '../../src';
import { successResponseObject } from '../response.util'; import {
successResponseObject,
successResponseObjectV3,
} from '../response.util';
describe('Private Inverse-Futures REST API POST Endpoints', () => { describe('Private Inverse-Futures REST API POST Endpoints', () => {
const useLivenet = true; const useLivenet = true;
@@ -11,10 +14,10 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
expect(API_SECRET).toStrictEqual(expect.any(String)); 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 symbol = 'BTCUSDT';
const ltCode = 'BTC3S';
// These tests are primarily check auth is working by expecting balance or order not found style errors // 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({ await api.submitOrder({
side: 'Buy', side: 'Buy',
symbol, symbol,
qty: 10000, orderQty: '10000',
type: 'MARKET', orderType: 'MARKET',
}) })
).toMatchObject({ ).toMatchObject({
ret_code: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT, retCode: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT_V3,
ret_msg: 'Balance insufficient ',
}); });
}); });
@@ -38,8 +40,7 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
orderId: '1231231', orderId: '1231231',
}) })
).toMatchObject({ ).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE_SPOT, retCode: API_ERROR_CODE.ORDER_NOT_FOUND_SPOT_V3,
ret_msg: 'Order does not exist.',
}); });
}); });
@@ -49,6 +50,30 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
symbol, symbol,
orderTypes: ['LIMIT', 'LIMIT_MAKER'], 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,
});
}); });
}); });