Merge pull request #370 from tiagosiebler/dependencies

v3.10.17: chore() update dependencies, feat() add apiRegion config for changing regional API URL
This commit is contained in:
Tiago
2024-09-09 10:26:16 +01:00
committed by GitHub
4 changed files with 530 additions and 415 deletions

View File

@@ -0,0 +1,57 @@
import { RestClientV5 } from '../src/index';
// or
// import { RestClientV5 } from 'bybit-api';
/**
* The first parameter of the REST client allows you to pass any configuration parameters supported by the SDK.
*
* These include API keys, if you wish to use private endpoints, but also expose other features such as
* setting a custom base URL (e.g. for Turkish users).
*
* Refer to the API documentation for a complete list of domains: https://bybit-exchange.github.io/docs/v5/guide#authentication
*/
const client = new RestClientV5({
/**
* You can pass a completely custom base URL,
* e.g. if you're trying to use a domain that hasn't been added yet (please let us know)
*/
// baseUrl: 'https://api5.bybit.com',
//
//
/**
*
* There are also predefined API regions, which you can easily use with the "apiRegion" property:
*
*/
//
//
// default: routes to api.bybit.com
// apiRegion: 'default',
//
//
// bytick: routes to api.bytick.com
// apiRegion: 'bytick',
//
//
// NL: routes to api.bybit.nl (for Netherland users)
// apiRegion: 'NL',
//
//
// HK: routes to api.byhkbit.com (for Hong Kong users)
// apiRegion: 'HK',
//
//
// TK: routes to api.bybit-tr.com (for Turkey users)
// apiRegion: 'TK',
});
(async () => {
try {
const time1 = await client.getServerTime();
console.log('time res: ', { time1 });
} catch (e) {
console.error('request failed: ', e);
}
})();

862
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.10.16", "version": "3.10.17",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -51,6 +51,8 @@ export interface RestClientOptions {
**/ **/
baseUrl?: string; baseUrl?: string;
apiRegion?: 'default' | 'bytick' | 'NL' | 'HK' | 'TK';
/** Default: true. whether to try and post-process request exceptions. */ /** Default: true. whether to try and post-process request exceptions. */
parse_exceptions?: boolean; parse_exceptions?: boolean;
@@ -100,7 +102,13 @@ export function getRestBaseUrl(
restClientOptions: RestClientOptions, restClientOptions: RestClientOptions,
): string { ): string {
const exchangeBaseUrls = { const exchangeBaseUrls = {
livenet: 'https://api.bybit.com', livenet: {
default: 'https://api.bybit.com',
bytick: 'https://api.bytick.com',
NL: 'https://api.bybit.nl',
HK: 'https://api.byhkbit.com',
TK: 'https://api.bybit-tr.com',
},
testnet: 'https://api-testnet.bybit.com', testnet: 'https://api-testnet.bybit.com',
demoLivenet: 'https://api-demo.bybit.com', demoLivenet: 'https://api-demo.bybit.com',
}; };
@@ -117,7 +125,19 @@ export function getRestBaseUrl(
return exchangeBaseUrls.testnet; return exchangeBaseUrls.testnet;
} }
return exchangeBaseUrls.livenet; if (restClientOptions.apiRegion) {
const regionalBaseURL =
exchangeBaseUrls.livenet[restClientOptions.apiRegion];
if (!regionalBaseURL) {
throw new Error(
`No base URL found for region "${restClientOptions.apiRegion}". Check that your "apiRegion" value is valid.`,
);
}
return regionalBaseURL;
}
return exchangeBaseUrls.livenet.default;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any