- Returned type improvements.

- Start migrating to base rest client.
- Remove deprecated methods.
- Run linter.
- Deprecate shared endpoints for readibility. All methods are replicated within each client (there's not much duplication).
- Expand test coverage for public inverse endpoints.
This commit is contained in:
tiagosiebler
2022-05-05 21:25:28 +01:00
parent cf9147ff60
commit 51aa7ae1f5
11 changed files with 8447 additions and 373 deletions

View File

@@ -19,25 +19,33 @@ export interface RestClientOptions {
parse_exceptions?: boolean;
}
export type GenericAPIResponse = Promise<any>;
export type GenericAPIResponse<T = any> = Promise<T>;
export function serializeParams(params: object = {}, strict_validation = false): string {
export function serializeParams(
params: object = {},
strict_validation = false
): string {
return Object.keys(params)
.sort()
.map(key => {
.map((key) => {
const value = params[key];
if (strict_validation === true && typeof value === 'undefined') {
throw new Error('Failed to sign API request due to undefined parameter');
throw new Error(
'Failed to sign API request due to undefined parameter'
);
}
return `${key}=${value}`;
})
.join('&');
};
}
export function getRestBaseUrl(useLivenet: boolean, restInverseOptions: RestClientOptions) {
export function getRestBaseUrl(
useLivenet: boolean,
restInverseOptions: RestClientOptions
) {
const baseUrlsInverse = {
livenet: 'https://api.bybit.com',
testnet: 'https://api-testnet.bybit.com'
testnet: 'https://api-testnet.bybit.com',
};
if (restInverseOptions.baseUrl) {
@@ -50,7 +58,7 @@ export function getRestBaseUrl(useLivenet: boolean, restInverseOptions: RestClie
return baseUrlsInverse.testnet;
}
export function isPublicEndpoint (endpoint: string): boolean {
export function isPublicEndpoint(endpoint: string): boolean {
if (endpoint.startsWith('v2/public')) {
return true;
}