From 8d85bcb1826999edc4df0e3021ad3b04d7c86c50 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 10 Sep 2022 19:35:17 +0100 Subject: [PATCH] private unified read tests --- src/constants/enum.ts | 2 + src/types/request/unified-margin.ts | 4 +- src/unified-margin-client.ts | 6 +- test/unified-margin/private.read.test.ts | 106 +++++++++++++---------- test/unified-margin/public.read.test.ts | 6 +- 5 files changed, 71 insertions(+), 53 deletions(-) diff --git a/src/constants/enum.ts b/src/constants/enum.ts index cf7fd6f..18de262 100644 --- a/src/constants/enum.ts +++ b/src/constants/enum.ts @@ -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, diff --git a/src/types/request/unified-margin.ts b/src/types/request/unified-margin.ts index 29c8e74..85eb3b3 100644 --- a/src/types/request/unified-margin.ts +++ b/src/types/request/unified-margin.ts @@ -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; diff --git a/src/unified-margin-client.ts b/src/unified-margin-client.ts index 3491833..c52be5b 100644 --- a/src/unified-margin-client.ts +++ b/src/unified-margin-client.ts @@ -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> { - 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> { + getCoinExchangeHistory( + params?: UMExchangeCoinsRequest + ): Promise> { return this.getPrivate( '/asset/v2/private/exchange/exchange-order-all', params diff --git a/test/unified-margin/private.read.test.ts b/test/unified-margin/private.read.test.ts index ae86d70..3620ed6 100644 --- a/test/unified-margin/private.read.test.ts +++ b/test/unified-margin/private.read.test.ts @@ -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, + }); }); }); diff --git a/test/unified-margin/public.read.test.ts b/test/unified-margin/public.read.test.ts index 26a6ab3..a1ee661 100644 --- a/test/unified-margin/public.read.test.ts +++ b/test/unified-margin/public.read.test.ts @@ -1,8 +1,4 @@ -import { - USDCKlineRequest, - UnifiedMarginClient, - UMCandlesRequest, -} from '../../src'; +import { UnifiedMarginClient, UMCandlesRequest } from '../../src'; import { successResponseObject, successResponseObjectV3,