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 */ /** 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,
/** Account not unified margin, update required */
ACCOUNT_NOT_UNIFIED: 10020,
BALANCE_INSUFFICIENT_SPOT_V3: 12131, 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,

View File

@@ -205,7 +205,7 @@ export interface UM7DayTradingHistoryRequest {
export interface UMOptionsSettlementHistoryRequest { export interface UMOptionsSettlementHistoryRequest {
category: UMCategory; category: UMCategory;
symbol: string; symbol?: string;
expDate?: string; expDate?: string;
direction?: UMDirection; direction?: UMDirection;
limit?: number; limit?: number;
@@ -214,7 +214,7 @@ export interface UMOptionsSettlementHistoryRequest {
export interface UMPerpSettlementHistoryRequest { export interface UMPerpSettlementHistoryRequest {
category: UMCategory; category: UMCategory;
symbol: string; symbol?: string;
direction?: UMDirection; direction?: UMDirection;
limit?: number; limit?: number;
cursor?: string; 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. * 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>> { 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. */ /** Leverage setting. */
@@ -351,7 +351,9 @@ export class UnifiedMarginClient extends BaseRestClient {
} }
/** Exchange Coins */ /** Exchange Coins */
exchangeCoins(params?: UMExchangeCoinsRequest): Promise<APIResponseV3<any>> { getCoinExchangeHistory(
params?: UMExchangeCoinsRequest
): Promise<APIResponseV3<any>> {
return this.getPrivate( return this.getPrivate(
'/asset/v2/private/exchange/exchange-order-all', '/asset/v2/private/exchange/exchange-order-all',
params params

View File

@@ -1,5 +1,5 @@
import { USDCPerpetualClient } from '../../../src'; import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
import { successResponseObjectV3 } from '../../response.util'; import { successResponseObjectV3 } from '../response.util';
describe('Private Account Asset REST API Endpoints', () => { describe('Private Account Asset REST API Endpoints', () => {
const useLivenet = true; const useLivenet = true;
@@ -11,62 +11,80 @@ describe('Private Account Asset REST API Endpoints', () => {
expect(API_SECRET).toStrictEqual(expect.any(String)); 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 symbol = 'BTCUSDT';
const category = 'PERPETUAL'; const category = 'linear';
it('getActiveOrders()', async () => { it('getActiveOrders()', async () => {
expect(await api.getActiveOrders({ category })).toMatchObject( expect(await api.getActiveOrders({ category })).toMatchObject({
successResponseObjectV3() retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
); });
}); });
it('getHistoricOrders()', async () => { it('getHistoricOrders()', async () => {
expect(await api.getHistoricOrders({ category })).toMatchObject( expect(await api.getHistoricOrders({ category })).toMatchObject({
successResponseObjectV3() retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
); });
});
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());
}); });
it('getPositions()', async () => { 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() successResponseObjectV3()
); );
}); });
it('getSettlementHistory()', async () => { it('getBorrowHistory()', async () => {
expect(await api.getSettlementHistory({ symbol })).toMatchObject( expect(await api.getBorrowHistory()).toMatchObject({
successResponseObjectV3() retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
); });
}); });
it('getPredictedFundingRate()', async () => { it('getBorrowRate()', async () => {
expect(await api.getPredictedFundingRate(symbol)).toMatchObject( expect(await api.getBorrowRate()).toMatchObject({
successResponseObjectV3() retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
); });
}); });
}); });

View File

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