From b6a17dcffeb8d5c81cab38e36746f9e445f866d4 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:17:13 +0000 Subject: [PATCH 01/21] cleaning unnecessary optionals --- src/inverse-client.ts | 2 +- src/linear-client.ts | 2 +- src/util/requestUtils.ts | 4 ++-- src/util/requestWrapper.ts | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/inverse-client.ts b/src/inverse-client.ts index 2a1779e8..f35eec82 100644 --- a/src/inverse-client.ts +++ b/src/inverse-client.ts @@ -18,7 +18,7 @@ export class InverseClient extends SharedEndpoints { constructor( key?: string | undefined, secret?: string | undefined, - useLivenet?: boolean, + useLivenet: boolean = false, restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {} ) { diff --git a/src/linear-client.ts b/src/linear-client.ts index 4c114116..9efc57ce 100644 --- a/src/linear-client.ts +++ b/src/linear-client.ts @@ -18,7 +18,7 @@ export class LinearClient extends SharedEndpoints { constructor( key?: string | undefined, secret?: string | undefined, - useLivenet?: boolean, + useLivenet: boolean = false, restClientOptions: RestClientOptions = {}, requestOptions: AxiosRequestConfig = {} ) { diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 903a7a23..a54086cd 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -42,13 +42,13 @@ export function serializeParams(params: object = {}, strict_validation = false): .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' }; - if (restInverseOptions?.baseUrl) { + if (restInverseOptions.baseUrl) { return restInverseOptions.baseUrl; } diff --git a/src/util/requestWrapper.ts b/src/util/requestWrapper.ts index e19f8f30..e618bc67 100644 --- a/src/util/requestWrapper.ts +++ b/src/util/requestWrapper.ts @@ -55,7 +55,6 @@ export default class RequestUtil { this.secret = secret; } - // TODO: type check that endpoint never starts with forward slash?? get(endpoint: string, params?: any): GenericAPIResponse { return this._call('GET', endpoint, params); } From 693d8b33a22cb490ae9d1474fe2745b859a4f6d2 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:37:54 +0000 Subject: [PATCH 02/21] v2.0.3: add support for inverse futures --- package.json | 2 +- src/index.ts | 1 + src/inverse-futures-client.ts | 354 ++++++++++++++++++++++++++++++++++ src/shared-endpoints.ts | 6 + 4 files changed, 362 insertions(+), 1 deletion(-) create mode 100644 src/inverse-futures-client.ts diff --git a/package.json b/package.json index 6568d7c1..ed63cc9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "2.0.2", + "version": "2.0.3", "description": "Node.js connector for Bybit's Inverse & Linear REST APIs and WebSockets", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/index.ts b/src/index.ts index bc82e2e4..bdd98508 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from './inverse-client'; +export * from './inverse-futures-client'; export * from './linear-client'; export * from './websocket-client'; export * from './logger'; diff --git a/src/inverse-futures-client.ts b/src/inverse-futures-client.ts new file mode 100644 index 00000000..6c3bdbd6 --- /dev/null +++ b/src/inverse-futures-client.ts @@ -0,0 +1,354 @@ +import { AxiosRequestConfig } from 'axios'; +import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils'; +import RequestWrapper from './util/requestWrapper'; +import SharedEndpoints from './shared-endpoints'; + +export class InverseFuturesClient extends SharedEndpoints { + protected requestWrapper: RequestWrapper; + + /** + * @public Creates an instance of the inverse REST API 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( + key?: string | undefined, + secret?: string | undefined, + useLivenet: boolean = false, + restClientOptions: RestClientOptions = {}, + requestOptions: AxiosRequestConfig = {} + ) { + super() + this.requestWrapper = new RequestWrapper( + key, + secret, + getRestBaseUrl(useLivenet, restClientOptions), + restClientOptions, + requestOptions + ); + return this; + } + + /** + * + * Market Data Endpoints + * Note: These are currently the same as the inverse client + */ + + getKline(params: { + symbol: string; + interval: string; + from: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/kline/list', params); + } + + /** + * Public trading records + */ + getTrades(params: { + symbol: string; + from?: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/trading-records', params); + } + + getMarkPriceKline(params: { + symbol: string; + interval: string; + from: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/mark-price-kline', params); + } + + getIndexPriceKline(params: { + symbol: string; + interval: string; + from: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/index-price-kline', params); + } + + getPremiumIndexKline(params: { + symbol: string; + interval: string; + from: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/premium-index-kline', params); + } + + /** + * + * Account Data Endpoints + * + */ + + /** + * Active orders + */ + + placeActiveOrder(orderRequest: { + side: string; + symbol: string; + order_type: string; + qty: number; + price?: number; + time_in_force: string; + take_profit?: number; + stop_loss?: number; + reduce_only?: boolean; + close_on_trigger?: boolean; + order_link_id?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/order/create', orderRequest); + } + + getActiveOrderList(params: { + symbol: string; + order_status?: string; + direction?: string; + limit?: number; + cursor?: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/order/list', params); + } + + cancelActiveOrder(params: { + symbol: string; + order_id?: string; + order_link_id?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/order/cancel', params); + } + + cancelAllActiveOrders(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/order/cancelAll', params); + } + + replaceActiveOrder(params: { + order_id?: string; + order_link_id?: string; + symbol: string; + p_r_qty?: string; + p_r_price?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/order/replace', params); + } + + queryActiveOrder(params: { + order_id?: string; + order_link_id?: string; + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/order', params); + } + + /** + * Conditional orders + */ + + placeConditionalOrder(params: { + side: string; + symbol: string; + order_type: string; + qty: string; + price?: string; + base_price: string; + stop_px: string; + time_in_force: string; + trigger_by?: string; + close_on_trigger?: boolean; + order_link_id?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/stop-order/create', params); + } + + getConditionalOrder(params: { + symbol: string; + stop_order_status?: string; + direction?: string; + limit?: number; + cursor?: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/stop-order/list', params); + } + + cancelConditionalOrder(params: { + symbol: string; + stop_order_id?: string; + order_link_id?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/stop-order/cancel', params); + } + + cancelAllConditionalOrders(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/stop-order/cancelAll', params); + } + + replaceConditionalOrder(params: { + stop_order_id?: string; + order_link_id?: string; + symbol: string; + p_r_qty?: number; + p_r_price?: string; + p_r_trigger_price?: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/stop-order/replace', params); + } + + queryConditionalOrder(params: { + symbol: string; + stop_order_id?: string; + order_link_id?: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/stop-order', params); + } + + /** + * Position + */ + + + /** + * Get position list + */ + getPosition(params?: { + symbol?: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/position/list', params); + } + + changePositionMargin(params: { + symbol: string; + margin: string; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/position/change-position-margin', params); + } + + setTradingStop(params: { + symbol: string; + take_profit?: number; + stop_loss?: number; + trailing_stop?: number; + tp_trigger_by?: string; + sl_trigger_by?: string; + new_trailing_active?: number; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/position/trading-stop', params); + } + + setUserLeverage(params: { + symbol: string; + buy_leverage: number; + sell_leverage: number; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/position/leverage/save', params); + } + + /** + * Position mode switch + */ + setPositionMode(params: { + symbol: string; + mode: number; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/position/switch-mode', params); + } + + /** + * Cross/Isolated margin switch. Must set leverage value when switching. + */ + setMarginType(params: { + symbol: string; + is_isolated: boolean; + buy_leverage: number; + sell_leverage: number; + }): GenericAPIResponse { + return this.requestWrapper.post('futures/private/position/switch-isolated', params); + } + + getTradeRecords(params: { + order_id?: string; + symbol: string; + start_time?: number; + page?: number; + limit?: number; + order?: string; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/execution/list', params); + } + + getClosedPnl(params: { + symbol: string; + start_time?: number; + end_time?: number; + exec_type?: string; + page?: number; + limit?: number; + }): GenericAPIResponse { + return this.requestWrapper.get('futures/private/trade/closed-pnl/list', params); + } + + /** + **** The following are all the same as the inverse client **** + */ + + /** + * Risk Limit + */ + getRiskLimitList(): GenericAPIResponse { + return this.requestWrapper.get('open-api/wallet/risk-limit/list'); + } + + setRiskLimit(params: { + symbol: string; + risk_id: string; + }): GenericAPIResponse { + return this.requestWrapper.post('open-api/wallet/risk-limit', params); + } + + /** + * Funding + */ + + getLastFundingRate(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params); + } + + getMyLastFundingFee(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/private/funding/prev-funding', params); + } + + getPredictedFunding(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/private/funding/predicted-funding', params); + } + + /** + * LCP Info + */ + + getLcpInfo(params: { + symbol: string; + }): GenericAPIResponse { + return this.requestWrapper.get('v2/private/account/lcp', params); + } +}; diff --git a/src/shared-endpoints.ts b/src/shared-endpoints.ts index 1f3a9b2e..730a3207 100644 --- a/src/shared-endpoints.ts +++ b/src/shared-endpoints.ts @@ -17,6 +17,9 @@ export default class SharedEndpoints { return this.requestWrapper.get('v2/public/orderBook/L2', params); } + /** + * Get latest information for symbol + */ getTickers(params?: { symbol?: string; }): GenericAPIResponse { @@ -27,6 +30,9 @@ export default class SharedEndpoints { return this.requestWrapper.get('v2/public/symbols'); } + /** + * Get liquidated orders + */ getLiquidations(params: { symbol: string; from?: number; From f181f9ac6135c26e9ff316971489255ce0b57eb3 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:38:06 +0000 Subject: [PATCH 03/21] Add missing parameter type --- src/inverse-client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/inverse-client.ts b/src/inverse-client.ts index f35eec82..80520bdc 100644 --- a/src/inverse-client.ts +++ b/src/inverse-client.ts @@ -282,6 +282,7 @@ export class InverseClient extends SharedEndpoints { symbol: string; take_profit?: number; stop_loss?: number; + trailing_stop?: number; tp_trigger_by?: string; sl_trigger_by?: string; new_trailing_active?: number; From d558986812b4e70995b180719d74ccfedc49ca97 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:53:02 +0000 Subject: [PATCH 04/21] Add inverse futures to docs --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ff9f3c00..60df7269 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,19 @@ Build a bundle using webpack: The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO. -### Inverse Contracts -Since inverse and linear (USDT) contracts don't use the exact same APIs, the REST abstractions are split into two modules. To use the inverse REST APIs, import the `InverseClient`: +### REST API Clients +There are three REST API modules as there are some differences in each contract type. +1. `InverseClient` for inverse perpetual +2. `InverseFuturesClient` for inverse futures +3. `LinearClient` for linear perpetual + +#### Inverse Contracts + +To use the inverse REST APIs, import the `InverseClient`: + +
Click here to expand and see full sample: +

```javascript const { InverseClient } = require('bybit-api'); @@ -97,35 +107,62 @@ client.getOrderBook({ symbol: 'BTCUSD' }) console.error("getOrderBook inverse error: ", err); }); ``` +

-See inverse [inverse-client.ts](./src/inverse-client.ts) for further information. +See [inverse-client.ts](./src/inverse-client.ts) for further information. -### Linear Contracts -To use the Linear (USDT) REST APIs, import the `LinearClient`: +#### Inverse Futures Contracts +**Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. + +To use the inverse futures REST APIs, import the `InverseFuturesClient`: +
Click here to expand and see full sample: +

```javascript -const { LinearClient } = require('bybit-api'); +const { InverseFuturesClient } = require('bybit-api'); -const restClientOptions = { - // override the max size of the request window (in ms) - recv_window?: number; +const API_KEY = 'xxx'; +const PRIVATE_KEY = 'yyy'; +const useLivenet = false; - // how often to sync time drift with bybit servers - sync_interval_ms?: number | string; +const client = new InverseFuturesClient( + API_KEY, + PRIVATE_KEY, - // Default: false. Disable above sync mechanism if true. - disable_time_sync?: boolean; + // optional, uses testnet by default. Set to 'true' to use livenet. + useLivenet, - // Default: false. If true, we'll throw errors if any params are undefined - strict_param_validation?: boolean; + // restClientOptions, + // requestLibraryOptions +); - // Optionally override API protocol + domain - // e.g 'https://api.bytick.com' - baseUrl?: string; +client.getApiKeyInfo() + .then(result => { + console.log("apiKey result: ", result); + }) + .catch(err => { + console.error("apiKey error: ", err); + }); - // Default: true. whether to try and post-process request exceptions. - parse_exceptions?: boolean; -}; +client.getOrderBook({ symbol: 'BTCUSDH21' }) + .then(result => { + console.log("getOrderBook inverse futures result: ", result); + }) + .catch(err => { + console.error("getOrderBook inverse futures error: ", err); + }); +``` +

+ +See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information. + +### Linear Contracts +To use the Linear (USDT) REST APIs, import the `LinearClient`: + +
Click here to expand and see full sample: +

+```javascript +const { LinearClient } = require('bybit-api'); const API_KEY = 'xxx'; const PRIVATE_KEY = 'yyy'; @@ -158,6 +195,7 @@ client.getOrderBook({ symbol: 'BTCUSDT' }) console.error("getOrderBook linear error: ", err); }); ``` +

### WebSockets @@ -167,6 +205,8 @@ Note: to use the linear websockets, pass "linear: true" in the constructor optio To connect to both linear and inverse websockets, make two instances of the WebsocketClient: +
Click here to expand and see full sample: +

```javascript const { WebsocketClient } = require('bybit-api'); @@ -240,11 +280,15 @@ ws.on('error', err => { console.error('ERR', err); }); ``` +

+ See [websocket-client.ts](./src/websocket-client.ts) for further information. ### Customise Logging Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired: +
Click here to expand and see full sample: +

```js const { WebsocketClient, DefaultLogger } = require('bybit-api'); @@ -256,6 +300,7 @@ const ws = new WebsocketClient( DefaultLogger ); ``` +

## Contributions & Thanks ### Donations From 904d1f672e8981df7eb770769147595607339b50 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:54:13 +0000 Subject: [PATCH 05/21] readme formatting --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 60df7269..b7d78cf8 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ There are three REST API modules as there are some differences in each contract To use the inverse REST APIs, import the `InverseClient`:
Click here to expand and see full sample: -

```javascript const { InverseClient } = require('bybit-api'); @@ -107,7 +106,7 @@ client.getOrderBook({ symbol: 'BTCUSD' }) console.error("getOrderBook inverse error: ", err); }); ``` -

+ See [inverse-client.ts](./src/inverse-client.ts) for further information. From b22bc38b543888e89e1fbebaf15f553ece8bf12e Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:55:01 +0000 Subject: [PATCH 06/21] readme formatting --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b7d78cf8..6ade13bf 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ There are three REST API modules as there are some differences in each contract To use the inverse REST APIs, import the `InverseClient`:
Click here to expand and see full sample: + ```javascript const { InverseClient } = require('bybit-api'); @@ -106,6 +107,7 @@ client.getOrderBook({ symbol: 'BTCUSD' }) console.error("getOrderBook inverse error: ", err); }); ``` +
See [inverse-client.ts](./src/inverse-client.ts) for further information. From 2d9c57089eee0db68c84b8e5380d3e4df9bb4d11 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:56:14 +0000 Subject: [PATCH 07/21] readme formatting fix --- README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6ade13bf..ae49dca3 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ See [inverse-client.ts](./src/inverse-client.ts) for further information. To use the inverse futures REST APIs, import the `InverseFuturesClient`:
Click here to expand and see full sample: -

+ ```javascript const { InverseFuturesClient } = require('bybit-api'); @@ -153,7 +153,8 @@ client.getOrderBook({ symbol: 'BTCUSDH21' }) console.error("getOrderBook inverse futures error: ", err); }); ``` -

+ + See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information. @@ -161,7 +162,7 @@ See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further inf To use the Linear (USDT) REST APIs, import the `LinearClient`:
Click here to expand and see full sample: -

+ ```javascript const { LinearClient } = require('bybit-api'); @@ -196,7 +197,8 @@ client.getOrderBook({ symbol: 'BTCUSDT' }) console.error("getOrderBook linear error: ", err); }); ``` -

+ + ### WebSockets @@ -207,7 +209,7 @@ Note: to use the linear websockets, pass "linear: true" in the constructor optio To connect to both linear and inverse websockets, make two instances of the WebsocketClient:
Click here to expand and see full sample: -

+ ```javascript const { WebsocketClient } = require('bybit-api'); @@ -281,7 +283,8 @@ ws.on('error', err => { console.error('ERR', err); }); ``` -

+ + See [websocket-client.ts](./src/websocket-client.ts) for further information. @@ -289,8 +292,8 @@ See [websocket-client.ts](./src/websocket-client.ts) for further information. Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired:
Click here to expand and see full sample: -

-```js + +```javascript const { WebsocketClient, DefaultLogger } = require('bybit-api'); // Disable all logging on the silly level @@ -301,7 +304,8 @@ const ws = new WebsocketClient( DefaultLogger ); ``` -

+ + ## Contributions & Thanks ### Donations From 3dc2b7ba457a927be61f549968034f8f5654aad5 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:58:19 +0000 Subject: [PATCH 08/21] readme formatting improvements --- README.md | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ae49dca3..9a20afbd 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,8 @@ There are three REST API modules as there are some differences in each contract 2. `InverseFuturesClient` for inverse futures 3. `LinearClient` for linear perpetual -#### Inverse Contracts - -To use the inverse REST APIs, import the `InverseClient`: - -
Click here to expand and see full sample: +## Inverse Contracts +
To use the inverse REST APIs, import the `InverseClient` Click here to expand and see full sample: ```javascript const { InverseClient } = require('bybit-api'); @@ -112,12 +109,10 @@ client.getOrderBook({ symbol: 'BTCUSD' }) See [inverse-client.ts](./src/inverse-client.ts) for further information. -#### Inverse Futures Contracts +## Inverse Futures Contracts **Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. -To use the inverse futures REST APIs, import the `InverseFuturesClient`: - -
Click here to expand and see full sample: +
To use the inverse futures REST APIs, import the `InverseFuturesClient`. Click here to expand and see full sample: ```javascript const { InverseFuturesClient } = require('bybit-api'); @@ -159,9 +154,7 @@ client.getOrderBook({ symbol: 'BTCUSDH21' }) See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information. ### Linear Contracts -To use the Linear (USDT) REST APIs, import the `LinearClient`: - -
Click here to expand and see full sample: +
To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample: ```javascript const { LinearClient } = require('bybit-api'); @@ -204,11 +197,9 @@ client.getOrderBook({ symbol: 'BTCUSDT' }) Inverse & linear WebSockets can be used via a shared `WebsocketClient`. -Note: to use the linear websockets, pass "linear: true" in the constructor options when instancing the `WebsocketClient`. +Note: for linear websockets, pass "linear: true" in the constructor options when instancing the `WebsocketClient`. -To connect to both linear and inverse websockets, make two instances of the WebsocketClient: - -
Click here to expand and see full sample: +
To connect to both linear and inverse websockets, make two instances of the WebsocketClient. Click here to expand and see full sample: ```javascript const { WebsocketClient } = require('bybit-api'); From 7bd40d10b8a4f031e3901b4db81d89f90f41ba98 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 17:58:35 +0000 Subject: [PATCH 09/21] readme headers --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a20afbd..2696bf46 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ client.getOrderBook({ symbol: 'BTCUSDH21' }) See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information. -### Linear Contracts +## Linear Contracts
To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample: ```javascript @@ -193,7 +193,7 @@ client.getOrderBook({ symbol: 'BTCUSDT' })
-### WebSockets +## WebSockets Inverse & linear WebSockets can be used via a shared `WebsocketClient`. From db9ff36478eac5846bf38a73928efb45f9077fa2 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:00:07 +0000 Subject: [PATCH 10/21] readme cleaning --- README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2696bf46..92783b41 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,6 @@ client.getOrderBook({ symbol: 'BTCUSD' }) See [inverse-client.ts](./src/inverse-client.ts) for further information. ## Inverse Futures Contracts -**Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. -
To use the inverse futures REST APIs, import the `InverseFuturesClient`. Click here to expand and see full sample: ```javascript @@ -153,6 +151,8 @@ client.getOrderBook({ symbol: 'BTCUSDH21' }) See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information. +**Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. + ## Linear Contracts
To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample: @@ -194,12 +194,7 @@ client.getOrderBook({ symbol: 'BTCUSDT' })
## WebSockets - -Inverse & linear WebSockets can be used via a shared `WebsocketClient`. - -Note: for linear websockets, pass "linear: true" in the constructor options when instancing the `WebsocketClient`. - -
To connect to both linear and inverse websockets, make two instances of the WebsocketClient. Click here to expand and see full sample: +
Inverse & linear WebSockets can be used via a shared `WebsocketClient`. Click here to expand and see full sample: ```javascript const { WebsocketClient } = require('bybit-api'); @@ -277,12 +272,11 @@ ws.on('error', err => {
+Note: for linear websockets, pass "linear: true" in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. See [websocket-client.ts](./src/websocket-client.ts) for further information. ### Customise Logging -Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired: - -
Click here to expand and see full sample: +
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired. Click here to expand and see full sample: ```javascript const { WebsocketClient, DefaultLogger } = require('bybit-api'); From a95a1c476f1d3df16f044b88823523431d1d1906 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:02:36 +0000 Subject: [PATCH 11/21] readme improvements --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 92783b41..4ec4af37 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,6 @@ Create API credentials at Bybit - [Livenet](https://bybit.com/app/user/api-management?affiliate_id=9410&language=en-US&group_id=0&group_type=1) - [Testnet](https://testnet.bybit.com/app/user/api-management) -### Browser Usage -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. - ### REST API Clients There are three REST API modules as there are some differences in each contract type. @@ -272,9 +264,10 @@ ws.on('error', err => {
-Note: for linear websockets, pass "linear: true" in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. See [websocket-client.ts](./src/websocket-client.ts) for further information. +Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. + ### Customise Logging
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired. Click here to expand and see full sample: @@ -292,6 +285,16 @@ const ws = new WebsocketClient(
+### Browser Usage +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. + ## Contributions & Thanks ### Donations #### tiagosiebler From 56daee715697185e84ccacce0f98ac5dfa92c4d7 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:03:05 +0000 Subject: [PATCH 12/21] readme improvements --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ec4af37..f85a8b02 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [1]: https://www.npmjs.com/package/bybit-api -A production-ready Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser support. +Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser support. ## Installation `npm install --save bybit-api` From 18e2f90f45f8192b0d117ab1f467e67cd8f3baa8 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:03:39 +0000 Subject: [PATCH 13/21] remove readme comment --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f85a8b02..737f531f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser s ## Issues & Discussion - Issues? Check the [issues tab](https://github.com/tiagosiebler/bybit-api/issues). - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram. -- `'bybit-api' has no exported member 'RestClient'`: use `InverseClient` instead of `RestClient` ## Documentation Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation. From 85e56ad3fdf0fcacd196b57b5e1531085d405128 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:04:21 +0000 Subject: [PATCH 14/21] docs link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 737f531f..b0f1dde5 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser s ## Documentation Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation. - [Bybit API Inverse Documentation](https://bybit-exchange.github.io/docs/inverse/#t-introduction). +- [Bybit API Inverse Futures Documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction). - [Bybit API Linear Documentation](https://bybit-exchange.github.io/docs/linear/#t-introduction) ## Structure From c7e30d9b498c7d1f685b516bde885d99e2e3069d Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:05:27 +0000 Subject: [PATCH 15/21] readme formatting --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0f1dde5..ad33affe 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,9 @@ See [websocket-client.ts](./src/websocket-client.ts) for further information. Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. ### Customise Logging -
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired. Click here to expand and see full sample: +Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired. + +
Click here to expand and see full sample: ```javascript const { WebsocketClient, DefaultLogger } = require('bybit-api'); From a18730870bb6e07c7249c44422d88050c6b312d1 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:06:10 +0000 Subject: [PATCH 16/21] readme links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad33affe..8a525026 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ There are three REST API modules as there are some differences in each contract 2. `InverseFuturesClient` for inverse futures 3. `LinearClient` for linear perpetual -## Inverse Contracts +## REST Inverse
To use the inverse REST APIs, import the `InverseClient` Click here to expand and see full sample: ```javascript @@ -101,7 +101,7 @@ client.getOrderBook({ symbol: 'BTCUSD' }) See [inverse-client.ts](./src/inverse-client.ts) for further information. -## Inverse Futures Contracts +## REST Inverse Futures
To use the inverse futures REST APIs, import the `InverseFuturesClient`. Click here to expand and see full sample: ```javascript @@ -145,7 +145,7 @@ See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further inf **Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. -## Linear Contracts +## REST Linear
To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample: ```javascript From 755f60abaa154afa4821a67fa5c484ac0dfb0e03 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:07:20 +0000 Subject: [PATCH 17/21] readme formatting --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a525026..3b4386ba 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,14 @@ This project uses typescript. Resources are stored in 3 key structures: - [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release. - [dist](./dist) - the packed bundle of the project for use in browser environments. -## Usage +--- + +# Usage Create API credentials at Bybit - [Livenet](https://bybit.com/app/user/api-management?affiliate_id=9410&language=en-US&group_id=0&group_type=1) - [Testnet](https://testnet.bybit.com/app/user/api-management) -### REST API Clients +## REST API Clients There are three REST API modules as there are some differences in each contract type. 1. `InverseClient` for inverse perpetual @@ -268,7 +270,7 @@ See [websocket-client.ts](./src/websocket-client.ts) for further information. Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. -### Customise Logging +## Customise Logging Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
Click here to expand and see full sample: @@ -287,7 +289,7 @@ const ws = new WebsocketClient(
-### Browser Usage +## Browser Usage Build a bundle using webpack: - `npm install` - `npm build` From ab183fd3393195b5fd7e1393715f6312a2311d62 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:08:22 +0000 Subject: [PATCH 18/21] readme formatting --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3b4386ba..763bcf12 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,8 @@ See [websocket-client.ts](./src/websocket-client.ts) for further information. Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient. +--- + ## Customise Logging Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired. @@ -299,6 +301,8 @@ The bundle can be found in `dist/`. Altough usage should be largely consistent, However, note that browser usage will lead to CORS errors due Bybit. See [issue #79](#79) for more information & alternative suggestions. +--- + ## Contributions & Thanks ### Donations #### tiagosiebler From 90c2a014b4616f365ea4a2b5630cb933b78a6492 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:08:56 +0000 Subject: [PATCH 19/21] readme headers --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 763bcf12..35cfe3b2 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ There are three REST API modules as there are some differences in each contract 2. `InverseFuturesClient` for inverse futures 3. `LinearClient` for linear perpetual -## REST Inverse +### REST Inverse
To use the inverse REST APIs, import the `InverseClient` Click here to expand and see full sample: ```javascript @@ -103,7 +103,7 @@ client.getOrderBook({ symbol: 'BTCUSD' }) See [inverse-client.ts](./src/inverse-client.ts) for further information. -## REST Inverse Futures +### REST Inverse Futures
To use the inverse futures REST APIs, import the `InverseFuturesClient`. Click here to expand and see full sample: ```javascript @@ -147,7 +147,7 @@ See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further inf **Note**: as of 6th March 2021 this is currently only for testnet. See the [Bybit API documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction) for official updates. -## REST Linear +### REST Linear
To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample: ```javascript From 59d8a682406b1d0803574ad4fa078d809cd769e9 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:09:29 +0000 Subject: [PATCH 20/21] readme fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35cfe3b2..943ba198 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ There are three REST API modules as there are some differences in each contract 3. `LinearClient` for linear perpetual ### REST Inverse -
To use the inverse REST APIs, import the `InverseClient` Click here to expand and see full sample: +
To use the inverse REST APIs, import the `InverseClient`. Click here to expand and see full sample: ```javascript const { InverseClient } = require('bybit-api'); From 308a2b69f860cdb58aadd37a3baf33b80c3d26c6 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sat, 6 Mar 2021 18:10:04 +0000 Subject: [PATCH 21/21] update comment --- src/inverse-futures-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inverse-futures-client.ts b/src/inverse-futures-client.ts index 6c3bdbd6..fcd4cd09 100644 --- a/src/inverse-futures-client.ts +++ b/src/inverse-futures-client.ts @@ -7,7 +7,7 @@ export class InverseFuturesClient extends SharedEndpoints { protected requestWrapper: RequestWrapper; /** - * @public Creates an instance of the inverse REST API client. + * @public Creates an instance of the inverse futures REST API client. * * @param {string} key - your API key * @param {string} secret - your API secret