deprecate redundant repeated constructors
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
|
||||||
import {
|
import {
|
||||||
AccountAssetInformationRequest,
|
AccountAssetInformationRequest,
|
||||||
APIResponseWithTime,
|
APIResponseWithTime,
|
||||||
@@ -12,39 +11,15 @@ import {
|
|||||||
WithdrawalRecordsRequest,
|
WithdrawalRecordsRequest,
|
||||||
WithdrawalRequest,
|
WithdrawalRequest,
|
||||||
} from './types';
|
} from './types';
|
||||||
import {
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
RestClientOptions,
|
|
||||||
getRestBaseUrl,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util';
|
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
|
|
||||||
export class AccountAssetClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the Account Asset REST API client.
|
* REST API client for Account Asset APIs
|
||||||
*
|
|
||||||
* @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(
|
export class AccountAssetClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.accountAsset;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.accountAsset
|
|
||||||
);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
import {
|
|
||||||
getRestBaseUrl,
|
|
||||||
RestClientOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util';
|
|
||||||
import {
|
import {
|
||||||
APIResponseWithTime,
|
APIResponseWithTime,
|
||||||
AssetExchangeRecordsReq,
|
AssetExchangeRecordsReq,
|
||||||
@@ -18,32 +13,12 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
|
|
||||||
export class InverseClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the inverse REST API client.
|
* REST API client for Inverse Perpetual Futures APIs (v2)
|
||||||
*
|
|
||||||
* @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(
|
export class InverseClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.inverse;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.inverse
|
|
||||||
);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
|
||||||
import {
|
|
||||||
getRestBaseUrl,
|
|
||||||
RestClientOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util/requestUtils';
|
|
||||||
import {
|
import {
|
||||||
APIResponseWithTime,
|
APIResponseWithTime,
|
||||||
AssetExchangeRecordsReq,
|
AssetExchangeRecordsReq,
|
||||||
@@ -18,32 +13,12 @@ import {
|
|||||||
} from './types/shared';
|
} from './types/shared';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
|
|
||||||
export class InverseFuturesClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the inverse futures REST API client.
|
* REST API client for Inverse Futures APIs (e.g. quarterly futures) (v2)
|
||||||
*
|
|
||||||
* @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(
|
export class InverseFuturesClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.inverseFutures;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.inverseFutures
|
|
||||||
);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
|
||||||
import {
|
|
||||||
getRestBaseUrl,
|
|
||||||
RestClientOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util/requestUtils';
|
|
||||||
import {
|
import {
|
||||||
APIResponse,
|
APIResponse,
|
||||||
APIResponseWithTime,
|
APIResponseWithTime,
|
||||||
@@ -25,32 +20,12 @@ import {
|
|||||||
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
|
import { linearPositionModeEnum, positionTpSlModeEnum } from './constants/enum';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
|
|
||||||
export class LinearClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the linear (USD Perps) REST API client.
|
* REST API client for linear/USD perpetual futures APIs (v2)
|
||||||
*
|
|
||||||
* @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(
|
export class LinearClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.linear;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.linear
|
|
||||||
);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
|
||||||
import {
|
import {
|
||||||
NewSpotOrder,
|
NewSpotOrder,
|
||||||
APIResponse,
|
APIResponse,
|
||||||
@@ -11,40 +10,14 @@ import {
|
|||||||
SpotSymbolInfo,
|
SpotSymbolInfo,
|
||||||
} from './types';
|
} from './types';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
import {
|
import { agentSource, REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
|
||||||
agentSource,
|
|
||||||
getRestBaseUrl,
|
|
||||||
RestClientOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util/requestUtils';
|
|
||||||
|
|
||||||
export class SpotClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the Spot REST API client.
|
* REST API client for Spot APIs (v1)
|
||||||
*
|
|
||||||
* @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(
|
export class SpotClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.spot;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.spot
|
|
||||||
);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchServerTime(): Promise<number> {
|
fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -1,38 +1,13 @@
|
|||||||
import { AxiosRequestConfig } from 'axios';
|
|
||||||
import { APIResponseWithTime } from './types';
|
import { APIResponseWithTime } from './types';
|
||||||
import {
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
RestClientOptions,
|
|
||||||
getRestBaseUrl,
|
|
||||||
REST_CLIENT_TYPE_ENUM,
|
|
||||||
} from './util';
|
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
|
|
||||||
export class USDCOptionsClient extends BaseRestClient {
|
|
||||||
/**
|
/**
|
||||||
* @public Creates an instance of the USDC Options REST API client.
|
* REST API client for USDC Options APIs
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
export class USDCOptionsClient extends BaseRestClient {
|
||||||
key?: string | undefined,
|
getClientType() {
|
||||||
secret?: string | undefined,
|
return REST_CLIENT_TYPE_ENUM.usdcOptions;
|
||||||
useLivenet: boolean = false,
|
|
||||||
restClientOptions: RestClientOptions = {},
|
|
||||||
requestOptions: AxiosRequestConfig = {}
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
key,
|
|
||||||
secret,
|
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
|
||||||
restClientOptions,
|
|
||||||
requestOptions,
|
|
||||||
REST_CLIENT_TYPE_ENUM.usdcOptions
|
|
||||||
);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
RestClientType,
|
RestClientType,
|
||||||
REST_CLIENT_TYPE_ENUM,
|
REST_CLIENT_TYPE_ENUM,
|
||||||
agentSource,
|
agentSource,
|
||||||
|
getRestBaseUrl,
|
||||||
} from './requestUtils';
|
} from './requestUtils';
|
||||||
|
|
||||||
// axios.interceptors.request.use((request) => {
|
// axios.interceptors.request.use((request) => {
|
||||||
@@ -53,21 +54,32 @@ export default abstract class BaseRestClient {
|
|||||||
private secret: string | undefined;
|
private secret: string | undefined;
|
||||||
private clientType: RestClientType;
|
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>;
|
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(
|
constructor(
|
||||||
key: string | undefined,
|
key?: string | undefined,
|
||||||
secret: string | undefined,
|
secret?: string | undefined,
|
||||||
baseUrl: string,
|
useLivenet: boolean = false,
|
||||||
options: RestClientOptions = {},
|
options: RestClientOptions = {},
|
||||||
requestOptions: AxiosRequestConfig = {},
|
requestOptions: AxiosRequestConfig = {}
|
||||||
clientType: RestClientType
|
|
||||||
) {
|
) {
|
||||||
|
const baseUrl = getRestBaseUrl(useLivenet, options);
|
||||||
this.timeOffset = null;
|
this.timeOffset = null;
|
||||||
this.syncTimePromise = null;
|
this.syncTimePromise = null;
|
||||||
|
|
||||||
this.clientType = clientType;
|
this.clientType = this.getClientType();
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
recv_window: 5000,
|
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
|
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config
|
||||||
...requestOptions,
|
...requestOptions,
|
||||||
headers: {
|
headers: {
|
||||||
'x-referer': 'bybitapinode',
|
'x-referer': agentSource,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user