add tests for private query endpoints

This commit is contained in:
tiagosiebler
2022-05-05 23:53:28 +01:00
parent 4ba36374cc
commit 749efad303
4 changed files with 108 additions and 68 deletions

View File

@@ -162,7 +162,7 @@ export class InverseClient extends BaseRestClient {
return this.requestWrapper.get('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params: WithdrawRecordsReq): GenericAPIResponse {
getWithdrawRecords(params?: WithdrawRecordsReq): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/withdraw/list', params);
}
@@ -278,6 +278,7 @@ export class InverseClient extends BaseRestClient {
return this.requestWrapper.post('v2/private/stop-order/create', params);
}
/** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
getConditionalOrder(params: {
symbol: string;
stop_order_status?: string;
@@ -323,24 +324,10 @@ export class InverseClient extends BaseRestClient {
* Position
*/
/**
* @deprecated use getPosition() instead
*/
getUserLeverage(): GenericAPIResponse {
return this.requestWrapper.get('user/leverage');
}
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
return this.requestWrapper.get('v2/private/position/list', params);
}
/**
* @deprecated use getPosition() instead
*/
getPositions(): GenericAPIResponse {
return this.requestWrapper.get('position/list');
}
changePositionMargin(params: {
symbol: string;
margin: string;
@@ -371,13 +358,6 @@ export class InverseClient extends BaseRestClient {
);
}
/**
* @deprecated use setUserLeverage() instead
*/
changeUserLeverage(params: any): GenericAPIResponse {
return this.setUserLeverage(params);
}
getTradeRecords(params: {
order_id?: string;
symbol: string;
@@ -428,7 +408,7 @@ export class InverseClient extends BaseRestClient {
*/
getRiskLimitList(): GenericAPIResponse {
return this.requestWrapper.get('open-api/wallet/risk-limit/list');
return this.get('open-api/wallet/risk-limit/list');
}
setRiskLimit(params: {
@@ -464,9 +444,4 @@ export class InverseClient extends BaseRestClient {
getLcpInfo(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/lcp', params);
}
//API Key Info
getAPIKeyInfo(): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/api-key');
}
}

View File

@@ -0,0 +1,101 @@
import { InverseClient } from '../../src/inverse-client';
import { successResponseList, successResponseObject } from '../response.util';
describe('Private Inverse 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 InverseClient(API_KEY, API_SECRET, useLivenet, {
disable_time_sync: true,
});
const symbol = 'BTCUSD';
describe('Inverse only private GET endpoints', () => {
it('getApiKeyInfo()', async () => {
expect(await api.getApiKeyInfo()).toMatchObject(successResponseObject());
});
it('getWalletBalance()', async () => {
expect(await api.getWalletBalance()).toMatchObject(
successResponseObject()
);
});
it('getWalletFundRecords()', async () => {
expect(await api.getWalletFundRecords()).toMatchObject(
successResponseObject()
);
});
it('getWithdrawRecords()', async () => {
expect(await api.getWithdrawRecords()).toMatchObject(
successResponseObject()
);
});
it('getAssetExchangeRecords()', async () => {
expect(await api.getAssetExchangeRecords()).toMatchObject(
successResponseList()
);
});
it('getActiveOrderList()', async () => {
expect(await api.getActiveOrderList({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('queryActiveOrder()', async () => {
expect(await api.queryActiveOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getConditionalOrder()', async () => {
expect(await api.getConditionalOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('queryConditionalOrder()', async () => {
expect(await api.queryConditionalOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getPosition()', async () => {
expect(await api.getPosition()).toMatchObject(successResponseObject());
});
it('getTradeRecords()', async () => {
expect(await api.getTradeRecords({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getClosedPnl()', async () => {
expect(await api.getClosedPnl({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getMyLastFundingFee()', async () => {
expect(await api.getMyLastFundingFee({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getLcpInfo()', async () => {
expect(await api.getLcpInfo({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
});
});

View File

@@ -1,40 +0,0 @@
import { InverseClient } from '../../src/inverse-client';
import {
notAuthenticatedError,
successResponseList,
successResponseObject,
} from '../response.util';
describe.skip('Private Inverse 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 InverseClient(API_KEY, API_SECRET, useLivenet, {
disable_time_sync: true,
});
const symbol = 'BTCUSD';
const interval = '15';
const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60;
const from = Number(timestampOneHourAgo.toFixed(0));
describe('Inverse only endpoints', () => {
it('getOrderBook()', async () => {
expect(await api.getOrderBook({ symbol })).toMatchObject(
successResponseList()
);
});
it('getKline()', async () => {
expect(await api.getKline({ symbol, interval, from })).toMatchObject(
successResponseList()
);
});
});
});

View File

@@ -70,6 +70,10 @@ describe('Public Inverse REST API Endpoints', () => {
).toMatchObject(successResponseList());
});
it('getRiskLimitList()', async () => {
expect(await api.getRiskLimitList()).toMatchObject(successResponseList());
});
it('getLastFundingRate()', async () => {
expect(await api.getLastFundingRate({ symbol })).toMatchObject(
successResponseObject()