diff --git a/test/account-asset/private.v3.read.test.ts b/test/account-asset/private.v3.read.test.ts deleted file mode 100644 index 895b1fb..0000000 --- a/test/account-asset/private.v3.read.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { API_ERROR_CODE, AccountAssetClientV3 } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObjectV3 } from '../response.util'; - -// Only some minimal coverage for v3 apis, since v5 apis are already available -describe('Private Account Asset V3 REST API Endpoints', () => { - 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 AccountAssetClientV3( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const coin = 'USDT'; - - it('fetchServerTime()', async () => { - expect(await api.fetchServerTime()).toEqual(expect.any(Number)); - }); - - it('getInternalTransfers()', async () => { - expect( - await api.getInternalTransfers({ - coin: coin, - }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('getSubAccountTransfers()', async () => { - expect(await api.getSubAccountTransfers()).toMatchObject({ - ...successResponseObjectV3(), - retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, - }); - }); - - it('getSubAccounts()', async () => { - expect(await api.getSubAccounts()).toMatchObject({ - ...successResponseObjectV3(), - retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, - }); - }); - - it.skip('getUniversalTransfers()', async () => { - expect(await api.getUniversalTransfers({ coin: coin })).toMatchObject({ - ...successResponseObjectV3(), - retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, - }); - }); - - it('getTransferableCoinList()', async () => { - expect( - await api.getTransferableCoinList({ - fromAccountType: 'SPOT', - toAccountType: 'CONTRACT', - }), - ).toMatchObject(successResponseObjectV3()); - }); -}); diff --git a/test/contract/private.read.test.ts b/test/contract/private.read.test.ts deleted file mode 100644 index 6cf7a62..0000000 --- a/test/contract/private.read.test.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* eslint-disable max-len */ -import { API_ERROR_CODE, ContractClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObjectV3 } from '../response.util'; - -describe('Private Contract REST API GET Endpoints', () => { - 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 ContractClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - it('getHistoricOrders()', async () => { - expect(await api.getHistoricOrders({ symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getHistoricOrders() with hardcoded cursor', async () => { - const cursor = - 'eyJza2lwX2xvY2FsX3N5bWJvbCI6ZmFsc2UsInBhZ2VfdG9rZW4iOiJleUpOSWpwN0luQnJJanA3SWtJaU9pSktSRmt6VG1wcmVFMXFaM2xNVkUwMFQwUlpkRTVFUlRKTmFURm9UakpPYWt4WFVUSk9lbFY1VDBSU2FrMVhXVEJOZHowOUluMHNJbDl6YTE4aU9uc2lRaUk2SWtaNFltMWFZMDV6TUROek1rNTZXVFZOVkVrMFRXa3dlazlFWnpKTVZGRjRUbXBKZEZsVVpHcFplVEZyVG1wak1VMXFaekJaZWtadFRrUk5QU0o5TENKZmRYTmZJanA3SWtJaU9pSkJLMmt2WkZGRlJ5SjlmWDA9In0='; - - expect( - await api.getHistoricOrders({ symbol, cursor, limit: 1 }), - ).toMatchObject({ - // retCode: API_ERROR_CODE.DB_ERROR_WRONG_CURSOR, - ...successResponseObjectV3(), - retMsg: 'OK', - }); - }); - - it('getHistoricOrders() with dynamic cursor', async () => { - const orders = await api.getHistoricOrders({ symbol, limit: 1 }); - - const cursor = orders.result.nextPageCursor; - - expect( - await api.getHistoricOrders({ symbol, cursor, limit: 1 }), - ).toMatchObject({ - ...successResponseObjectV3(), - retMsg: 'OK', - }); - }); - - it('getActiveOrders()', async () => { - expect(await api.getActiveOrders({ symbol })).toMatchObject({ - ...successResponseObjectV3(), - retMsg: 'OK', - }); - }); - - it('getPositions()', async () => { - expect(await api.getPositions({ symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getUserExecutionHistory()', async () => { - expect(await api.getUserExecutionHistory({ symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getClosedProfitAndLoss()', async () => { - expect(await api.getClosedProfitAndLoss({ symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - // Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before. - 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), - }); - }); - - it('getBalances()', async () => { - expect(await api.getBalances()).toMatchObject(successResponseObjectV3()); - }); - - it('getTradingFeeRate()', async () => { - expect(await api.getTradingFeeRate()).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getWalletFundRecords()', async () => { - expect(await api.getWalletFundRecords()).toMatchObject( - successResponseObjectV3(), - ); - }); -}); diff --git a/test/contract/private.write.test.ts b/test/contract/private.write.test.ts deleted file mode 100644 index 8d72ac1..0000000 --- a/test/contract/private.write.test.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { API_ERROR_CODE, ContractClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObjectV3 } from '../response.util'; - -describe('Private Contract REST API POST Endpoints', () => { - 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 ContractClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - - /** - * While it may seem silly, these tests simply validate the request is processed at all. - * Something very wrong would be a sign error or complaints about the endpoint/request method/server error. - */ - - it('submitOrder()', async () => { - expect( - await api.submitOrder({ - symbol, - side: 'Sell', - orderType: 'Limit', - qty: '1', - price: '20000', - orderLinkId: Date.now().toString(), - timeInForce: 'GoodTillCancel', - positionIdx: '2', - }), - ).toMatchObject({ - // retMsg: '', - retCode: API_ERROR_CODE.CONTRACT_INSUFFICIENT_BALANCE, - }); - }); - - it('cancelOrder()', async () => { - expect( - await api.cancelOrder({ - symbol, - orderId: 'somethingFake1', - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.CONTRACT_ORDER_NOT_EXISTS, - }); - }); - - it('cancelAllOrders()', async () => { - expect(await api.cancelAllOrders(symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('modifyOrder()', async () => { - expect( - await api.modifyOrder({ - symbol, - orderId: 'somethingFake', - price: '20000', - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.CONTRACT_ORDER_NOT_EXISTS, - }); - }); - - it('setAutoAddMargin()', async () => { - expect( - await api.setAutoAddMargin({ - autoAddMargin: 1, - side: 'Buy', - symbol, - positionIdx: 1, - }), - ).toMatchObject({ - retMsg: expect.stringMatching(/not modified/gim), - retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, - }); - }); - - it('setMarginSwitch()', async () => { - expect( - await api.setMarginSwitch({ - symbol, - tradeMode: 1, - buyLeverage: '5', - sellLeverage: '5', - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.CONTRACT_MARGIN_MODE_NOT_MODIFIED, - }); - }); - - it('setPositionMode()', async () => { - expect( - await api.setPositionMode({ - symbol, - mode: 3, - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.CONTRACT_POSITION_MODE_NOT_MODIFIED, - }); - }); - - it('setTPSLMode()', async () => { - expect(await api.setTPSLMode(symbol, 'Full')).toMatchObject({ - retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, - retMsg: expect.stringMatching(/same/gim), - }); - }); - - it('setLeverage()', async () => { - expect(await api.setLeverage(symbol, '5', '5')).toMatchObject({ - retCode: API_ERROR_CODE.CONTRACT_SET_LEVERAGE_NOT_MODIFIED, - }); - }); - - it('setTPSL()', async () => { - expect( - await api.setTPSL({ symbol, positionIdx: 1, stopLoss: '100' }), - ).toMatchObject({ - retMsg: expect.stringMatching(/zero position/gim), - retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, - }); - }); - - it('setRiskLimit()', async () => { - expect(await api.setRiskLimit(symbol, 43, 2)).toMatchObject({ - // retMsg: '', - retCode: API_ERROR_CODE.CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS, - }); - }); -}); diff --git a/test/contract/public.read.test.ts b/test/contract/public.read.test.ts deleted file mode 100644 index eb58185..0000000 --- a/test/contract/public.read.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { ContractClient, UMCandlesRequest } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { - successResponseObject, - successResponseObjectV3, -} from '../response.util'; - -describe('Public Contract REST API Endpoints', () => { - const API_KEY = undefined; - const API_SECRET = undefined; - - const api = new ContractClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - const category = 'linear'; - const start = Number((Date.now() / 1000).toFixed(0)); - const end = start + 1000 * 60 * 60 * 24; - const interval = '1'; - - const candleRequest: UMCandlesRequest = { - category, - symbol, - interval, - start, - end, - }; - - it('getOrderBook()', async () => { - expect(await api.getOrderBook(symbol, category)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCandles()', async () => { - expect(await api.getCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getSymbolTicker()', async () => { - expect(await api.getSymbolTicker(category)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getInstrumentInfo()', async () => { - expect(await api.getInstrumentInfo({ category })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getMarkPriceCandles()', async () => { - expect(await api.getMarkPriceCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getIndexPriceCandles()', async () => { - expect(await api.getIndexPriceCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getFundingRateHistory()', async () => { - expect( - await api.getFundingRateHistory({ - category, - symbol, - }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('getRiskLimit()', async () => { - expect(await api.getRiskLimit(category, symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getOptionDeliveryPrice()', async () => { - expect(await api.getOptionDeliveryPrice({ category })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getTrades()', async () => { - expect(await api.getTrades({ category, symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getOpenInterest()', async () => { - expect( - await api.getOpenInterest({ symbol, category, interval: '5min' }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); -}); diff --git a/test/contract/ws.private.test.ts b/test/contract/ws.private.test.ts deleted file mode 100644 index 5392208..0000000 --- a/test/contract/ws.private.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Private Contract Websocket Client', () => { - const API_KEY = process.env.API_KEY_COM; - const API_SECRET = process.env.API_SECRET_COM; - - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'contractUSDT', - key: API_KEY, - secret: API_SECRET, - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - // fullLogger - ); - // logAllEvents(wsClient); - wsClient.connectPrivate(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a private ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.contractUSDTPrivate, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - it('should authenticate successfully', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - try { - expect(await wsResponsePromise).toMatchObject({ - op: 'auth', - req_id: 'contractUSDTPrivate-auth', - success: true, - wsKey: WS_KEY_MAP.contractUSDTPrivate, - }); - } catch (e) { - // sub failed - expect(e).toBeFalsy(); - } - - // try { - // expect(await wsUpdatePromise).toStrictEqual(''); - // } catch (e) { - // // no data - // expect(e).toBeFalsy(); - // } - }); -}); diff --git a/test/contract/ws.public.inverse.test.ts b/test/contract/ws.public.inverse.test.ts deleted file mode 100644 index 24cc45e..0000000 --- a/test/contract/ws.public.inverse.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Contract Inverse Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'contractInverse', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - ); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.contractInversePublic, - }); - } catch (e) { - console.error('open: ', e); - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'orderbook.1.BTCUSD'; - wsClient.subscribe(wsTopic); - - try { - expect(await wsResponsePromise).toMatchObject({ - success: true, - op: 'subscribe', - }); - } catch (e) { - console.error('response: ', e); - // sub failed (or jest expect threw) - expect(e).toBeFalsy(); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - topic: wsTopic, - data: { - a: expect.any(Array), - }, - }); - } catch (e) { - console.error(`Wait for "${wsTopic}" event exception: `, e); - } - }); -}); diff --git a/test/contract/ws.public.usdt.test.ts b/test/contract/ws.public.usdt.test.ts deleted file mode 100644 index c72b7c5..0000000 --- a/test/contract/ws.public.usdt.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Contract USDT Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'contractUSDT', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - ); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.contractUSDTPublic, - }); - } catch (e) { - console.error('open: ', e); - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'orderbook.1.BTCUSDT'; - wsClient.subscribe(wsTopic); - - try { - expect(await wsResponsePromise).toMatchObject({ - success: true, - op: 'subscribe', - }); - } catch (e) { - console.error('response: ', e); - // sub failed (or jest expect threw) - expect(e).toBeFalsy(); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - topic: wsTopic, - data: { - a: expect.any(Array), - }, - }); - } catch (e) { - console.error(`Wait for "${wsTopic}" event exception: `, e); - } - }); -}); diff --git a/test/copy-trading/private.read.test.ts b/test/copy-trading/private.read.test.ts deleted file mode 100644 index 714bf3c..0000000 --- a/test/copy-trading/private.read.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { API_ERROR_CODE, CopyTradingClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObjectV3 } from '../response.util'; - -describe('Private Copy Trading REST API GET Endpoints', () => { - 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 CopyTradingClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - // Don't have copy trading properly enabled on the test account, so testing is very light - // (just make sure auth works and endpoint doesn't throw) - - it('getActiveOrders()', async () => { - expect(await api.getActiveOrders()).toMatchObject({ - retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, - }); - }); - - it('getPositions()', async () => { - expect(await api.getPositions()).toMatchObject({ - retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS, - }); - }); - - it('getBalances()', async () => { - 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.INCORRECT_API_KEY_PERMISSIONS, - }); - }); -}); diff --git a/test/copy-trading/public.read.test.ts b/test/copy-trading/public.read.test.ts deleted file mode 100644 index e42dcc9..0000000 --- a/test/copy-trading/public.read.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { CopyTradingClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObject } from '../response.util'; - -describe('Public Copy Trading REST API Endpoints', () => { - const API_KEY = undefined; - const API_SECRET = undefined; - - const api = new CopyTradingClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject({ - result: { - list: expect.any(Array), - }, - }); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); -}); diff --git a/test/inverse-futures/private.read.test.ts b/test/inverse-futures/private.read.test.ts deleted file mode 100644 index 73d0632..0000000 --- a/test/inverse-futures/private.read.test.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { InverseFuturesClient } from '../../src/inverse-futures-client'; -import { getTestProxy } from '../proxy.util'; -import { successResponseList, successResponseObject } from '../response.util'; - -describe.skip('Private Inverse-Futures REST API GET Endpoints', () => { - const API_KEY = process.env.API_KEY_COM; - const API_SECRET = process.env.API_SECRET_COM; - - const api = new InverseFuturesClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - // Warning: if some of these start to fail with 10001 params error, - // it's probably that this future expired and a newer one exists with a different symbol! - let symbol = ''; - - beforeAll(async () => { - const symbolsResponse = await api.getSymbols(); - - const prefix = 'BTCUSD'; - - const futuresAsset = symbolsResponse.result - .filter((row) => row.name.startsWith(prefix)) - .find((row) => { - const splitSymbol = row.name.split(prefix); - return splitSymbol[1] && splitSymbol[1] !== 'T'; - }); - - if (!futuresAsset?.name) { - throw new Error('No symbol'); - } - - symbol = futuresAsset?.name; - console.log('Symbol: ', symbol); - }); - - 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('getPredictedFunding()', async () => { - expect(await api.getPredictedFunding({ symbol: 'BTCUSD' })).toMatchObject( - successResponseObject(), - ); - }); - - it('getLcpInfo()', async () => { - expect(await api.getLcpInfo({ symbol: symbol })).toMatchObject( - successResponseObject(), - ); - }); -}); diff --git a/test/inverse-futures/private.write.test.ts b/test/inverse-futures/private.write.test.ts deleted file mode 100644 index ad15698..0000000 --- a/test/inverse-futures/private.write.test.ts +++ /dev/null @@ -1,206 +0,0 @@ -import { API_ERROR_CODE, InverseFuturesClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObject } from '../response.util'; - -describe.skip('Private Inverse-Futures REST API POST Endpoints', () => { - 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 InverseFuturesClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - // Warning: if some of these start to fail with 10001 params error, - // it's probably that this future expired and a newer one exists with a different symbol! - let symbol = ''; - - beforeAll(async () => { - const symbolsResponse = await api.getSymbols(); - - const prefix = 'BTCUSD'; - - const futuresAsset = symbolsResponse.result - .filter((row) => row.name.startsWith(prefix)) - .find((row) => { - const splitSymbol = row.name.split(prefix); - return splitSymbol[1] && splitSymbol[1] !== 'T'; - }); - - if (!futuresAsset?.name) { - throw new Error('No symbol'); - } - - symbol = futuresAsset?.name; - console.log('Symbol: ', symbol); - }); - - // These tests are primarily check auth is working by expecting balance or order not found style errors - - it('placeActiveOrder()', async () => { - expect( - await api.placeActiveOrder({ - side: 'Buy', - symbol, - order_type: 'Limit', - price: 30000, - qty: 1, - time_in_force: 'GoodTillCancel', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE, - }); - }); - - it('cancelActiveOrder()', async () => { - expect( - await api.cancelActiveOrder({ - symbol, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('cancelAllActiveOrders()', async () => { - expect( - await api.cancelAllActiveOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceActiveOrder()', async () => { - expect( - await api.replaceActiveOrder({ - symbol, - order_id: '123123123', - p_r_qty: '1', - p_r_price: '30000', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('placeConditionalOrder()', async () => { - expect( - await api.placeConditionalOrder({ - order_type: 'Limit', - side: 'Buy', - symbol, - qty: '1', - price: '8100', - base_price: '8300', - stop_px: '8150', - time_in_force: 'GoodTillCancel', - order_link_id: 'cus_order_id_1', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE, - }); - }); - - it('cancelConditionalOrder()', async () => { - expect( - await api.cancelConditionalOrder({ - symbol, - order_link_id: 'lkasmdflasd', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('cancelAllConditionalOrders()', async () => { - expect( - await api.cancelAllConditionalOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceConditionalOrder()', async () => { - expect( - await api.replaceConditionalOrder({ - symbol, - order_link_id: 'fakeOrderId', - p_r_price: '50000', - p_r_qty: 1, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - ret_msg: expect.stringMatching( - /orderID or orderLinkID invalid|order not exists/gim, - ), - }); - }); - - it('changePositionMargin()', async () => { - expect( - await api.changePositionMargin({ - symbol, - margin: '10', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE, - }); - }); - - it('setTradingStop()', async () => { - expect( - await api.setTradingStop({ - symbol, - take_profit: 50000, - }), - ).toMatchObject({ - // seems to fluctuate between POSITION_STATUS_NOT_NORMAL and POSITION_IDX_NOT_MATCH_POSITION_MODE - ret_code: /^30013|30041$/, - }); - }); - - it('setUserLeverage()', async () => { - expect( - await api.setUserLeverage({ - symbol, - buy_leverage: 5, - sell_leverage: 5, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.LEVERAGE_NOT_MODIFIED, - }); - }); - - it('setPositionMode()', async () => { - expect( - await api.setPositionMode({ - symbol, - mode: 3, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.POSITION_MODE_NOT_MODIFIED, - }); - }); - - it('setMarginType()', async () => { - expect( - await api.setMarginType({ - symbol, - is_isolated: false, - buy_leverage: 5, - sell_leverage: 5, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ISOLATED_NOT_MODIFIED, - }); - }); -}); diff --git a/test/inverse-futures/public.test.ts b/test/inverse-futures/public.test.ts deleted file mode 100644 index 1f5bbf0..0000000 --- a/test/inverse-futures/public.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { InverseFuturesClient } from '../../src/inverse-futures-client'; -import { getTestProxy } from '../proxy.util'; -import { - notAuthenticatedError, - successResponseList, - successResponseObject, -} from '../response.util'; - -describe.skip('Public Inverse-Futures REST API Endpoints', () => { - const api = new InverseFuturesClient({}, getTestProxy()); - - const symbol = 'BTCUSD'; - const interval = '15'; - const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60; - const from = Number(timestampOneHourAgo.toFixed(0)); - - describe('Inverse-Futures only endpoints', () => { - it('should throw for unauthenticated private calls', async () => { - expect(() => api.getPosition()).rejects.toMatchObject( - notAuthenticatedError(), - ); - expect(() => api.getApiKeyInfo()).rejects.toMatchObject( - notAuthenticatedError(), - ); - }); - - it('getOrderBook()', async () => { - expect(await api.getOrderBook({ symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getKline()', async () => { - expect(await api.getKline({ symbol, interval, from })).toMatchObject( - successResponseList(), - ); - }); - - it('getTickers()', async () => { - expect(await api.getTickers()).toMatchObject(successResponseList()); - }); - - it('getTrades()', async () => { - expect(await api.getTrades({ symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject(successResponseList()); - }); - - it('getMarkPriceKline()', async () => { - expect( - await api.getMarkPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getIndexPriceKline()', async () => { - expect( - await api.getIndexPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getPremiumIndexKline()', async () => { - expect( - await api.getPremiumIndexKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getLastFundingRate()', async () => { - expect(await api.getLastFundingRate({ symbol })).toMatchObject( - successResponseObject(), - ); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); - - it('fetchServertime() returns number', async () => { - expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); - }); - - it('getApiAnnouncements()', async () => { - expect(await api.getApiAnnouncements()).toMatchObject( - successResponseList(), - ); - }); - }); -}); diff --git a/test/inverse/private.read.test.ts b/test/inverse/private.read.test.ts deleted file mode 100644 index 7f32d4e..0000000 --- a/test/inverse/private.read.test.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { InverseClient } from '../../src/'; -import { getTestProxy } from '../proxy.util'; -import { successResponseList, successResponseObject } from '../response.util'; - -describe.skip('Private Inverse REST API GET Endpoints', () => { - 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( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSD'; - - 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(), - ); - }); -}); diff --git a/test/inverse/private.write.test.ts b/test/inverse/private.write.test.ts deleted file mode 100644 index e45efc4..0000000 --- a/test/inverse/private.write.test.ts +++ /dev/null @@ -1,181 +0,0 @@ -import { API_ERROR_CODE } from '../../src'; -import { InverseClient } from '../../src/inverse-client'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObject } from '../response.util'; - -describe.skip('Private Inverse REST API POST Endpoints', () => { - 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( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSD'; - - // These tests are primarily check auth is working by expecting balance or order not found style errors - - it('placeActiveOrder()', async () => { - expect( - await api.placeActiveOrder({ - side: 'Buy', - symbol, - order_type: 'Limit', - price: 30000, - qty: 1, - time_in_force: 'GoodTillCancel', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.INSUFFICIENT_BALANCE_FOR_ORDER_COST, - }); - }); - - it('cancelActiveOrder()', async () => { - expect( - await api.cancelActiveOrder({ - symbol, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('cancelAllActiveOrders()', async () => { - expect( - await api.cancelAllActiveOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceActiveOrder()', async () => { - expect( - await api.replaceActiveOrder({ - symbol, - order_id: '123123123', - p_r_qty: 1, - p_r_price: '30000', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('placeConditionalOrder()', async () => { - expect( - await api.placeConditionalOrder({ - order_type: 'Limit', - side: 'Buy', - symbol, - qty: '1', - price: '8100', - base_price: '8300', - stop_px: '8150', - time_in_force: 'GoodTillCancel', - order_link_id: 'cus_order_id_1', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.INSUFFICIENT_BALANCE, - }); - }); - - it('cancelConditionalOrder()', async () => { - expect( - await api.cancelConditionalOrder({ - symbol, - order_link_id: 'lkasmdflasd', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - it('cancelAllConditionalOrders()', async () => { - expect( - await api.cancelAllConditionalOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceConditionalOrder()', async () => { - expect( - await api.replaceConditionalOrder({ - symbol, - p_r_price: '50000', - p_r_qty: 1, - order_link_id: 'fakeorderid', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE, - }); - }); - - // server error, but v2 is going away anyway - it.skip('changePositionMargin()', async () => { - expect( - await api.changePositionMargin({ - symbol, - margin: '10', - }), - ).toMatchObject({ - ret_msg: 'test', - ret_code: API_ERROR_CODE.POSITION_IS_CROSS_MARGIN, - }); - }); - - it('setTradingStop()', async () => { - expect( - await api.setTradingStop({ - symbol, - take_profit: 5555, - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.CANNOT_SET_TRADING_STOP_FOR_ZERO_POS, - }); - }); - - it('setUserLeverage()', async () => { - expect( - await api.setUserLeverage({ - symbol, - leverage: 5, - }), - ).toMatchObject({ - result: 5, - ret_code: 0, - }); - }); - - it('setSlTpPositionMode()', async () => { - expect( - await api.setSlTpPositionMode({ - symbol, - tp_sl_mode: 'Full', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.SAME_SLTP_MODE, - }); - }); - - it('setMarginType()', async () => { - expect( - await api.setMarginType({ - symbol, - is_isolated: false, - buy_leverage: 5, - sell_leverage: 5, - }), - ).toMatchObject(successResponseObject()); - }); -}); diff --git a/test/inverse/public.test.ts b/test/inverse/public.test.ts deleted file mode 100644 index e951d38..0000000 --- a/test/inverse/public.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { InverseClient } from '../../src/inverse-client'; -import { getTestProxy } from '../proxy.util'; -import { - notAuthenticatedError, - successResponseList, - successResponseObject, -} from '../response.util'; - -describe.skip('Public Inverse REST API Endpoints', () => { - const api = new InverseClient({}, getTestProxy()); - - 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('should throw for unauthenticated private calls', async () => { - expect(() => api.getPosition()).rejects.toMatchObject( - notAuthenticatedError(), - ); - expect(() => api.getApiKeyInfo()).rejects.toMatchObject( - notAuthenticatedError(), - ); - }); - - it('getOrderBook()', async () => { - expect(await api.getOrderBook({ symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getKline()', async () => { - expect(await api.getKline({ symbol, interval, from })).toMatchObject( - successResponseList(), - ); - }); - - it('getTickers()', async () => { - expect(await api.getTickers()).toMatchObject(successResponseList()); - }); - - it('getTrades()', async () => { - expect(await api.getTrades({ symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject(successResponseList()); - }); - - it('getMarkPriceKline()', async () => { - expect( - await api.getMarkPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getIndexPriceKline()', async () => { - expect( - await api.getIndexPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getPremiumIndexKline()', async () => { - expect( - await api.getPremiumIndexKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getLastFundingRate()', async () => { - expect(await api.getLastFundingRate({ symbol })).toMatchObject( - successResponseObject(), - ); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); - - it('fetchServertime() returns number', async () => { - expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); - }); - - it('getApiAnnouncements()', async () => { - expect(await api.getApiAnnouncements()).toMatchObject( - successResponseList(), - ); - }); - }); -}); diff --git a/test/inverse/ws.private.test.ts b/test/inverse/ws.private.test.ts deleted file mode 100644 index bc78fa6..0000000 --- a/test/inverse/ws.private.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Private Inverse Perps Websocket Client', () => { - const API_KEY = process.env.API_KEY_COM; - const API_SECRET = process.env.API_SECRET_COM; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'inverse', - key: API_KEY, - secret: API_SECRET, - }; - - describe('with invalid credentials', () => { - it('should fail to open a connection if keys/signature are incorrect', async () => { - const badClient = new WebsocketClient( - { - ...wsClientOptions, - key: 'bad', - secret: 'bad', - }, - getSilentLogger('expect401'), - ); - - const wsOpenPromise = waitForSocketEvent(badClient, 'open', 2500); - - badClient.connectPrivate(); - - try { - expect(await wsOpenPromise).toMatch('Failed to receive'); - } catch (e) { - // console.error() - expect(e?.message).toStrictEqual('Unexpected server response: 401'); - } - badClient.closeAll(true); - }); - }); - - describe('with valid API credentails', () => { - let wsClient: WebsocketClient; - - it('should have api credentials to test with', () => { - expect(API_KEY).toStrictEqual(expect.any(String)); - expect(API_SECRET).toStrictEqual(expect.any(String)); - }); - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccess'), - ); - wsClient.connectPrivate(); - }); - - afterAll(() => { - // await promiseSleep(2000); - wsClient.closeAll(true); - }); - - it('should open a ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.inverse, - }); - }); - - it('should subscribe to private wallet events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'wallet'; - // No easy way to trigger a private event (other than executing trades) - // expect(wsUpdatePromise).resolves.toMatchObject({ - // topic: wsTopic, - // data: expect.any(Array), - // }); - - wsClient.subscribe(wsTopic); - - expect(await wsResponsePromise).toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); - }); - }); -}); diff --git a/test/inverse/ws.public.test.ts b/test/inverse/ws.public.test.ts deleted file mode 100644 index 96b75e6..0000000 --- a/test/inverse/ws.public.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - LinearClient, - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - promiseSleep, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Public Inverse Perps Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'inverse', - }; - - beforeAll(() => { - wsClient = new WebsocketClient(wsClientOptions, getSilentLogger('public')); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.inverse, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderBookL2_25 events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'orderBookL2_25.BTCUSD'; - expect(wsResponsePromise).resolves.toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); - expect(wsUpdatePromise).resolves.toMatchObject({ - topic: wsTopic, - data: expect.any(Array), - }); - - wsClient.subscribe(wsTopic); - - try { - await wsResponsePromise; - } catch (e) { - console.error( - `Wait for "${wsTopic}" subscription response exception: `, - e, - ); - } - - try { - await wsUpdatePromise; - } catch (e) { - console.error(`Wait for "${wsTopic}" event exception: `, e); - } - }); -}); diff --git a/test/linear/private.read.test.ts b/test/linear/private.read.test.ts deleted file mode 100644 index cce0f32..0000000 --- a/test/linear/private.read.test.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { LinearClient } from '../../src/linear-client'; -import { getTestProxy } from '../proxy.util'; -import { successResponseList, successResponseObject } from '../response.util'; - -describe.skip('Private Linear REST API GET Endpoints', () => { - 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 LinearClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - - 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(), - // ret_msg: 'ok', - }); - }); - - 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('getRiskLimitList()', async () => { - expect(await api.getRiskLimitList({ symbol: symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getPredictedFundingFee()', async () => { - expect(await api.getPredictedFundingFee({ symbol: symbol })).toMatchObject( - successResponseObject(), - ); - }); - - it('getLastFundingFee()', async () => { - expect(await api.getLastFundingFee({ symbol: symbol })).toMatchObject( - successResponseObject(), - ); - }); -}); diff --git a/test/linear/private.write.test.ts b/test/linear/private.write.test.ts deleted file mode 100644 index 74e55b5..0000000 --- a/test/linear/private.write.test.ts +++ /dev/null @@ -1,224 +0,0 @@ -import { LinearClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObject } from '../response.util'; - -describe.skip('Private Linear REST API POST Endpoints', () => { - 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 LinearClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - // Warning: if some of these start to fail with 10001 params error, - // it's probably that this future expired and a newer one exists with a different symbol! - const symbol = 'BTCUSDT'; - - // These tests are primarily check auth is working by expecting balance or order not found style errors - - it('placeActiveOrder()', async () => { - expect( - await api.placeActiveOrder({ - side: 'Buy', - symbol, - order_type: 'Limit', - price: 20000, - qty: 1, - time_in_force: 'GoodTillCancel', - reduce_only: false, - close_on_trigger: false, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('cancelActiveOrder()', async () => { - expect( - await api.cancelActiveOrder({ - symbol, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('cancelAllActiveOrders()', async () => { - expect( - await api.cancelAllActiveOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceActiveOrder()', async () => { - expect( - await api.replaceActiveOrder({ - symbol, - order_id: '123123123', - p_r_qty: 1, - p_r_price: 30000, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('placeConditionalOrder()', async () => { - expect( - await api.placeConditionalOrder({ - order_type: 'Limit', - side: 'Buy', - symbol, - qty: 1000000, - price: 8100, - base_price: 8300, - stop_px: 8150, - time_in_force: 'GoodTillCancel', - reduce_only: false, - trigger_by: 'LastPrice', - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('cancelConditionalOrder()', async () => { - expect( - await api.cancelConditionalOrder({ - symbol, - order_link_id: 'lkasmdflasd', - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('cancelAllConditionalOrders()', async () => { - expect( - await api.cancelAllConditionalOrders({ - symbol, - }), - ).toMatchObject(successResponseObject()); - }); - - it('replaceConditionalOrder()', async () => { - expect( - await api.replaceConditionalOrder({ - symbol, - p_r_price: 50000, - p_r_qty: 1, - order_link_id: 'someorderid', - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setAutoAddMargin()', async () => { - expect( - await api.setAutoAddMargin({ - symbol, - side: 'Buy', - auto_add_margin: true, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setMarginSwitch()', async () => { - expect( - await api.setMarginSwitch({ - symbol, - is_isolated: true, - buy_leverage: 10, - sell_leverage: 10, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setPositionMode()', async () => { - expect( - await api.setPositionMode({ - symbol, - mode: 'BothSide', - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setPositionTpSlMode()', async () => { - expect( - await api.setPositionTpSlMode({ - symbol, - tp_sl_mode: 'Full', - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setAddReduceMargin()', async () => { - expect( - await api.setAddReduceMargin({ - symbol, - side: 'Buy', - margin: 5, - }), - ).toMatchObject({ - // ret_msg: '', - ret_code: expect.any(Number), - // ret_code: API_ERROR_CODE.ISOLATED_NOT_MODIFIED_LINEAR, - }); - }); - - it('setUserLeverage()', async () => { - expect( - await api.setUserLeverage({ - symbol, - buy_leverage: 5, - sell_leverage: 5, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it('setTradingStop()', async () => { - expect( - await api.setTradingStop({ - symbol, - side: 'Buy', - take_profit: 555, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); - - it.skip('setRiskLimit()', async () => { - expect( - await api.setRiskLimit({ - symbol, - side: 'Buy', - risk_id: 2, - }), - ).toMatchObject({ - ret_code: expect.any(Number), - }); - }); -}); diff --git a/test/linear/public.test.ts b/test/linear/public.test.ts deleted file mode 100644 index ce504d2..0000000 --- a/test/linear/public.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { LinearClient } from '../../src/linear-client'; -import { getTestProxy } from '../proxy.util'; -import { - notAuthenticatedError, - successResponseList, - successResponseObject, -} from '../response.util'; - -describe.skip('Public Linear REST API Endpoints', () => { - const api = new LinearClient({}, getTestProxy()); - - const symbol = 'BTCUSDT'; - const interval = '15'; - const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60; - const from = Number(timestampOneHourAgo.toFixed(0)); - - describe('Linear only endpoints', () => { - it('should throw for unauthenticated private calls', async () => { - expect(() => api.getPosition()).rejects.toMatchObject( - notAuthenticatedError(), - ); - expect(() => api.getApiKeyInfo()).rejects.toMatchObject( - notAuthenticatedError(), - ); - }); - - it('getOrderBook()', async () => { - expect(await api.getOrderBook({ symbol })).toMatchObject( - successResponseList(), - ); - }); - - it('getKline()', async () => { - expect(await api.getKline({ symbol, interval, from })).toMatchObject( - successResponseList(), - ); - }); - - it('getTickers()', async () => { - expect(await api.getTickers()).toMatchObject(successResponseList()); - }); - - it('getTrades()', async () => { - expect(await api.getTrades({ symbol })).toMatchObject( - successResponseList(), - ); - }); - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject(successResponseList()); - }); - - it('getMarkPriceKline()', async () => { - expect( - await api.getMarkPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getIndexPriceKline()', async () => { - expect( - await api.getIndexPriceKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getPremiumIndexKline()', async () => { - expect( - await api.getPremiumIndexKline({ symbol, interval, from }), - ).toMatchObject(successResponseList()); - }); - - it('getLastFundingRate()', async () => { - expect(await api.getLastFundingRate({ symbol })).toMatchObject( - successResponseObject(), - ); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); - - it('fetchServertime() returns number', async () => { - expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); - }); - - it('getApiAnnouncements()', async () => { - expect(await api.getApiAnnouncements()).toMatchObject( - successResponseList(), - ); - }); - }); -}); diff --git a/test/linear/ws.private.test.ts b/test/linear/ws.private.test.ts deleted file mode 100644 index 8a7f683..0000000 --- a/test/linear/ws.private.test.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Private Linear Perps Websocket Client', () => { - const API_KEY = process.env.API_KEY_COM; - const API_SECRET = process.env.API_SECRET_COM; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'linear', - key: API_KEY, - secret: API_SECRET, - }; - - describe('with invalid credentials', () => { - it('should fail to open a connection if keys/signature are incorrect', async () => { - const badClient = new WebsocketClient( - { - ...wsClientOptions, - key: 'bad', - secret: 'bad', - }, - getSilentLogger('expect401'), - ); - - const wsOpenPromise = waitForSocketEvent(badClient, 'open', 2500); - badClient.connectPrivate(); - - try { - expect(await wsOpenPromise).toMatch('Failed to receive'); - } catch (e) { - expect(e?.message).toStrictEqual('Unexpected server response: 401'); - } - badClient.closeAll(true); - }); - }); - - describe('with valid API credentails', () => { - let wsClient: WebsocketClient; - - it('should have api credentials to test with', () => { - expect(API_KEY).toStrictEqual(expect.any(String)); - expect(API_SECRET).toStrictEqual(expect.any(String)); - }); - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'linear', - key: API_KEY, - secret: API_SECRET, - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccess'), - ); - wsClient.connectPrivate(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.linearPrivate, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to private wallet events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'wallet'; - expect(wsResponsePromise).resolves.toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); - - // No easy way to trigger a private event (other than executing trades) - // expect(wsUpdatePromise).resolves.toMatchObject({ - // topic: wsTopic, - // data: expect.any(Array), - // }); - - wsClient.subscribe(wsTopic); - - await Promise.all([wsResponsePromise]); - }); - }); -}); diff --git a/test/linear/ws.public.test.ts b/test/linear/ws.public.test.ts deleted file mode 100644 index aee4ffc..0000000 --- a/test/linear/ws.public.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Public Linear Perps Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'linear', - }; - - beforeAll(() => { - wsClient = new WebsocketClient(wsClientOptions, getSilentLogger('public')); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.linearPublic, - }); - }); - - it('should subscribe to public orderBookL2_25 events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const wsTopic = 'orderBookL2_25.BTCUSDT'; - wsClient.subscribe(wsTopic); - - try { - expect(await wsResponsePromise).toMatchObject({ - request: { - args: [wsTopic], - op: 'subscribe', - }, - success: true, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - topic: wsTopic, - data: { - order_book: expect.any(Array), - }, - }); - } catch (e) { - console.error(`Wait for "${wsTopic}" event exception: `, e); - } - }); -}); diff --git a/test/spot/private.v1.read.test.ts b/test/spot/private.v1.read.test.ts deleted file mode 100644 index af8425c..0000000 --- a/test/spot/private.v1.read.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { SpotClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { errorResponseObject, successResponseList } from '../response.util'; - -describe.skip('Private Spot REST API GET Endpoints', () => { - 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 SpotClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - it('getOrder()', async () => { - // No auth error == test pass - expect(await api.getOrder({ orderId: '123123' })).toMatchObject( - errorResponseObject({}, -2013, 'Order does not exist.'), - ); - }); - - it('getOpenOrders()', async () => { - expect(await api.getOpenOrders()).toMatchObject(successResponseList()); - }); - - it('getPastOrders()', async () => { - expect(await api.getPastOrders()).toMatchObject(successResponseList()); - }); - - it('getMyTrades()', async () => { - expect(await api.getMyTrades()).toMatchObject(successResponseList()); - }); - - it('getBalances()', async () => { - expect(await api.getBalances()).toMatchObject({ - result: { - balances: expect.any(Array), - }, - ret_code: 0, - ret_msg: 'OK', - }); - }); -}); diff --git a/test/spot/private.v1.write.test.ts b/test/spot/private.v1.write.test.ts deleted file mode 100644 index 41e59a5..0000000 --- a/test/spot/private.v1.write.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { API_ERROR_CODE, SpotClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObject } from '../response.util'; - -describe.skip('Private Spot REST API POST Endpoints', () => { - 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 SpotClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - // Warning: if some of these start to fail with 10001 params error, - // it's probably that this future expired and a newer one exists with a different symbol! - const symbol = 'BTCUSDT'; - - // These tests are primarily check auth is working by expecting balance or order not found style errors - - it('submitOrder()', async () => { - expect( - await api.submitOrder({ - side: 'Buy', - symbol, - qty: 10000, - type: 'MARKET', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT, - ret_msg: 'Balance insufficient ', - }); - }); - - it('cancelOrder()', async () => { - expect( - await api.cancelOrder({ - orderId: '1231231', - }), - ).toMatchObject({ - ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE_SPOT, - ret_msg: 'Order does not exist.', - }); - }); - - it('cancelOrderBatch()', async () => { - expect( - await api.cancelOrderBatch({ - symbol, - orderTypes: ['LIMIT', 'LIMIT_MAKER'], - }), - ).toMatchObject(successResponseObject()); - }); -}); diff --git a/test/spot/private.v3.read.test.ts b/test/spot/private.v3.read.test.ts deleted file mode 100644 index 2d61be0..0000000 --- a/test/spot/private.v3.read.test.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { API_ERROR_CODE, SpotClientV3 } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { - successEmptyResponseObjectV3, - successResponseListV3, - successResponseObjectV3, -} from '../response.util'; - -describe('Private Spot REST API GET Endpoints', () => { - 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 SpotClientV3( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - // const interval = '15m'; - const ltCode = 'BTC3S'; - - it('getOrder()', async () => { - // No auth error == test pass - expect(await api.getOrder({ orderId: '123123' })).toMatchObject({ - retCode: API_ERROR_CODE.ORDER_NOT_FOUND_SPOT_V3, - }); - }); - - it('getOpenOrders()', async () => { - expect(await api.getOpenOrders()).toMatchObject(successResponseListV3()); - }); - - it('getOpenOrders() with symbol', async () => { - expect(await api.getOpenOrders(symbol)).toMatchObject( - successResponseListV3(), - ); - }); - - it('getOpenOrders() with order category', async () => { - const orderId = undefined; - const ordersPerPage = undefined; - - // all these should succeed - expect( - await api.getOpenOrders(symbol, orderId, ordersPerPage), - ).toMatchObject(successResponseListV3()); - expect( - await api.getOpenOrders(symbol, orderId, ordersPerPage, 0), - ).toMatchObject(successResponseListV3()); - expect( - await api.getOpenOrders(symbol, orderId, ordersPerPage, 1), - ).toMatchObject(successResponseListV3()); - }); - - it('getPastOrders()', async () => { - expect(await api.getPastOrders()).toMatchObject(successResponseListV3()); - }); - - it('getMyTrades()', async () => { - expect(await api.getMyTrades()).toMatchObject(successResponseListV3()); - }); - - it('getBalances()', async () => { - expect(await api.getBalances()).toMatchObject({ - result: { - balances: expect.any(Array), - }, - ...successEmptyResponseObjectV3(), - }); - }); - - it('getLeveragedTokenMarketInfo()', async () => { - expect(await api.getLeveragedTokenMarketInfo(ltCode)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCrossMarginBorrowingInfo()', async () => { - expect(await api.getCrossMarginBorrowingInfo()).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCrossMarginAccountInfo()', async () => { - expect(await api.getCrossMarginAccountInfo()).toMatchObject({ - retCode: API_ERROR_CODE.CROSS_MARGIN_NOT_ENABLED, - }); - }); - - it('getCrossMarginInterestQuota()', async () => { - expect(await api.getCrossMarginInterestQuota('USDT')).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCrossMarginRepaymentHistory()', async () => { - expect(await api.getCrossMarginRepaymentHistory()).toMatchObject( - successResponseObjectV3(), - ); - }); -}); diff --git a/test/spot/private.v3.write.test.ts b/test/spot/private.v3.write.test.ts deleted file mode 100644 index 7e7a623..0000000 --- a/test/spot/private.v3.write.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { API_ERROR_CODE, SpotClientV3 } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { successResponseObjectV3 } from '../response.util'; - -describe('Private Spot REST API POST Endpoints', () => { - 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 SpotClientV3( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - const ltCode = 'BTC3S'; - - // These tests are primarily check auth is working by expecting balance or order not found style errors - - it('submitOrder()', async () => { - expect( - await api.submitOrder({ - side: 'Buy', - symbol, - orderQty: '10000', - orderType: 'MARKET', - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.BALANCE_INSUFFICIENT_SPOT_V3, - }); - }); - - it('cancelOrder()', async () => { - expect( - await api.cancelOrder({ - orderId: '1231231', - }), - ).toMatchObject({ - retCode: API_ERROR_CODE.ORDER_NOT_FOUND_SPOT_V3, - }); - }); - - it('cancelOrderBatch()', async () => { - expect( - await api.cancelOrderBatch({ - symbol, - orderTypes: ['LIMIT', 'LIMIT_MAKER'], - }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('purchaseLeveragedToken()', async () => { - expect(await api.purchaseLeveragedToken(ltCode, '1')).toMatchObject({ - retCode: API_ERROR_CODE.EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN, - }); - }); - - it('redeemLeveragedToken()', async () => { - expect(await api.redeemLeveragedToken(ltCode, '1')).toMatchObject({ - retCode: 12426, // unknown error code, not listed in docs yet - }); - }); - - it('borrowCrossMarginLoan()', async () => { - expect(await api.borrowCrossMarginLoan('USDT', '1')).toMatchObject({ - retCode: expect.any(Number), - }); - }); - - it('repayCrossMarginLoan()', async () => { - expect(await api.repayCrossMarginLoan('USDT', '1')).toMatchObject({ - retCode: expect.any(Number), - // previously: - // retCode: API_ERROR_CODE.CROSS_MARGIN_REPAYMENT_NOT_REQUIRED, - }); - }); -}); diff --git a/test/spot/public.v1.test.ts b/test/spot/public.v1.test.ts deleted file mode 100644 index 45ddbc0..0000000 --- a/test/spot/public.v1.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { SpotClient } from '../../src'; -import { - notAuthenticatedError, - successResponseList, - successResponseObject, -} from '../response.util'; - -describe.skip('Public Spot REST API Endpoints', () => { - const api = new SpotClient(); - - const symbol = 'BTCUSDT'; - const interval = '15m'; - const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60; - const from = Number(timestampOneHourAgo.toFixed(0)); - - it('should throw for unauthenticated private calls', async () => { - expect(() => api.getOpenOrders()).rejects.toMatchObject( - notAuthenticatedError(), - ); - expect(() => api.getBalances()).rejects.toMatchObject( - notAuthenticatedError(), - ); - }); - - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject(successResponseList()); - }); - - it('getOrderBook()', async () => { - expect(await api.getOrderBook(symbol)).toMatchObject( - successResponseObject(), - ); - }); - - it('getMergedOrderBook()', async () => { - expect(await api.getMergedOrderBook(symbol)).toMatchObject( - successResponseObject(), - ); - }); - - it('getTrades()', async () => { - expect(await api.getTrades(symbol)).toMatchObject(successResponseObject()); - }); - - it('getCandles()', async () => { - expect(await api.getCandles(symbol, interval)).toMatchObject( - successResponseObject(), - ); - }); - - it('get24hrTicker()', async () => { - expect(await api.get24hrTicker()).toMatchObject(successResponseObject()); - }); - - it('getLastTradedPrice()', async () => { - expect(await api.getLastTradedPrice()).toMatchObject( - successResponseObject(), - ); - }); - - it('getBestBidAskPrice()', async () => { - expect(await api.getBestBidAskPrice()).toMatchObject( - successResponseObject(), - ); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toStrictEqual(expect.any(Number)); - }); - - it('fetchServertime() returns number', async () => { - expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); - }); -}); diff --git a/test/spot/public.v3.test.ts b/test/spot/public.v3.test.ts deleted file mode 100644 index 7f468e8..0000000 --- a/test/spot/public.v3.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { SpotClientV3 } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { - notAuthenticatedError, - successResponseObjectV3, -} from '../response.util'; - -describe('Public Spot REST API Endpoints', () => { - const api = new SpotClientV3({}, getTestProxy()); - - const symbol = 'BTCUSDT'; - const interval = '15m'; - const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60; - const from = Number(timestampOneHourAgo.toFixed(0)); - - it('should throw for unauthenticated private calls', async () => { - expect(() => api.getOpenOrders()).rejects.toMatchObject( - notAuthenticatedError(), - ); - expect(() => api.getBalances()).rejects.toMatchObject( - notAuthenticatedError(), - ); - }); - - it('getSymbols()', async () => { - expect(await api.getSymbols()).toMatchObject(successResponseObjectV3()); - }); - - it('getOrderBook()', async () => { - expect(await api.getOrderBook(symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getMergedOrderBook()', async () => { - expect(await api.getMergedOrderBook(symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getTrades()', async () => { - expect(await api.getTrades(symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCandles()', async () => { - expect(await api.getCandles(symbol, interval)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('get24hrTicker()', async () => { - expect(await api.get24hrTicker()).toMatchObject(successResponseObjectV3()); - }); - - it('getLastTradedPrice()', async () => { - expect(await api.getLastTradedPrice()).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getBestBidAskPrice()', async () => { - expect(await api.getBestBidAskPrice()).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('fetchServertime() returns number', async () => { - expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); - }); -}); diff --git a/test/spot/ws.private.v1.test.ts b/test/spot/ws.private.v1.test.ts deleted file mode 100644 index 2a64338..0000000 --- a/test/spot/ws.private.v1.test.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - promiseSleep, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Private Spot V1 Websocket Client', () => { - let wsClient: WebsocketClient; - 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 wsClientOptions: WSClientConfigurableOptions = { - market: 'spot', - key: API_KEY, - secret: API_SECRET, - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - // fullLogger - getSilentLogger('expectSuccess'), - ); - logAllEvents(wsClient); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - // TODO: how to detect if auth failed for the v1 spot ws - it('should open a private ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - wsClient.connectPrivate(); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - // wsKey: WS_KEY_MAP.spotPrivate, - // also opens public conn automatically, which can confuse the test - }); - } catch (e) { - expect(e).toBeFalsy(); - } - // expect(wsUpdatePromise).resolves.toMatchObject({ - // topic: 'wsTopic', - // data: expect.any(Array), - // }); - - // await Promise.all([wsUpdatePromise]); - // await promiseSleep(4000); - }); -}); diff --git a/test/spot/ws.private.v3.test.ts b/test/spot/ws.private.v3.test.ts deleted file mode 100644 index 0628151..0000000 --- a/test/spot/ws.private.v3.test.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_ERROR_ENUM, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - waitForSocketEvent, -} from '../ws.util'; - -describe('Private Spot V3 Websocket Client', () => { - const API_KEY = process.env.API_KEY_COM; - const API_SECRET = process.env.API_SECRET_COM; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'spotv3', - key: API_KEY, - secret: API_SECRET, - }; - const wsTopic = 'outboundAccountInfo'; - - describe('with invalid credentials', () => { - it('should reject private subscribe if keys/signature are incorrect', async () => { - const badClient = new WebsocketClient( - { - ...wsClientOptions, - key: 'bad', - secret: 'bad', - }, - getSilentLogger('expect401') - ); - - // const wsOpenPromise = waitForSocketEvent(badClient, 'open'); - const wsResponsePromise = waitForSocketEvent(badClient, 'response'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - badClient.connectPrivate(); - badClient.subscribe(wsTopic); - - expect(wsResponsePromise).rejects.toMatchObject({ - ret_code: WS_ERROR_ENUM.API_SIGN_AUTH_FAILED, - ret_msg: expect.any(String), - type: 'error', - }); - - try { - await Promise.all([wsResponsePromise]); - } catch (e) { - // console.error() - } - badClient.closeAll(true); - }); - }); - - describe('with valid API credentails', () => { - let wsClient: WebsocketClient; - - it('should have api credentials to test with', () => { - expect(API_KEY).toStrictEqual(expect.any(String)); - expect(API_SECRET).toStrictEqual(expect.any(String)); - }); - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccess') - ); - wsClient.connectPrivate(); - // logAllEvents(wsClient); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a private ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotV3Private, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - - expect(await wsResponsePromise).toMatchObject({ - op: 'auth', - success: true, - req_id: `${WS_KEY_MAP.spotV3Private}-auth`, - }); - }); - - it('should subscribe to private outboundAccountInfo events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - - // expect(wsUpdatePromise).resolves.toStrictEqual(''); - wsClient.subscribe(wsTopic); - - expect(await wsResponsePromise).toMatchObject({ - op: 'subscribe', - success: true, - ret_msg: '', - req_id: wsTopic, - }); - }); - }); -}); diff --git a/test/spot/ws.public.v1.test.ts b/test/spot/ws.public.v1.test.ts deleted file mode 100644 index 8824b37..0000000 --- a/test/spot/ws.public.v1.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe.skip('Public Spot V1 Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'spot', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccess'), - ); - wsClient.connectPublic(); - // logAllEvents(wsClient); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotPublic, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events', async () => { - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const symbol = 'BTCUSDT'; - expect(wsUpdatePromise).resolves.toMatchObject({ - symbol: symbol, - symbolName: symbol, - topic: 'diffDepth', - params: { - realtimeInterval: '24h', - binary: 'false', - }, - data: expect.any(Array), - }); - - wsClient.subscribePublicSpotOrderbook(symbol, 'delta'); - - try { - await wsUpdatePromise; - } catch (e) { - console.error('Wait for spot v1 orderbook event exception: ', e); - } - }); -}); diff --git a/test/spot/ws.public.v3.test.ts b/test/spot/ws.public.v3.test.ts deleted file mode 100644 index a6327d8..0000000 --- a/test/spot/ws.public.v3.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Spot V3 Websocket Client', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'spotv3', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccess') - ); - wsClient.connectPublic(); - // logAllEvents(wsClient); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.spotV3Public, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - const symbol = 'BTCUSDT'; - const wsTopic = `orderbook.40.${symbol}`; - - expect(wsResponsePromise).resolves.toMatchObject({ - op: 'subscribe', - success: true, - ret_msg: 'subscribe', - req_id: wsTopic, - }); - - wsClient.subscribe(wsTopic); - - try { - await wsResponsePromise; - } catch (e) { - console.error( - `Wait for "${wsTopic}" subscription response exception: `, - e - ); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - data: { - a: expect.any(Array), - b: expect.any(Array), - s: symbol, - t: expect.any(Number), - }, - topic: wsTopic, - ts: expect.any(Number), - type: 'snapshot', - }); - } catch (e) { - console.error(`Wait for "${wsTopic}" event exception: `, e); - expect(e).toBeFalsy(); - } - }); -}); diff --git a/test/unified-margin/public.read.test.ts b/test/unified-margin/public.read.test.ts deleted file mode 100644 index 5e3cdc0..0000000 --- a/test/unified-margin/public.read.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { UMCandlesRequest, UnifiedMarginClient } from '../../src'; -import { getTestProxy } from '../proxy.util'; -import { - successResponseObject, - successResponseObjectV3, -} from '../response.util'; - -describe('Public Unified Margin REST API Endpoints', () => { - const API_KEY = undefined; - const API_SECRET = undefined; - - const api = new UnifiedMarginClient( - { - key: API_KEY, - secret: API_SECRET, - testnet: false, - }, - getTestProxy(), - ); - - const symbol = 'BTCUSDT'; - const category = 'linear'; - const start = Number((Date.now() / 1000).toFixed(0)); - const end = start + 1000 * 60 * 60 * 24; - const interval = '1'; - - const candleRequest: UMCandlesRequest = { - category, - symbol, - interval, - start, - end, - }; - - it('getOrderBook()', async () => { - expect(await api.getOrderBook(symbol, category)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getCandles()', async () => { - expect(await api.getCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getSymbolTicker()', async () => { - expect(await api.getSymbolTicker(category)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getInstrumentInfo()', async () => { - expect(await api.getInstrumentInfo({ category })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getMarkPrice()', async () => { - expect(await api.getMarkPriceCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getIndexPrice()', async () => { - expect(await api.getIndexPriceCandles(candleRequest)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getLastFundingRate()', async () => { - expect( - await api.getFundingRateHistory({ - category, - symbol, - }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('getRiskLimit()', async () => { - expect(await api.getRiskLimit(category, symbol)).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getOptionDeliveryPrice()', async () => { - expect(await api.getOptionDeliveryPrice({ category })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getTrades()', async () => { - expect(await api.getTrades({ category, symbol })).toMatchObject( - successResponseObjectV3(), - ); - }); - - it('getOpenInterest()', async () => { - expect( - await api.getOpenInterest({ symbol, category, interval: '5min' }), - ).toMatchObject(successResponseObjectV3()); - }); - - it('getServerTime()', async () => { - expect(await api.getServerTime()).toMatchObject(successResponseObject()); - }); -}); diff --git a/test/unified-margin/ws.public.option.test.ts b/test/unified-margin/ws.public.option.test.ts deleted file mode 100644 index 0d7cc79..0000000 --- a/test/unified-margin/ws.public.option.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Unified Margin Websocket Client (Options)', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'unifiedOption', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - ); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: WS_KEY_MAP.unifiedOptionPublic, - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - // const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - wsClient.subscribe('orderbook.25.BTCUSDT'); - - try { - expect(await wsResponsePromise).toMatchObject({ - success: true, - type: 'COMMAND_RESP', - }); - } catch (e) { - // sub failed - expect(e).toBeFalsy(); - } - - // try { - // expect(await wsUpdatePromise).toStrictEqual('asdfasdf'); - // } catch (e) { - // // no data - // expect(e).toBeFalsy(); - // } - }); -}); diff --git a/test/unified-margin/ws.public.perp.usdc.test.ts b/test/unified-margin/ws.public.perp.usdc.test.ts deleted file mode 100644 index 11634f4..0000000 --- a/test/unified-margin/ws.public.perp.usdc.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Unified Margin Websocket Client (Perps - USDC)', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'unifiedPerp', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - // fullLogger - ); - // logAllEvents(wsClient); - wsClient.connectPublic(); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: expect.stringContaining('unifiedPerpUSD'), - }); - } catch (e) { - expect(e).toBeFalsy(); - } - - wsClient.closeAll(true); - }); - - // TODO: are there USDC topics? This doesn't seem to work - it.skip('should subscribe to public orderbook events through USDC connection', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - // USDT should be detected and automatically routed through the USDT connection - wsClient.subscribe('orderbook.25.BTCUSDC'); - - try { - expect(await wsResponsePromise).toMatchObject({ - op: 'subscribe', - req_id: 'orderbook.25.BTCUSDC', - success: true, - wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, - }); - } catch (e) { - // sub failed - expect(e).toBeFalsy(); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - data: { - a: expect.any(Array), - b: expect.any(Array), - s: 'BTCUSDT', - u: expect.any(Number), - }, - wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, - topic: 'orderbook.25.BTCUSDC', - ts: expect.any(Number), - type: 'snapshot', - }); - } catch (e) { - console.error('unified margin perp ws public error: ', e); - - // no data - expect(e).toBeFalsy(); - } - }); -}); diff --git a/test/unified-margin/ws.public.perp.usdt.test.ts b/test/unified-margin/ws.public.perp.usdt.test.ts deleted file mode 100644 index 34f27a3..0000000 --- a/test/unified-margin/ws.public.perp.usdt.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - WSClientConfigurableOptions, - WS_KEY_MAP, - WebsocketClient, -} from '../../src'; -import { - WS_OPEN_EVENT_PARTIAL, - fullLogger, - getSilentLogger, - logAllEvents, - waitForSocketEvent, -} from '../ws.util'; - -describe('Public Unified Margin Websocket Client (Perps - USDT)', () => { - let wsClient: WebsocketClient; - - const wsClientOptions: WSClientConfigurableOptions = { - market: 'unifiedPerp', - }; - - beforeAll(() => { - wsClient = new WebsocketClient( - wsClientOptions, - getSilentLogger('expectSuccessNoAuth') - // fullLogger - ); - // logAllEvents(wsClient); - wsClient.connectPublic(); - }); - - afterAll(() => { - wsClient.closeAll(true); - }); - - it('should open a public ws connection', async () => { - const wsOpenPromise = waitForSocketEvent(wsClient, 'open'); - try { - expect(await wsOpenPromise).toMatchObject({ - event: WS_OPEN_EVENT_PARTIAL, - wsKey: expect.stringContaining('unifiedPerpUSD'), - }); - } catch (e) { - expect(e).toBeFalsy(); - } - }); - - it('should subscribe to public orderbook events through USDT connection', async () => { - const wsResponsePromise = waitForSocketEvent(wsClient, 'response'); - const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); - - // USDT should be detected and automatically routed through the USDT connection - const topic = 'orderbook.1.BTCUSDT'; - wsClient.subscribe(topic); - - try { - expect(await wsResponsePromise).toMatchObject({ - op: 'subscribe', - req_id: topic, - success: true, - wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, - }); - } catch (e) { - // sub failed - expect(e).toBeFalsy(); - } - - try { - expect(await wsUpdatePromise).toMatchObject({ - data: { - a: expect.any(Array), - b: expect.any(Array), - s: 'BTCUSDT', - u: expect.any(Number), - }, - topic: topic, - ts: expect.any(Number), - wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, - type: 'snapshot', - }); - } catch (e) { - console.error('unified margin perp usdt orderbook test fail', e); - // no data - expect(e).toBeFalsy(); - } - }); -}); diff --git a/test/ws.util.ts b/test/ws.util.ts index 6d134bb..dd800d5 100644 --- a/test/ws.util.ts +++ b/test/ws.util.ts @@ -31,13 +31,13 @@ export const WS_OPEN_EVENT_PARTIAL = { export function waitForSocketEvent( wsClient: WebsocketClient, event: WsClientEvent, - timeoutMs: number = 4.5 * 1000 + timeoutMs: number = 4.5 * 1000, ) { return new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject( // eslint-disable-next-line max-len - `Failed to receive "${event}" event before timeout. Check that these are correct: topic, api keys (if private), signature process (if private)` + `Failed to receive "${event}" event before timeout. Check that these are correct: topic, api keys (if private), signature process (if private)`, ); }, timeoutMs);