deprecate redundant repeated constructors

This commit is contained in:
tiagosiebler
2022-09-08 14:31:03 +01:00
parent 88bd4fd9af
commit 666720b27d
7 changed files with 56 additions and 196 deletions

View File

@@ -1,4 +1,3 @@
import { AxiosRequestConfig } from 'axios';
import {
AccountAssetInformationRequest,
APIResponseWithTime,
@@ -12,39 +11,15 @@ import {
WithdrawalRecordsRequest,
WithdrawalRequest,
} from './types';
import {
RestClientOptions,
getRestBaseUrl,
REST_CLIENT_TYPE_ENUM,
} from './util';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
export class AccountAssetClient extends BaseRestClient {
/**
* @public Creates an instance of the Account Asset REST API client.
*
* @param {string} key - your API key
* @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
* REST API client for Account Asset APIs
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.accountAsset
);
return this;
export class AccountAssetClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.accountAsset;
}
async fetchServerTime(): Promise<number> {

View File

@@ -1,9 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import {
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
} from './util';
import { REST_CLIENT_TYPE_ENUM } from './util';
import {
APIResponseWithTime,
AssetExchangeRecordsReq,
@@ -18,32 +13,12 @@ import {
} from './types';
import BaseRestClient from './util/BaseRestClient';
export class InverseClient extends BaseRestClient {
/**
* @public Creates an instance of the inverse REST API client.
*
* @param {string} key - your API key
* @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
* REST API client for Inverse Perpetual Futures APIs (v2)
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.inverse
);
return this;
export class InverseClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.inverse;
}
async fetchServerTime(): Promise<number> {

View File

@@ -1,9 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import {
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
} from './util/requestUtils';
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
import {
APIResponseWithTime,
AssetExchangeRecordsReq,
@@ -18,32 +13,12 @@ import {
} from './types/shared';
import BaseRestClient from './util/BaseRestClient';
export class InverseFuturesClient extends BaseRestClient {
/**
* @public Creates an instance of the inverse futures REST API client.
*
* @param {string} key - your API key
* @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
* REST API client for Inverse Futures APIs (e.g. quarterly futures) (v2)
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.inverseFutures
);
return this;
export class InverseFuturesClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.inverseFutures;
}
async fetchServerTime(): Promise<number> {

View File

@@ -1,9 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import {
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
} from './util/requestUtils';
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
import {
APIResponse,
APIResponseWithTime,
@@ -25,32 +20,12 @@ import {
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
import BaseRestClient from './util/BaseRestClient';
export class LinearClient extends BaseRestClient {
/**
* @public Creates an instance of the linear (USD Perps) REST API client.
*
* @param {string} key - your API key
* @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
* REST API client for linear/USD perpetual futures APIs (v2)
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.linear
);
return this;
export class LinearClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.linear;
}
async fetchServerTime(): Promise<number> {

View File

@@ -1,4 +1,3 @@
import { AxiosRequestConfig } from 'axios';
import {
NewSpotOrder,
APIResponse,
@@ -11,40 +10,14 @@ import {
SpotSymbolInfo,
} from './types';
import BaseRestClient from './util/BaseRestClient';
import {
agentSource,
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
} from './util/requestUtils';
import { agentSource, REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
export class SpotClient extends BaseRestClient {
/**
* @public Creates an instance of the Spot REST API client.
*
* @param {string} key - your API key
* @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
* REST API client for Spot APIs (v1)
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.spot
);
return this;
export class SpotClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.spot;
}
fetchServerTime(): Promise<number> {

View File

@@ -1,38 +1,13 @@
import { AxiosRequestConfig } from 'axios';
import { APIResponseWithTime } from './types';
import {
RestClientOptions,
getRestBaseUrl,
REST_CLIENT_TYPE_ENUM,
} from './util';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
export class USDCOptionsClient extends BaseRestClient {
/**
* @public Creates an instance of the USDC Options REST API client.
*
* @param {string} key - your API key
* @param {string} secret - your API secret
* @param {boolean} [useLivenet=false] uses testnet by default
* @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
* REST API client for USDC Options APIs
*/
constructor(
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {}
) {
super(
key,
secret,
getRestBaseUrl(useLivenet, restClientOptions),
restClientOptions,
requestOptions,
REST_CLIENT_TYPE_ENUM.usdcOptions
);
return this;
export class USDCOptionsClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.usdcOptions;
}
async fetchServerTime(): Promise<number> {

View File

@@ -7,6 +7,7 @@ import {
RestClientType,
REST_CLIENT_TYPE_ENUM,
agentSource,
getRestBaseUrl,
} from './requestUtils';
// axios.interceptors.request.use((request) => {
@@ -53,21 +54,32 @@ export default abstract class BaseRestClient {
private secret: string | undefined;
private clientType: RestClientType;
/** Function that calls exchange API to query & resolve server time, used by time sync */
/** Function that calls exchange API to query & resolve server time, used by time sync, disabled by default */
abstract fetchServerTime(): Promise<number>;
/** Defines the client type (affecting how requests & signatures behave) */
abstract getClientType(): RestClientType;
/**
* Create an instance of the REST client
* @param {string} key - your API key
* @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
*/
constructor(
key: string | undefined,
secret: string | undefined,
baseUrl: string,
key?: string | undefined,
secret?: string | undefined,
useLivenet: boolean = false,
options: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {},
clientType: RestClientType
requestOptions: AxiosRequestConfig = {}
) {
const baseUrl = getRestBaseUrl(useLivenet, options);
this.timeOffset = null;
this.syncTimePromise = null;
this.clientType = clientType;
this.clientType = this.getClientType();
this.options = {
recv_window: 5000,
@@ -86,7 +98,7 @@ export default abstract class BaseRestClient {
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config
...requestOptions,
headers: {
'x-referer': 'bybitapinode',
'x-referer': agentSource,
},
};