Merge pull request #273 from tiagosiebler/typenaming
v3.7.1: chore() naming consistency for interface, pass through logger for ws url getter
This commit is contained in:
40
README.md
40
README.md
@@ -1,4 +1,4 @@
|
||||
# Node.js & Typescript Bybit API SDK
|
||||
# Node.js & JavaScript SDK for Bybit REST API & WebSockets
|
||||
|
||||
[](https://circleci.com/gh/tiagosiebler/bybit-api)
|
||||
[][1] [][1] [][1]
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
[1]: https://www.npmjs.com/package/bybit-api
|
||||
|
||||
Node.js SDK for the Bybit APIs and WebSockets:
|
||||
Node.js & JavaScript SDK for the Bybit REST APIs and WebSockets:
|
||||
|
||||
- Complete integration with all Bybit APIs.
|
||||
- Complete integration with all Bybit REST APIs & WebSockets.
|
||||
- TypeScript support (with type declarations for most API requests & responses).
|
||||
- Over 450 end-to-end tests making real API calls & WebSocket connections, validating any changes before they reach npm.
|
||||
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
||||
@@ -329,15 +329,43 @@ In rare situations, you may want to see the raw HTTP requets being built as well
|
||||
|
||||
## Browser Usage
|
||||
|
||||
### Import
|
||||
|
||||
This is the "modern" way, allowing the package to be directly imported into frontend projects with full typescript support.
|
||||
|
||||
1. Install these dependencies
|
||||
```sh
|
||||
npm install crypto-browserify stream-browserify
|
||||
```
|
||||
2. Add this to your `tsconfig.json`
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"crypto": [
|
||||
"./node_modules/crypto-browserify"
|
||||
],
|
||||
"stream": [
|
||||
"./node_modules/stream-browserify"
|
||||
]
|
||||
}
|
||||
```
|
||||
3. Declare this in the global context of your application (ex: in polyfills for angular)
|
||||
```js
|
||||
(window as any).global = window;
|
||||
```
|
||||
|
||||
### Webpack
|
||||
|
||||
This is the "old" way of using this package on webpages. This will build a minified js bundle that can be pulled in using a script tag on a website.
|
||||
|
||||
Build a bundle using webpack:
|
||||
|
||||
- `npm install`
|
||||
- `npm build`
|
||||
- `npm pack`
|
||||
|
||||
The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
|
||||
|
||||
However, note that browser usage will lead to CORS errors due Bybit. See [issue #79](#79) for more information & alternative suggestions.
|
||||
The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO - contributions welcome.
|
||||
|
||||
---
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "bybit-api",
|
||||
"version": "3.7.0",
|
||||
"version": "3.7.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "bybit-api",
|
||||
"version": "3.7.0",
|
||||
"version": "3.7.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^0.21.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bybit-api",
|
||||
"version": "3.7.0",
|
||||
"version": "3.7.1",
|
||||
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
||||
@@ -46,8 +46,8 @@ import {
|
||||
FeeRateV5,
|
||||
FundingRateHistoryResponseV5,
|
||||
GetAccountCoinBalanceParamsV5,
|
||||
GetAccountHistoricOrdersPArams,
|
||||
GetAccountOrdersParams,
|
||||
GetAccountHistoricOrdersParamsV5,
|
||||
GetAccountOrdersParamsV5,
|
||||
GetAllCoinsBalanceParamsV5,
|
||||
GetAllowedDepositCoinInfoParamsV5,
|
||||
GetAssetInfoParamsV5,
|
||||
@@ -392,7 +392,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
* Query unfilled or partially filled orders in real-time. To query older order records, please use the order history interface.
|
||||
*/
|
||||
getActiveOrders(
|
||||
params: GetAccountOrdersParams,
|
||||
params: GetAccountOrdersParamsV5,
|
||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<AccountOrderV5[]>>> {
|
||||
return this.getPrivate('/v5/order/realtime', params);
|
||||
}
|
||||
@@ -409,7 +409,7 @@ export class RestClientV5 extends BaseRestClient {
|
||||
* If you want to get real-time order information, you could query this endpoint or rely on the websocket stream (recommended).
|
||||
*/
|
||||
getHistoricOrders(
|
||||
params: GetAccountHistoricOrdersPArams,
|
||||
params: GetAccountHistoricOrdersParamsV5,
|
||||
): Promise<APIResponseV3WithTime<CategoryCursorListV5<AccountOrderV5[]>>> {
|
||||
return this.getPrivate('/v5/order/history', params);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export interface CancelOrderParamsV5 {
|
||||
orderFilter?: OrderFilterV5;
|
||||
}
|
||||
|
||||
export interface GetAccountOrdersParams {
|
||||
export interface GetAccountOrdersParamsV5 {
|
||||
category: CategoryV5;
|
||||
symbol?: string;
|
||||
baseCoin?: string;
|
||||
@@ -81,7 +81,7 @@ export interface GetAccountOrdersParams {
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
export interface GetAccountHistoricOrdersPArams {
|
||||
export interface GetAccountHistoricOrdersParamsV5 {
|
||||
category: CategoryV5;
|
||||
symbol?: string;
|
||||
baseCoin?: string;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { APIMarket, CategoryV5, WsKey } from '../types';
|
||||
import { DefaultLogger } from './logger';
|
||||
|
||||
interface NetworkMapV3 {
|
||||
livenet: string;
|
||||
@@ -397,6 +398,7 @@ export function getWsUrl(
|
||||
wsKey: WsKey,
|
||||
wsUrl: string | undefined,
|
||||
isTestnet: boolean,
|
||||
logger: typeof DefaultLogger,
|
||||
): string {
|
||||
if (wsUrl) {
|
||||
return wsUrl;
|
||||
@@ -479,7 +481,7 @@ export function getWsUrl(
|
||||
return WS_BASE_URL_MAP.v5OptionPublic.public[networkKey];
|
||||
}
|
||||
default: {
|
||||
this.logger.error('getWsUrl(): Unhandled wsKey: ', {
|
||||
logger.error('getWsUrl(): Unhandled wsKey: ', {
|
||||
category: 'bybit-ws',
|
||||
wsKey,
|
||||
});
|
||||
|
||||
@@ -621,7 +621,12 @@ export class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
|
||||
const authParams = await this.getAuthParams(wsKey);
|
||||
const url = getWsUrl(wsKey, this.options.wsUrl, this.isTestnet());
|
||||
const url = getWsUrl(
|
||||
wsKey,
|
||||
this.options.wsUrl,
|
||||
this.isTestnet(),
|
||||
this.logger,
|
||||
);
|
||||
const ws = this.connectToWsUrl(url + authParams, wsKey);
|
||||
|
||||
return this.wsStore.setWs(wsKey, ws);
|
||||
|
||||
@@ -21,6 +21,7 @@ function generateConfig(name) {
|
||||
alias: {
|
||||
[path.resolve(__dirname, "../lib/util/node-support.js")]:
|
||||
path.resolve(__dirname, "../lib/util/browser-support.js"),
|
||||
process: "process/browser",
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user