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

@@ -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,
},
};