private unified read tests

This commit is contained in:
tiagosiebler
2022-09-10 19:35:17 +01:00
parent 8e60d5dfdf
commit 8d85bcb182
5 changed files with 71 additions and 53 deletions

View File

@@ -17,6 +17,8 @@ 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,
/** Account not unified margin, update required */
ACCOUNT_NOT_UNIFIED: 10020,
BALANCE_INSUFFICIENT_SPOT_V3: 12131,
ORDER_NOT_FOUND_SPOT_V3: 12213,
ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407,

View File

@@ -205,7 +205,7 @@ export interface UM7DayTradingHistoryRequest {
export interface UMOptionsSettlementHistoryRequest {
category: UMCategory;
symbol: string;
symbol?: string;
expDate?: string;
direction?: UMDirection;
limit?: number;
@@ -214,7 +214,7 @@ export interface UMOptionsSettlementHistoryRequest {
export interface UMPerpSettlementHistoryRequest {
category: UMCategory;
symbol: string;
symbol?: string;
direction?: UMDirection;
limit?: number;
cursor?: string;

View File

@@ -234,7 +234,7 @@ export class UnifiedMarginClient extends BaseRestClient {
* Users can access their position holding information through this interface, such as the number of position holdings and wallet balance.
*/
getPositions(params: UMPositionsRequest): Promise<APIResponseV3<any>> {
return this.postPrivate('/unified/v3/private/position/list', params);
return this.getPrivate('/unified/v3/private/position/list', params);
}
/** Leverage setting. */
@@ -351,7 +351,9 @@ export class UnifiedMarginClient extends BaseRestClient {
}
/** Exchange Coins */
exchangeCoins(params?: UMExchangeCoinsRequest): Promise<APIResponseV3<any>> {
getCoinExchangeHistory(
params?: UMExchangeCoinsRequest
): Promise<APIResponseV3<any>> {
return this.getPrivate(
'/asset/v2/private/exchange/exchange-order-all',
params

View File

@@ -1,5 +1,5 @@
import { USDCPerpetualClient } from '../../../src';
import { successResponseObjectV3 } from '../../response.util';
import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
import { successResponseObjectV3 } from '../response.util';
describe('Private Account Asset REST API Endpoints', () => {
const useLivenet = true;
@@ -11,62 +11,80 @@ describe('Private Account Asset REST API Endpoints', () => {
expect(API_SECRET).toStrictEqual(expect.any(String));
});
const api = new USDCPerpetualClient(API_KEY, API_SECRET, useLivenet);
const api = new UnifiedMarginClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTCPERP';
const category = 'PERPETUAL';
const symbol = 'BTCUSDT';
const category = 'linear';
it('getActiveOrders()', async () => {
expect(await api.getActiveOrders({ category })).toMatchObject(
successResponseObjectV3()
);
expect(await api.getActiveOrders({ category })).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getHistoricOrders()', async () => {
expect(await api.getHistoricOrders({ category })).toMatchObject(
successResponseObjectV3()
);
});
it('getOrderExecutionHistory()', async () => {
expect(await api.getOrderExecutionHistory({ category })).toMatchObject(
successResponseObjectV3()
);
});
it('getTransactionLog()', async () => {
expect(await api.getTransactionLog({ type: 'TRADE' })).toMatchObject(
successResponseObjectV3()
);
});
it('getBalances()', async () => {
expect(await api.getBalances()).toMatchObject(successResponseObjectV3());
});
it('getAssetInfo()', async () => {
expect(await api.getAssetInfo()).toMatchObject(successResponseObjectV3());
});
it('getMarginMode()', async () => {
expect(await api.getMarginMode()).toMatchObject(successResponseObjectV3());
expect(await api.getHistoricOrders({ category })).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getPositions()', async () => {
expect(await api.getPositions({ category })).toMatchObject(
expect(await api.getPositions({ category })).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('get7DayTradingHistory()', async () => {
expect(await api.get7DayTradingHistory({ category, symbol })).toMatchObject(
{
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
}
);
});
it('getOptionsSettlementHistory()', async () => {
expect(await api.getOptionsSettlementHistory({ category })).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getUSDCPerpetualSettlementHistory()', async () => {
expect(
await api.getUSDCPerpetualSettlementHistory({ category })
).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getBalances()', async () => {
expect(await api.getBalances()).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getTransactionLog()', async () => {
expect(
await api.getTransactionLog({ category, currency: 'USDT' })
).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getCoinExchangeHistory()', async () => {
expect(await api.getCoinExchangeHistory()).toMatchObject(
successResponseObjectV3()
);
});
it('getSettlementHistory()', async () => {
expect(await api.getSettlementHistory({ symbol })).toMatchObject(
successResponseObjectV3()
);
it('getBorrowHistory()', async () => {
expect(await api.getBorrowHistory()).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
it('getPredictedFundingRate()', async () => {
expect(await api.getPredictedFundingRate(symbol)).toMatchObject(
successResponseObjectV3()
);
it('getBorrowRate()', async () => {
expect(await api.getBorrowRate()).toMatchObject({
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
});
});
});

View File

@@ -1,8 +1,4 @@
import {
USDCKlineRequest,
UnifiedMarginClient,
UMCandlesRequest,
} from '../../src';
import { UnifiedMarginClient, UMCandlesRequest } from '../../src';
import {
successResponseObject,
successResponseObjectV3,