rename rest client options to be more generic

This commit is contained in:
tiagosiebler
2021-02-14 16:29:35 +00:00
parent 3b2af548d0
commit 26602cfa05
4 changed files with 30 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
import { AxiosRequestConfig } from 'axios'; import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, getBaseRESTInverseUrl, RestClientInverseOptions } from './util/requestUtils'; import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper'; import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints'; import SharedEndpoints from './shared-endpoints';
@@ -12,23 +12,23 @@ export class InverseClient extends SharedEndpoints {
* @param {string} key - your API key * @param {string} key - your API key
* @param {string} secret - your API secret * @param {string} secret - your API secret
* @param {boolean} [useLivenet=false] * @param {boolean} [useLivenet=false]
* @param {RestClientInverseOptions} [restInverseOptions={}] options to configure REST API connectivity * @param {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios * @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
*/ */
constructor( constructor(
key?: string | undefined, key?: string | undefined,
secret?: string | undefined, secret?: string | undefined,
useLivenet?: boolean, useLivenet?: boolean,
restInverseOptions: RestClientInverseOptions = {}, restInverseOptions: RestClientOptions = {},
httpOptions: AxiosRequestConfig = {} requestOptions: AxiosRequestConfig = {}
) { ) {
super() super()
this.requestWrapper = new RequestWrapper( this.requestWrapper = new RequestWrapper(
key, key,
secret, secret,
getBaseRESTInverseUrl(useLivenet), getRestBaseUrl(useLivenet),
restInverseOptions, restInverseOptions,
httpOptions requestOptions
); );
return this; return this;
} }

View File

@@ -1,5 +1,5 @@
import { AxiosRequestConfig } from 'axios'; import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, getBaseRESTInverseUrl, RestClientInverseOptions } from './util/requestUtils'; import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper'; import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints'; import SharedEndpoints from './shared-endpoints';
@@ -11,23 +11,22 @@ export class LinearClient extends SharedEndpoints {
* *
* @param {string} key - your API key * @param {string} key - your API key
* @param {string} secret - your API secret * @param {string} secret - your API secret
* @param {boolean} [livenet=false] * @param {boolean} [useLivenet=false]
* @param {RestClientInverseOptions} [restInverseOptions={}] options to configure REST API connectivity * @param {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios * @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
*/ */
constructor( constructor(
key?: string | undefined, key?: string | undefined,
secret?: string | undefined, secret?: string | undefined,
livenet?: boolean, useLivenet?: boolean,
restInverseOptions:RestClientInverseOptions = {}, // TODO: Rename this type to be more general. restInverseOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {} requestOptions: AxiosRequestConfig = {}
) { ) {
super() super()
this.requestWrapper = new RequestWrapper( this.requestWrapper = new RequestWrapper(
key, key,
secret, secret,
getBaseRESTInverseUrl(livenet), getRestBaseUrl(useLivenet),
restInverseOptions, restInverseOptions,
requestOptions requestOptions
); );
@@ -46,7 +45,7 @@ export class LinearClient extends SharedEndpoints {
from: number; from: number;
limit?: number; limit?: number;
}): GenericAPIResponse { }): GenericAPIResponse {
return this.requestWrapper.get('/public/linear/kline', params); return this.requestWrapper.get('public/linear/kline', params);
} }
/** /**

View File

@@ -1,6 +1,6 @@
import { createHmac } from 'crypto'; import { createHmac } from 'crypto';
export interface RestClientInverseOptions { export interface RestClientOptions {
// 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;
@@ -42,7 +42,7 @@ export function serializeParams(params: object = {}, strict_validation = false):
.join('&'); .join('&');
}; };
export function getBaseRESTInverseUrl(useLivenet?: boolean, restInverseOptions?: RestClientInverseOptions) { export function getRestBaseUrl(useLivenet?: boolean, restInverseOptions?: RestClientOptions) {
const baseUrlsInverse = { const baseUrlsInverse = {
livenet: 'https://api.bybit.com', livenet: 'https://api.bybit.com',
testnet: 'https://api-testnet.bybit.com' testnet: 'https://api-testnet.bybit.com'

View File

@@ -1,11 +1,11 @@
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import { signMessage, serializeParams, RestClientInverseOptions, GenericAPIResponse, isPublicEndpoint } from './requestUtils'; import { signMessage, serializeParams, RestClientOptions, GenericAPIResponse, isPublicEndpoint } from './requestUtils';
export default class RequestUtil { export default class RequestUtil {
private timeOffset: number | null; private timeOffset: number | null;
private syncTimePromise: null | Promise<any>; private syncTimePromise: null | Promise<any>;
private options: RestClientInverseOptions; private options: RestClientOptions;
private baseUrl: string; private baseUrl: string;
private globalRequestOptions: AxiosRequestConfig; private globalRequestOptions: AxiosRequestConfig;
private key: string | undefined; private key: string | undefined;
@@ -15,7 +15,7 @@ export default class RequestUtil {
key: string | undefined, key: string | undefined,
secret: string | undefined, secret: string | undefined,
baseUrl: string, baseUrl: string,
options: RestClientInverseOptions = {}, options: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {} requestOptions: AxiosRequestConfig = {}
) { ) {
this.timeOffset = null; this.timeOffset = null;