refactor tests for new constructor pattern

This commit is contained in:
tiagosiebler
2022-09-19 23:48:35 +01:00
parent f7d59b48c1
commit d3fa937cdf
30 changed files with 160 additions and 102 deletions

View File

@@ -240,10 +240,9 @@ ws.on('close', () => {
console.log('connection closed'); console.log('connection closed');
}); });
// Optional: Listen to raw error events. // Optional: Listen to raw error events. Recommended.
// Note: responses to invalid topics are currently only sent in the "response" event.
ws.on('error', err => { ws.on('error', err => {
console.error('ERR', err); console.error('error', err);
}); });
``` ```

View File

@@ -1,9 +1,9 @@
import { SpotClient } from '../src/index'; import { SpotClientV3 } from '../src/index';
// or // or
// import { SpotClient } from 'bybit-api'; // import { SpotClientV3 } from 'bybit-api';
const client = new SpotClient(); const client = new SpotClientV3();
const symbol = 'BTCUSDT'; const symbol = 'BTCUSDT';

View File

@@ -24,7 +24,7 @@ interface SignedRequestContext {
timestamp?: number; timestamp?: number;
api_key?: string; api_key?: string;
recv_window?: number; recv_window?: number;
// spot is diff from the rest... // spot v1 is diff from the rest...
recvWindow?: number; recvWindow?: number;
} }
@@ -45,8 +45,8 @@ interface UnsignedRequest<T> {
type SignMethod = 'keyInBody' | 'usdc'; type SignMethod = 'keyInBody' | 'usdc';
export default abstract class BaseRestClient { export default abstract class BaseRestClient {
private timeOffset: number | null; private timeOffset: number | null = null;
private syncTimePromise: null | Promise<any>; private syncTimePromise: null | Promise<any> = null;
private options: RestClientOptions; private options: RestClientOptions;
private baseUrl: string; private baseUrl: string;
private globalRequestOptions: AxiosRequestConfig; private globalRequestOptions: AxiosRequestConfig;
@@ -66,19 +66,12 @@ export default abstract class BaseRestClient {
* @param {string} secret - your API secret * @param {string} secret - your API secret
* @param {boolean} [useLivenet=false] * @param {boolean} [useLivenet=false]
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity * @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( constructor(
key?: string | undefined, restOptions: RestClientOptions = {},
secret?: string | undefined, networkOptions: AxiosRequestConfig = {}
useLivenet: boolean = false,
options: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) { ) {
const baseUrl = getRestBaseUrl(useLivenet, options);
this.timeOffset = null;
this.syncTimePromise = null;
this.clientType = this.getClientType(); this.clientType = this.getClientType();
this.options = { this.options = {
@@ -89,24 +82,26 @@ export default abstract class BaseRestClient {
enable_time_sync: false, enable_time_sync: false,
/** How often to sync time drift with bybit servers (if time sync is enabled) */ /** How often to sync time drift with bybit servers (if time sync is enabled) */
sync_interval_ms: 3600000, sync_interval_ms: 3600000,
...options, ...restOptions,
}; };
this.globalRequestOptions = { this.globalRequestOptions = {
// in ms == 5 minutes by default // in ms == 5 minutes by default
timeout: 1000 * 60 * 5, timeout: 1000 * 60 * 5,
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config // custom request options based on axios specs - see: https://github.com/axios/axios#request-config
...requestOptions, ...networkOptions,
headers: { headers: {
'x-referer': APIID, '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( 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(); this.syncTime();
setInterval(this.syncTime.bind(this), +this.options.sync_interval_ms!); setInterval(this.syncTime.bind(this), +this.options.sync_interval_ms!);
} }
this.key = key;
this.secret = secret;
} }
private isSpotClient() { private isSpotClient() {

View File

@@ -1,4 +1,13 @@
export interface RestClientOptions { 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) */ /** Override the max size of the request window (in ms) */
recv_window?: number; recv_window?: number;
@@ -43,7 +52,7 @@ export function serializeParams(
} }
export function getRestBaseUrl( export function getRestBaseUrl(
useLivenet: boolean, useTestnet: boolean,
restInverseOptions: RestClientOptions restInverseOptions: RestClientOptions
): string { ): string {
const exchangeBaseUrls = { const exchangeBaseUrls = {
@@ -55,12 +64,13 @@ export function getRestBaseUrl(
return restInverseOptions.baseUrl; return restInverseOptions.baseUrl;
} }
if (useLivenet === true) { if (useTestnet) {
return exchangeBaseUrls.livenet;
}
return exchangeBaseUrls.testnet; return exchangeBaseUrls.testnet;
} }
return exchangeBaseUrls.livenet;
}
export function isWsPong(msg: any): boolean { export function isWsPong(msg: any): boolean {
if (!msg) { if (!msg) {
return false; return false;

View File

@@ -47,12 +47,19 @@ export type WsClientEvent =
| 'response'; | 'response';
interface WebsocketClientEvents { interface WebsocketClientEvents {
/** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
open: (evt: { wsKey: WsKey; event: any }) => void; open: (evt: { wsKey: WsKey; event: any }) => void;
/** Reconnecting a dropped connection */
reconnect: (evt: { wsKey: WsKey; event: any }) => void; reconnect: (evt: { wsKey: WsKey; event: any }) => void;
/** Successfully reconnected a connection that dropped */
reconnected: (evt: { wsKey: WsKey; event: any }) => void; reconnected: (evt: { wsKey: WsKey; event: any }) => void;
/** Connection closed */
close: (evt: { wsKey: WsKey; event: any }) => void; close: (evt: { wsKey: WsKey; event: any }) => void;
/** Received reply to websocket command (e.g. after subscribing to topics) */
response: (response: any) => void; response: (response: any) => void;
/** Received data for topic */
update: (response: any) => void; update: (response: any) => void;
/** Exception from ws client OR custom listeners */
error: (response: any) => void; error: (response: any) => void;
} }
@@ -92,6 +99,10 @@ export class WebsocketClient extends EventEmitter {
fetchTimeOffsetBeforeAuth: false, fetchTimeOffsetBeforeAuth: false,
...options, ...options,
}; };
this.options.restOptions = {
...this.options.restOptions,
testnet: this.options.testnet,
};
this.prepareRESTClient(); this.prepareRESTClient();
} }
@@ -105,9 +116,6 @@ export class WebsocketClient extends EventEmitter {
switch (this.options.market) { switch (this.options.market) {
case 'inverse': { case 'inverse': {
this.restClient = new InverseClient( this.restClient = new InverseClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -115,9 +123,6 @@ export class WebsocketClient extends EventEmitter {
} }
case 'linear': { case 'linear': {
this.restClient = new LinearClient( this.restClient = new LinearClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -125,9 +130,6 @@ export class WebsocketClient extends EventEmitter {
} }
case 'spot': { case 'spot': {
this.restClient = new SpotClient( this.restClient = new SpotClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -136,9 +138,6 @@ export class WebsocketClient extends EventEmitter {
} }
case 'spotv3': { case 'spotv3': {
this.restClient = new SpotClientV3( this.restClient = new SpotClientV3(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -146,9 +145,6 @@ export class WebsocketClient extends EventEmitter {
} }
case 'usdcOption': { case 'usdcOption': {
this.restClient = new USDCOptionClient( this.restClient = new USDCOptionClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -156,9 +152,6 @@ export class WebsocketClient extends EventEmitter {
} }
case 'usdcPerp': { case 'usdcPerp': {
this.restClient = new USDCPerpetualClient( this.restClient = new USDCPerpetualClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );
@@ -167,9 +160,6 @@ export class WebsocketClient extends EventEmitter {
case 'unifiedOption': case 'unifiedOption':
case 'unifiedPerp': { case 'unifiedPerp': {
this.restClient = new UnifiedMarginClient( this.restClient = new UnifiedMarginClient(
undefined,
undefined,
!this.isTestnet(),
this.options.restOptions, this.options.restOptions,
this.options.requestOptions this.options.requestOptions
); );

View File

@@ -2,7 +2,6 @@ import { AccountAssetClient } from '../../src/';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Account Asset REST API GET Endpoints', () => { describe('Private Account Asset REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 () => { it('getInternalTransfers()', async () => {
expect(await api.getInternalTransfers()).toMatchObject( expect(await api.getInternalTransfers()).toMatchObject(

View File

@@ -2,11 +2,14 @@ import { AccountAssetClient } from '../../src';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Public Account Asset REST API Endpoints', () => { describe('Public Account Asset REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined; const API_KEY = undefined;
const API_SECRET = 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 () => { it('getSupportedDepositList()', async () => {
expect(await api.getSupportedDepositList()).toMatchObject( expect(await api.getSupportedDepositList()).toMatchObject(

View File

@@ -1,7 +1,6 @@
import { API_ERROR_CODE, CopyTradingClient } from '../../src'; import { API_ERROR_CODE, CopyTradingClient } from '../../src';
describe('Private Copy Trading REST API GET Endpoints', () => { describe('Private Copy Trading REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 // 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) // (just make sure auth works and endpoint doesn't throw)

View File

@@ -2,11 +2,14 @@ import { CopyTradingClient } from '../../src';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Public Copy Trading REST API Endpoints', () => { describe('Public Copy Trading REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined; const API_KEY = undefined;
const API_SECRET = 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 () => { it('getSymbols()', async () => {
expect(await api.getSymbols()).toMatchObject({ expect(await api.getSymbols()).toMatchObject({

View File

@@ -2,11 +2,14 @@ import { InverseFuturesClient } from '../../src/inverse-futures-client';
import { successResponseList, successResponseObject } from '../response.util'; import { successResponseList, successResponseObject } from '../response.util';
describe('Private Inverse-Futures REST API GET Endpoints', () => { describe('Private Inverse-Futures REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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! // 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'; const symbol = 'BTCUSDU22';

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, InverseFuturesClient } from '../../src';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Inverse-Futures REST API POST Endpoints', () => { describe('Private Inverse-Futures REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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! // 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'; const symbol = 'BTCUSDU22';

View File

@@ -6,8 +6,7 @@ import {
} from '../response.util'; } from '../response.util';
describe('Public Inverse-Futures REST API Endpoints', () => { describe('Public Inverse-Futures REST API Endpoints', () => {
const useLivenet = true; const api = new InverseFuturesClient();
const api = new InverseFuturesClient(undefined, undefined, useLivenet);
const symbol = 'BTCUSD'; const symbol = 'BTCUSD';
const interval = '15'; const interval = '15';

View File

@@ -2,7 +2,6 @@ import { InverseClient } from '../../src/';
import { successResponseList, successResponseObject } from '../response.util'; import { successResponseList, successResponseObject } from '../response.util';
describe('Private Inverse REST API GET Endpoints', () => { describe('Private Inverse REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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'; const symbol = 'BTCUSD';

View File

@@ -3,7 +3,6 @@ import { InverseClient } from '../../src/inverse-client';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Inverse REST API POST Endpoints', () => { describe('Private Inverse REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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'; const symbol = 'BTCUSD';

View File

@@ -6,8 +6,7 @@ import {
} from '../response.util'; } from '../response.util';
describe('Public Inverse REST API Endpoints', () => { describe('Public Inverse REST API Endpoints', () => {
const useLivenet = true; const api = new InverseClient();
const api = new InverseClient(undefined, undefined, useLivenet);
const symbol = 'BTCUSD'; const symbol = 'BTCUSD';
const interval = '15'; const interval = '15';

View File

@@ -2,7 +2,6 @@ import { LinearClient } from '../../src/linear-client';
import { successResponseList, successResponseObject } from '../response.util'; import { successResponseList, successResponseObject } from '../response.util';
describe('Private Linear REST API GET Endpoints', () => { describe('Private Linear REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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'; const symbol = 'BTCUSDT';

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, LinearClient } from '../../src';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Linear REST API POST Endpoints', () => { describe('Private Linear REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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! // 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'; const symbol = 'BTCUSDT';

View File

@@ -2,7 +2,6 @@ import { SpotClient } from '../../src';
import { errorResponseObject, successResponseList } from '../response.util'; import { errorResponseObject, successResponseList } from '../response.util';
describe('Private Spot REST API GET Endpoints', () => { describe('Private Spot REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 () => { it('getOrder()', async () => {
// No auth error == test pass // No auth error == test pass

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, SpotClient } from '../../src';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Spot REST API POST Endpoints', () => { describe('Private Spot REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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! // 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'; const symbol = 'BTCUSDT';

View File

@@ -6,7 +6,6 @@ import {
} from '../response.util'; } from '../response.util';
describe('Private Spot REST API GET Endpoints', () => { describe('Private Spot REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCUSDT';
const interval = '15m'; const interval = '15m';

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, SpotClientV3 } from '../../src';
import { successResponseObjectV3 } from '../response.util'; import { successResponseObjectV3 } from '../response.util';
describe('Private Spot REST API POST Endpoints', () => { describe('Private Spot REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCUSDT';
const ltCode = 'BTC3S'; const ltCode = 'BTC3S';

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
import { successResponseObjectV3 } from '../response.util'; import { successResponseObjectV3 } from '../response.util';
describe('Private Unified Margin REST API GET Endpoints', () => { describe('Private Unified Margin REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCUSDT';
const category = 'linear'; const category = 'linear';

View File

@@ -1,7 +1,6 @@
import { API_ERROR_CODE, UnifiedMarginClient } from '../../src'; import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
describe('Private Unified Margin REST API POST Endpoints', () => { describe('Private Unified Margin REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCUSDT';
const category = 'linear'; const category = 'linear';

View File

@@ -5,11 +5,14 @@ import {
} from '../response.util'; } from '../response.util';
describe('Public Unified Margin REST API Endpoints', () => { describe('Public Unified Margin REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined; const API_KEY = undefined;
const API_SECRET = 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 symbol = 'BTCUSDT';
const category = 'linear'; const category = 'linear';

View File

@@ -2,7 +2,6 @@ import { USDCOptionClient } from '../../../src';
import { successResponseObjectV3 } from '../../response.util'; import { successResponseObjectV3 } from '../../response.util';
describe('Private USDC Options REST API GET Endpoints', () => { describe('Private USDC Options REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM; const API_SECRET = process.env.API_SECRET_COM;
const symbol = 'BTC-30SEP22-400000-C'; 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)); 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'; const category = 'OPTION';
it('getActiveRealtimeOrders()', async () => { it('getActiveRealtimeOrders()', async () => {

View File

@@ -2,7 +2,6 @@ import { API_ERROR_CODE, USDCOptionClient } from '../../../src';
import { successResponseObjectV3 } from '../../response.util'; import { successResponseObjectV3 } from '../../response.util';
describe('Private USDC Options REST API POST Endpoints', () => { describe('Private USDC Options REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 currency = 'USDC';
const symbol = 'BTC-30SEP22-400000-C'; const symbol = 'BTC-30SEP22-400000-C';

View File

@@ -5,11 +5,14 @@ import {
} from '../../response.util'; } from '../../response.util';
describe('Public USDC Options REST API Endpoints', () => { describe('Public USDC Options REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined; const API_KEY = undefined;
const API_SECRET = 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'; const symbol = 'BTC-30SEP22-400000-C';
it('getOrderBook()', async () => { it('getOrderBook()', async () => {

View File

@@ -2,7 +2,6 @@ import { USDCPerpetualClient } from '../../../src';
import { successResponseObjectV3 } from '../../response.util'; import { successResponseObjectV3 } from '../../response.util';
describe('Private USDC Perp REST API GET Endpoints', () => { describe('Private USDC Perp REST API GET Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCPERP';
const category = 'PERPETUAL'; const category = 'PERPETUAL';

View File

@@ -5,7 +5,6 @@ import {
} from '../../response.util'; } from '../../response.util';
describe('Private USDC Perp REST API POST Endpoints', () => { describe('Private USDC Perp REST API POST Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM; const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_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)); 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 symbol = 'BTCPERP';

View File

@@ -5,11 +5,14 @@ import {
} from '../../response.util'; } from '../../response.util';
describe('Public USDC Perp REST API Endpoints', () => { describe('Public USDC Perp REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined; const API_KEY = undefined;
const API_SECRET = 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 symbol = 'BTCPERP';
const category = 'PERPETUAL'; const category = 'PERPETUAL';