From a5aa7f6cf2ed514d89072031c0fb99618892eaad Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Tue, 16 May 2023 14:48:20 +0100 Subject: [PATCH] chore(): update tests for compatibility with new testing sub account --- package-lock.json | 4 +-- src/constants/enum.ts | 2 ++ test/account-asset/private.read.test.ts | 33 +++++++++++++--------- test/account-asset/private.v3.read.test.ts | 25 +++++++++------- test/contract/private.read.test.ts | 2 +- test/copy-trading/private.read.test.ts | 16 +++++++---- test/v5/private.read.test.ts | 5 +++- test/v5/private.write.test.ts | 6 ++-- tsconfig.json | 2 +- tsconfig.test.json | 2 +- 10 files changed, 59 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index feb57b5..8ef531a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.5.1", + "version": "3.5.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.5.1", + "version": "3.5.8", "license": "MIT", "dependencies": { "axios": "^0.21.0", diff --git a/src/constants/enum.ts b/src/constants/enum.ts index 8ade830..5904bd0 100644 --- a/src/constants/enum.ts +++ b/src/constants/enum.ts @@ -58,6 +58,7 @@ export const API_ERROR_CODE = { V5_RISK_ID_NOT_CHANGED: 10001, V5_AUTO_ADD_MARGIN_NOT_CHANGED: 10001, V5_TPSL_ERROR_NO_POSITION: 10001, + V5_RISK_ID_NOT_MODIFIED: 110075, QTY_EXCEEDS_MAX_LIMIT: 130006, ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR: 130010, ORDER_COST_NOT_AVAILABLE: 130021, @@ -67,6 +68,7 @@ export const API_ERROR_CODE = { AUTO_ADD_MARGIN_NOT_MODIFIED: 130060, INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080, SAME_SLTP_MODE_LINEAR: 130150, + NOT_SUPPORTED_FOR_SUBACCOUNTS: 131003, TRANSFER_ID_EXISTS: 131214, RISK_ID_NOT_MODIFIED: 134026, CONTRACT_ORDER_NOT_EXISTS: 140001, diff --git a/test/account-asset/private.read.test.ts b/test/account-asset/private.read.test.ts index 16d97cd..4b01ad7 100644 --- a/test/account-asset/private.read.test.ts +++ b/test/account-asset/private.read.test.ts @@ -1,4 +1,4 @@ -import { AccountAssetClient } from '../../src/'; +import { API_ERROR_CODE, AccountAssetClient } from '../../src/'; import { successResponseObject } from '../response.util'; describe('Private Account Asset REST API GET Endpoints', () => { @@ -18,53 +18,58 @@ describe('Private Account Asset REST API GET Endpoints', () => { it('getInternalTransfers()', async () => { expect(await api.getInternalTransfers()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getSubAccountTransfers()', async () => { - expect(await api.getSubAccountTransfers()).toMatchObject( - successResponseObject() - ); + expect(await api.getSubAccountTransfers()).toMatchObject({ + ...successResponseObject(), + ret_code: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getSubAccounts()', async () => { - expect(await api.getSubAccounts()).toMatchObject(successResponseObject()); + expect(await api.getSubAccounts()).toMatchObject({ + ...successResponseObject(), + ret_code: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getUniversalTransfers()', async () => { expect(await api.getInternalTransfers()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getDepositRecords()', async () => { expect(await api.getDepositRecords()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getWithdrawRecords()', async () => { expect(await api.getWithdrawRecords()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getCoinInformation()', async () => { expect(await api.getCoinInformation()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getAssetInformation()', async () => { expect(await api.getAssetInformation()).toMatchObject( - successResponseObject() + successResponseObject(), ); }); it('getDepositAddress()', async () => { - expect(await api.getDepositAddress('BTC')).toMatchObject( - successResponseObject() - ); + expect(await api.getDepositAddress('BTC')).toMatchObject({ + ...successResponseObject(), + ret_code: API_ERROR_CODE.NOT_SUPPORTED_FOR_SUBACCOUNTS, + }); }); }); diff --git a/test/account-asset/private.v3.read.test.ts b/test/account-asset/private.v3.read.test.ts index d7244a7..11cfb00 100644 --- a/test/account-asset/private.v3.read.test.ts +++ b/test/account-asset/private.v3.read.test.ts @@ -1,4 +1,4 @@ -import { AccountAssetClientV3 } from '../../src'; +import { API_ERROR_CODE, AccountAssetClientV3 } from '../../src'; import { successResponseObjectV3 } from '../response.util'; // Only some minimal coverage for v3 apis, since v5 apis are already available @@ -27,24 +27,29 @@ describe('Private Account Asset V3 REST API Endpoints', () => { expect( await api.getInternalTransfers({ coin: coin, - }) + }), ).toMatchObject(successResponseObjectV3()); }); it('getSubAccountTransfers()', async () => { - expect(await api.getSubAccountTransfers()).toMatchObject( - successResponseObjectV3() - ); + expect(await api.getSubAccountTransfers()).toMatchObject({ + ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getSubAccounts()', async () => { - expect(await api.getSubAccounts()).toMatchObject(successResponseObjectV3()); + expect(await api.getSubAccounts()).toMatchObject({ + ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getUniversalTransfers()', async () => { - expect(await api.getUniversalTransfers({ coin: coin })).toMatchObject( - successResponseObjectV3() - ); + expect(await api.getUniversalTransfers({ coin: coin })).toMatchObject({ + ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getTransferableCoinList()', async () => { @@ -52,7 +57,7 @@ describe('Private Account Asset V3 REST API Endpoints', () => { await api.getTransferableCoinList({ fromAccountType: 'SPOT', toAccountType: 'CONTRACT', - }) + }), ).toMatchObject(successResponseObjectV3()); }); }); diff --git a/test/contract/private.read.test.ts b/test/contract/private.read.test.ts index 7fe9c6a..82e9fe8 100644 --- a/test/contract/private.read.test.ts +++ b/test/contract/private.read.test.ts @@ -76,7 +76,7 @@ describe('Private Contract REST API GET Endpoints', () => { }); // Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before. - it('getOpenInterestLimitInfo()', async () => { + it.skip('getOpenInterestLimitInfo()', async () => { expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({ retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, retMsg: expect.stringMatching(/OI group don't exist/gim), diff --git a/test/copy-trading/private.read.test.ts b/test/copy-trading/private.read.test.ts index fc9a104..d3ca02d 100644 --- a/test/copy-trading/private.read.test.ts +++ b/test/copy-trading/private.read.test.ts @@ -20,22 +20,26 @@ describe('Private Copy Trading REST API GET Endpoints', () => { // (just make sure auth works and endpoint doesn't throw) it('getActiveOrders()', async () => { - expect(await api.getActiveOrders()).toMatchObject( - successResponseObjectV3() - ); + expect(await api.getActiveOrders()).toMatchObject({ + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getPositions()', async () => { - expect(await api.getPositions()).toMatchObject(successResponseObjectV3()); + expect(await api.getPositions()).toMatchObject({ + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('getBalances()', async () => { - expect(await api.getBalances()).toMatchObject(successResponseObjectV3()); + expect(await api.getBalances()).toMatchObject({ + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, + }); }); it('closePosition()', async () => { expect(await api.closePosition('SOLUSDT', '1')).toMatchObject({ - retCode: API_ERROR_CODE.COPY_TRADE_NOT_OPEN_ORDER, + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, }); }); }); diff --git a/test/v5/private.read.test.ts b/test/v5/private.read.test.ts index 181f059..1684741 100644 --- a/test/v5/private.read.test.ts +++ b/test/v5/private.read.test.ts @@ -185,12 +185,14 @@ describe('Private READ V5 REST API Endpoints', () => { it('getSubUID()', async () => { expect(await api.getSubUID()).toMatchObject({ ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, }); }); it('getUniversalTransferRecords()', async () => { expect(await api.getUniversalTransferRecords()).toMatchObject({ ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, }); }); @@ -216,7 +218,8 @@ describe('Private READ V5 REST API Endpoints', () => { }); }); - it('getMasterDepositAddress()', async () => { + // Not available for sub accounts + it.skip('getMasterDepositAddress()', async () => { expect(await api.getMasterDepositAddress(settleCoin)).toMatchObject({ ...successResponseObjectV3(), }); diff --git a/test/v5/private.write.test.ts b/test/v5/private.write.test.ts index fb8d2d2..8e3befd 100644 --- a/test/v5/private.write.test.ts +++ b/test/v5/private.write.test.ts @@ -247,7 +247,7 @@ describe('Private WRITE V5 REST API Endpoints', () => { ).toMatchObject({ // ...successResponseObjectV3(), // retMsg: '', - retCode: API_ERROR_CODE.V5_RISK_ID_NOT_CHANGED, + retCode: API_ERROR_CODE.V5_RISK_ID_NOT_MODIFIED, }); }); @@ -338,6 +338,7 @@ describe('Private WRITE V5 REST API Endpoints', () => { it('enableUniversalTransferForSubUIDs()', async () => { expect(await api.enableUniversalTransferForSubUIDs([])).toMatchObject({ ...successResponseObjectV3(), + retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, }); }); @@ -385,7 +386,8 @@ describe('Private WRITE V5 REST API Endpoints', () => { }); describe('User APIs', () => { - it('createSubMember()', async () => { + // Not available on sub account + it.skip('createSubMember()', async () => { expect( await api.createSubMember({ memberType: 1, diff --git a/tsconfig.json b/tsconfig.json index 7ac09ca..fe0ee8c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ "sourceMap": true, "esModuleInterop": true, "lib": ["es2017", "dom"], - "outDir": "lib" + "outDir": "./lib" }, "include": ["src/**/*"], "exclude": ["node_modules", "**/node_modules/*", "coverage", "doc"] diff --git a/tsconfig.test.json b/tsconfig.test.json index c381f98..8a01ce0 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "distTest", + "outDir": "./distTest", "allowJs": true }, "include": ["test/**/*.ts", "test/**/*.js"]