Merge pull request #262 from tiagosiebler/testsfornewacc

chore(): update tests for compatibility with new testing sub account
This commit is contained in:
Tiago
2023-05-16 17:17:37 +01:00
committed by GitHub
10 changed files with 59 additions and 38 deletions

4
package-lock.json generated
View File

@@ -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",

View File

@@ -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,

View File

@@ -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,
});
});
});

View File

@@ -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());
});
});

View File

@@ -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),

View File

@@ -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,
});
});
});

View File

@@ -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(),
});

View File

@@ -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,

View File

@@ -14,7 +14,7 @@
"sourceMap": true,
"esModuleInterop": true,
"lib": ["es2017", "dom"],
"outDir": "lib"
"outDir": "./lib"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/node_modules/*", "coverage", "doc"]

View File

@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "distTest",
"outDir": "./distTest",
"allowJs": true
},
"include": ["test/**/*.ts", "test/**/*.js"]