From d3fa937cdf7f98de7fa097ab3db9a5622273efa8 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Mon, 19 Sep 2022 23:48:35 +0100 Subject: [PATCH] refactor tests for new constructor pattern --- README.md | 5 ++-- examples/rest-spot-public.ts | 6 ++-- src/util/BaseRestClient.ts | 34 +++++++++------------- src/util/requestUtils.ts | 18 +++++++++--- src/websocket-client.ts | 32 +++++++------------- test/account-asset/private.read.test.ts | 7 +++-- test/account-asset/public.read.test.ts | 7 +++-- test/copy-trading/private.read.test.ts | 7 +++-- test/copy-trading/public.read.test.ts | 7 +++-- test/inverse-futures/private.read.test.ts | 7 +++-- test/inverse-futures/private.write.test.ts | 7 +++-- test/inverse-futures/public.test.ts | 3 +- test/inverse/private.read.test.ts | 7 +++-- test/inverse/private.write.test.ts | 7 +++-- test/inverse/public.test.ts | 3 +- test/linear/private.read.test.ts | 7 +++-- test/linear/private.write.test.ts | 7 +++-- test/spot/private.v1.read.test.ts | 7 +++-- test/spot/private.v1.write.test.ts | 7 +++-- test/spot/private.v3.read.test.ts | 7 +++-- test/spot/private.v3.write.test.ts | 7 +++-- test/unified-margin/private.read.test.ts | 7 +++-- test/unified-margin/private.write.test.ts | 7 +++-- test/unified-margin/public.read.test.ts | 7 +++-- test/usdc/options/private.read.test.ts | 7 +++-- test/usdc/options/private.write.test.ts | 7 +++-- test/usdc/options/public.read.test.ts | 7 +++-- test/usdc/perpetual/private.read.test.ts | 7 +++-- test/usdc/perpetual/private.write.test.ts | 7 +++-- test/usdc/perpetual/public.read.test.ts | 7 +++-- 30 files changed, 160 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index 8727a4d..b6102f6 100644 --- a/README.md +++ b/README.md @@ -240,10 +240,9 @@ ws.on('close', () => { console.log('connection closed'); }); -// Optional: Listen to raw error events. -// Note: responses to invalid topics are currently only sent in the "response" event. +// Optional: Listen to raw error events. Recommended. ws.on('error', err => { - console.error('ERR', err); + console.error('error', err); }); ``` diff --git a/examples/rest-spot-public.ts b/examples/rest-spot-public.ts index 151d71d..cfbe950 100644 --- a/examples/rest-spot-public.ts +++ b/examples/rest-spot-public.ts @@ -1,9 +1,9 @@ -import { SpotClient } from '../src/index'; +import { SpotClientV3 } from '../src/index'; // or -// import { SpotClient } from 'bybit-api'; +// import { SpotClientV3 } from 'bybit-api'; -const client = new SpotClient(); +const client = new SpotClientV3(); const symbol = 'BTCUSDT'; diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 9141dab..c9a7328 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -24,7 +24,7 @@ interface SignedRequestContext { timestamp?: number; api_key?: string; recv_window?: number; - // spot is diff from the rest... + // spot v1 is diff from the rest... recvWindow?: number; } @@ -45,8 +45,8 @@ interface UnsignedRequest { type SignMethod = 'keyInBody' | 'usdc'; export default abstract class BaseRestClient { - private timeOffset: number | null; - private syncTimePromise: null | Promise; + private timeOffset: number | null = null; + private syncTimePromise: null | Promise = null; private options: RestClientOptions; private baseUrl: string; private globalRequestOptions: AxiosRequestConfig; @@ -66,19 +66,12 @@ export default abstract class BaseRestClient { * @param {string} secret - your API secret * @param {boolean} [useLivenet=false] * @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity - * @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios + * @param {AxiosRequestConfig} [networkOptions={}] HTTP networking options for axios */ constructor( - key?: string | undefined, - secret?: string | undefined, - useLivenet: boolean = false, - options: RestClientOptions = {}, - requestOptions: AxiosRequestConfig = {} + restOptions: RestClientOptions = {}, + networkOptions: AxiosRequestConfig = {} ) { - const baseUrl = getRestBaseUrl(useLivenet, options); - this.timeOffset = null; - this.syncTimePromise = null; - this.clientType = this.getClientType(); this.options = { @@ -89,24 +82,26 @@ export default abstract class BaseRestClient { enable_time_sync: false, /** How often to sync time drift with bybit servers (if time sync is enabled) */ sync_interval_ms: 3600000, - ...options, + ...restOptions, }; this.globalRequestOptions = { // in ms == 5 minutes by default timeout: 1000 * 60 * 5, // custom request options based on axios specs - see: https://github.com/axios/axios#request-config - ...requestOptions, + ...networkOptions, headers: { 'x-referer': APIID, }, }; - this.baseUrl = baseUrl; + this.baseUrl = getRestBaseUrl(!!this.options.testnet, restOptions); + this.key = this.options.key; + this.secret = this.options.secret; - if (key && !secret) { + if (this.key && !this.secret) { throw new Error( - 'API Key & Secret are both required for private enpoints' + 'API Key & Secret are both required for private endpoints' ); } @@ -114,9 +109,6 @@ export default abstract class BaseRestClient { this.syncTime(); setInterval(this.syncTime.bind(this), +this.options.sync_interval_ms!); } - - this.key = key; - this.secret = secret; } private isSpotClient() { diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index fde95a0..aa26be4 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -1,4 +1,13 @@ export interface RestClientOptions { + /** Your API key */ + key?: string; + + /** Your API secret */ + secret?: string; + + /** Set to `true` to connect to testnet. Uses the live environment by default. */ + testnet?: boolean; + /** Override the max size of the request window (in ms) */ recv_window?: number; @@ -43,7 +52,7 @@ export function serializeParams( } export function getRestBaseUrl( - useLivenet: boolean, + useTestnet: boolean, restInverseOptions: RestClientOptions ): string { const exchangeBaseUrls = { @@ -55,10 +64,11 @@ export function getRestBaseUrl( return restInverseOptions.baseUrl; } - if (useLivenet === true) { - return exchangeBaseUrls.livenet; + if (useTestnet) { + return exchangeBaseUrls.testnet; } - return exchangeBaseUrls.testnet; + + return exchangeBaseUrls.livenet; } export function isWsPong(msg: any): boolean { diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 062dae2..3905a21 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -47,12 +47,19 @@ export type WsClientEvent = | 'response'; interface WebsocketClientEvents { + /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */ open: (evt: { wsKey: WsKey; event: any }) => void; + /** Reconnecting a dropped connection */ reconnect: (evt: { wsKey: WsKey; event: any }) => void; + /** Successfully reconnected a connection that dropped */ reconnected: (evt: { wsKey: WsKey; event: any }) => void; + /** Connection closed */ close: (evt: { wsKey: WsKey; event: any }) => void; + /** Received reply to websocket command (e.g. after subscribing to topics) */ response: (response: any) => void; + /** Received data for topic */ update: (response: any) => void; + /** Exception from ws client OR custom listeners */ error: (response: any) => void; } @@ -92,6 +99,10 @@ export class WebsocketClient extends EventEmitter { fetchTimeOffsetBeforeAuth: false, ...options, }; + this.options.restOptions = { + ...this.options.restOptions, + testnet: this.options.testnet, + }; this.prepareRESTClient(); } @@ -105,9 +116,6 @@ export class WebsocketClient extends EventEmitter { switch (this.options.market) { case 'inverse': { this.restClient = new InverseClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -115,9 +123,6 @@ export class WebsocketClient extends EventEmitter { } case 'linear': { this.restClient = new LinearClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -125,9 +130,6 @@ export class WebsocketClient extends EventEmitter { } case 'spot': { this.restClient = new SpotClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -136,9 +138,6 @@ export class WebsocketClient extends EventEmitter { } case 'spotv3': { this.restClient = new SpotClientV3( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -146,9 +145,6 @@ export class WebsocketClient extends EventEmitter { } case 'usdcOption': { this.restClient = new USDCOptionClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -156,9 +152,6 @@ export class WebsocketClient extends EventEmitter { } case 'usdcPerp': { this.restClient = new USDCPerpetualClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); @@ -167,9 +160,6 @@ export class WebsocketClient extends EventEmitter { case 'unifiedOption': case 'unifiedPerp': { this.restClient = new UnifiedMarginClient( - undefined, - undefined, - !this.isTestnet(), this.options.restOptions, this.options.requestOptions ); diff --git a/test/account-asset/private.read.test.ts b/test/account-asset/private.read.test.ts index 36f1458..16d97cd 100644 --- a/test/account-asset/private.read.test.ts +++ b/test/account-asset/private.read.test.ts @@ -2,7 +2,6 @@ import { AccountAssetClient } from '../../src/'; import { successResponseObject } from '../response.util'; describe('Private Account Asset REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Account Asset REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new AccountAssetClient(API_KEY, API_SECRET, useLivenet); + const api = new AccountAssetClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); it('getInternalTransfers()', async () => { expect(await api.getInternalTransfers()).toMatchObject( diff --git a/test/account-asset/public.read.test.ts b/test/account-asset/public.read.test.ts index e6e9f0b..d98cd9a 100644 --- a/test/account-asset/public.read.test.ts +++ b/test/account-asset/public.read.test.ts @@ -2,11 +2,14 @@ import { AccountAssetClient } from '../../src'; import { successResponseObject } from '../response.util'; describe('Public Account Asset REST API Endpoints', () => { - const useLivenet = true; const API_KEY = undefined; const API_SECRET = undefined; - const api = new AccountAssetClient(API_KEY, API_SECRET, useLivenet); + const api = new AccountAssetClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); it('getSupportedDepositList()', async () => { expect(await api.getSupportedDepositList()).toMatchObject( diff --git a/test/copy-trading/private.read.test.ts b/test/copy-trading/private.read.test.ts index d0637ea..3579ddb 100644 --- a/test/copy-trading/private.read.test.ts +++ b/test/copy-trading/private.read.test.ts @@ -1,7 +1,6 @@ import { API_ERROR_CODE, CopyTradingClient } from '../../src'; describe('Private Copy Trading REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -10,7 +9,11 @@ describe('Private Copy Trading REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new CopyTradingClient(API_KEY, API_SECRET, useLivenet); + const api = new CopyTradingClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); // 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) diff --git a/test/copy-trading/public.read.test.ts b/test/copy-trading/public.read.test.ts index 8e5abc4..36b7f4b 100644 --- a/test/copy-trading/public.read.test.ts +++ b/test/copy-trading/public.read.test.ts @@ -2,11 +2,14 @@ import { CopyTradingClient } from '../../src'; import { successResponseObject } from '../response.util'; describe('Public Copy Trading REST API Endpoints', () => { - const useLivenet = true; const API_KEY = undefined; const API_SECRET = undefined; - const api = new CopyTradingClient(API_KEY, API_SECRET, useLivenet); + const api = new CopyTradingClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); it('getSymbols()', async () => { expect(await api.getSymbols()).toMatchObject({ diff --git a/test/inverse-futures/private.read.test.ts b/test/inverse-futures/private.read.test.ts index 821d82b..7df1ec0 100644 --- a/test/inverse-futures/private.read.test.ts +++ b/test/inverse-futures/private.read.test.ts @@ -2,11 +2,14 @@ import { InverseFuturesClient } from '../../src/inverse-futures-client'; import { successResponseList, successResponseObject } from '../response.util'; describe('Private Inverse-Futures REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; - const api = new InverseFuturesClient(API_KEY, API_SECRET, useLivenet); + const api = new InverseFuturesClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); // 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 = 'BTCUSDU22'; diff --git a/test/inverse-futures/private.write.test.ts b/test/inverse-futures/private.write.test.ts index d3c1cab..074d8f9 100644 --- a/test/inverse-futures/private.write.test.ts +++ b/test/inverse-futures/private.write.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, InverseFuturesClient } from '../../src'; import { successResponseObject } from '../response.util'; describe('Private Inverse-Futures REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new InverseFuturesClient(API_KEY, API_SECRET, useLivenet); + const api = new InverseFuturesClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); // 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 = 'BTCUSDU22'; diff --git a/test/inverse-futures/public.test.ts b/test/inverse-futures/public.test.ts index fd34263..bb60ea9 100644 --- a/test/inverse-futures/public.test.ts +++ b/test/inverse-futures/public.test.ts @@ -6,8 +6,7 @@ import { } from '../response.util'; describe('Public Inverse-Futures REST API Endpoints', () => { - const useLivenet = true; - const api = new InverseFuturesClient(undefined, undefined, useLivenet); + const api = new InverseFuturesClient(); const symbol = 'BTCUSD'; const interval = '15'; diff --git a/test/inverse/private.read.test.ts b/test/inverse/private.read.test.ts index d0b9ee9..db167b8 100644 --- a/test/inverse/private.read.test.ts +++ b/test/inverse/private.read.test.ts @@ -2,7 +2,6 @@ import { InverseClient } from '../../src/'; import { successResponseList, successResponseObject } from '../response.util'; describe('Private Inverse REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Inverse REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new InverseClient(API_KEY, API_SECRET, useLivenet); + const api = new InverseClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSD'; diff --git a/test/inverse/private.write.test.ts b/test/inverse/private.write.test.ts index f667045..6b106ef 100644 --- a/test/inverse/private.write.test.ts +++ b/test/inverse/private.write.test.ts @@ -3,7 +3,6 @@ import { InverseClient } from '../../src/inverse-client'; import { successResponseObject } from '../response.util'; describe('Private Inverse REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -12,7 +11,11 @@ describe('Private Inverse REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new InverseClient(API_KEY, API_SECRET, useLivenet); + const api = new InverseClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSD'; diff --git a/test/inverse/public.test.ts b/test/inverse/public.test.ts index 310641a..fb47bb9 100644 --- a/test/inverse/public.test.ts +++ b/test/inverse/public.test.ts @@ -6,8 +6,7 @@ import { } from '../response.util'; describe('Public Inverse REST API Endpoints', () => { - const useLivenet = true; - const api = new InverseClient(undefined, undefined, useLivenet); + const api = new InverseClient(); const symbol = 'BTCUSD'; const interval = '15'; diff --git a/test/linear/private.read.test.ts b/test/linear/private.read.test.ts index 9eef850..af403ab 100644 --- a/test/linear/private.read.test.ts +++ b/test/linear/private.read.test.ts @@ -2,7 +2,6 @@ import { LinearClient } from '../../src/linear-client'; import { successResponseList, successResponseObject } from '../response.util'; describe('Private Linear REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Linear REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new LinearClient(API_KEY, API_SECRET, useLivenet); + const api = new LinearClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; diff --git a/test/linear/private.write.test.ts b/test/linear/private.write.test.ts index dd920f1..32a3919 100644 --- a/test/linear/private.write.test.ts +++ b/test/linear/private.write.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, LinearClient } from '../../src'; import { successResponseObject } from '../response.util'; describe('Private Linear REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Linear REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new LinearClient(API_KEY, API_SECRET, useLivenet); + const api = new LinearClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); // 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'; diff --git a/test/spot/private.v1.read.test.ts b/test/spot/private.v1.read.test.ts index 518e853..cbb6950 100644 --- a/test/spot/private.v1.read.test.ts +++ b/test/spot/private.v1.read.test.ts @@ -2,7 +2,6 @@ import { SpotClient } from '../../src'; import { errorResponseObject, successResponseList } from '../response.util'; describe('Private Spot REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Spot REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new SpotClient(API_KEY, API_SECRET, useLivenet); + const api = new SpotClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); it('getOrder()', async () => { // No auth error == test pass diff --git a/test/spot/private.v1.write.test.ts b/test/spot/private.v1.write.test.ts index 4b678de..fb59c7a 100644 --- a/test/spot/private.v1.write.test.ts +++ b/test/spot/private.v1.write.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, SpotClient } from '../../src'; import { successResponseObject } from '../response.util'; describe('Private Spot REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Spot REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new SpotClient(API_KEY, API_SECRET, useLivenet); + const api = new SpotClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); // 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'; diff --git a/test/spot/private.v3.read.test.ts b/test/spot/private.v3.read.test.ts index 949bf0f..6db17ae 100644 --- a/test/spot/private.v3.read.test.ts +++ b/test/spot/private.v3.read.test.ts @@ -6,7 +6,6 @@ import { } from '../response.util'; describe('Private Spot REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -15,7 +14,11 @@ describe('Private Spot REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new SpotClientV3(API_KEY, API_SECRET, useLivenet); + const api = new SpotClientV3({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; const interval = '15m'; diff --git a/test/spot/private.v3.write.test.ts b/test/spot/private.v3.write.test.ts index 95ad6e7..6e9694f 100644 --- a/test/spot/private.v3.write.test.ts +++ b/test/spot/private.v3.write.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, SpotClientV3 } from '../../src'; import { successResponseObjectV3 } from '../response.util'; describe('Private Spot REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Spot REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new SpotClientV3(API_KEY, API_SECRET, useLivenet); + const api = new SpotClientV3({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; const ltCode = 'BTC3S'; diff --git a/test/unified-margin/private.read.test.ts b/test/unified-margin/private.read.test.ts index c5093b9..9deeced 100644 --- a/test/unified-margin/private.read.test.ts +++ b/test/unified-margin/private.read.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, UnifiedMarginClient } from '../../src'; import { successResponseObjectV3 } from '../response.util'; describe('Private Unified Margin REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private Unified Margin REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new UnifiedMarginClient(API_KEY, API_SECRET, useLivenet); + const api = new UnifiedMarginClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; const category = 'linear'; diff --git a/test/unified-margin/private.write.test.ts b/test/unified-margin/private.write.test.ts index 3e8d297..f0cb47f 100644 --- a/test/unified-margin/private.write.test.ts +++ b/test/unified-margin/private.write.test.ts @@ -1,7 +1,6 @@ import { API_ERROR_CODE, UnifiedMarginClient } from '../../src'; describe('Private Unified Margin REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -10,7 +9,11 @@ describe('Private Unified Margin REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new UnifiedMarginClient(API_KEY, API_SECRET, useLivenet); + const api = new UnifiedMarginClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; const category = 'linear'; diff --git a/test/unified-margin/public.read.test.ts b/test/unified-margin/public.read.test.ts index 9f7843d..406e8a9 100644 --- a/test/unified-margin/public.read.test.ts +++ b/test/unified-margin/public.read.test.ts @@ -5,11 +5,14 @@ import { } from '../response.util'; describe('Public Unified Margin REST API Endpoints', () => { - const useLivenet = true; const API_KEY = undefined; const API_SECRET = undefined; - const api = new UnifiedMarginClient(API_KEY, API_SECRET, useLivenet); + const api = new UnifiedMarginClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCUSDT'; const category = 'linear'; diff --git a/test/usdc/options/private.read.test.ts b/test/usdc/options/private.read.test.ts index cd31815..abdc79b 100644 --- a/test/usdc/options/private.read.test.ts +++ b/test/usdc/options/private.read.test.ts @@ -2,7 +2,6 @@ import { USDCOptionClient } from '../../../src'; import { successResponseObjectV3 } from '../../response.util'; describe('Private USDC Options REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; const symbol = 'BTC-30SEP22-400000-C'; @@ -12,7 +11,11 @@ describe('Private USDC Options REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new USDCOptionClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCOptionClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const category = 'OPTION'; it('getActiveRealtimeOrders()', async () => { diff --git a/test/usdc/options/private.write.test.ts b/test/usdc/options/private.write.test.ts index 5bd48a7..442aa20 100644 --- a/test/usdc/options/private.write.test.ts +++ b/test/usdc/options/private.write.test.ts @@ -2,7 +2,6 @@ import { API_ERROR_CODE, USDCOptionClient } from '../../../src'; import { successResponseObjectV3 } from '../../response.util'; describe('Private USDC Options REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private USDC Options REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new USDCOptionClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCOptionClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const currency = 'USDC'; const symbol = 'BTC-30SEP22-400000-C'; diff --git a/test/usdc/options/public.read.test.ts b/test/usdc/options/public.read.test.ts index 891082c..46536cc 100644 --- a/test/usdc/options/public.read.test.ts +++ b/test/usdc/options/public.read.test.ts @@ -5,11 +5,14 @@ import { } from '../../response.util'; describe('Public USDC Options REST API Endpoints', () => { - const useLivenet = true; const API_KEY = undefined; const API_SECRET = undefined; - const api = new USDCOptionClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCOptionClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTC-30SEP22-400000-C'; it('getOrderBook()', async () => { diff --git a/test/usdc/perpetual/private.read.test.ts b/test/usdc/perpetual/private.read.test.ts index 876aeac..ea565f2 100644 --- a/test/usdc/perpetual/private.read.test.ts +++ b/test/usdc/perpetual/private.read.test.ts @@ -2,7 +2,6 @@ import { USDCPerpetualClient } from '../../../src'; import { successResponseObjectV3 } from '../../response.util'; describe('Private USDC Perp REST API GET Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -11,7 +10,11 @@ describe('Private USDC Perp REST API GET Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new USDCPerpetualClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCPerpetualClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCPERP'; const category = 'PERPETUAL'; diff --git a/test/usdc/perpetual/private.write.test.ts b/test/usdc/perpetual/private.write.test.ts index 9401a37..ef13efc 100644 --- a/test/usdc/perpetual/private.write.test.ts +++ b/test/usdc/perpetual/private.write.test.ts @@ -5,7 +5,6 @@ import { } from '../../response.util'; describe('Private USDC Perp REST API POST Endpoints', () => { - const useLivenet = true; const API_KEY = process.env.API_KEY_COM; const API_SECRET = process.env.API_SECRET_COM; @@ -14,7 +13,11 @@ describe('Private USDC Perp REST API POST Endpoints', () => { expect(API_SECRET).toStrictEqual(expect.any(String)); }); - const api = new USDCPerpetualClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCPerpetualClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCPERP'; diff --git a/test/usdc/perpetual/public.read.test.ts b/test/usdc/perpetual/public.read.test.ts index 161c580..0eb6865 100644 --- a/test/usdc/perpetual/public.read.test.ts +++ b/test/usdc/perpetual/public.read.test.ts @@ -5,11 +5,14 @@ import { } from '../../response.util'; describe('Public USDC Perp REST API Endpoints', () => { - const useLivenet = true; const API_KEY = undefined; const API_SECRET = undefined; - const api = new USDCPerpetualClient(API_KEY, API_SECRET, useLivenet); + const api = new USDCPerpetualClient({ + key: API_KEY, + secret: API_SECRET, + testnet: false, + }); const symbol = 'BTCPERP'; const category = 'PERPETUAL';