Merge pull request #81 from tiagosiebler/samples

replace deprecated method in sample
This commit is contained in:
Tiago
2021-02-22 11:17:46 +00:00
committed by GitHub
5 changed files with 34 additions and 18 deletions

View File

@@ -45,7 +45,7 @@ Since inverse and linear (USDT) contracts don't use the exact same APIs, the RES
```javascript ```javascript
const { InverseClient } = require('bybit-api'); const { InverseClient } = require('bybit-api');
const restInverseOptions = { const 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;
@@ -77,16 +77,24 @@ const client = new InverseClient(
// optional, uses testnet by default. Set to 'true' to use livenet. // optional, uses testnet by default. Set to 'true' to use livenet.
useLivenet, useLivenet,
// restInverseOptions, // restClientOptions,
// requestLibraryOptions // requestLibraryOptions
); );
client.changeUserLeverage({leverage: 4, symbol: 'ETHUSD'}) client.getApiKeyInfo()
.then(result => { .then(result => {
console.log(result); console.log("apiKey result: ", result);
}) })
.catch(err => { .catch(err => {
console.error(err); console.error("apiKey error: ", err);
});
client.getOrderBook({ symbol: 'BTCUSD' })
.then(result => {
console.log("getOrderBook inverse result: ", result);
})
.catch(err => {
console.error("getOrderBook inverse error: ", err);
}); });
``` ```
@@ -98,7 +106,7 @@ To use the Linear (USDT) REST APIs, import the `LinearClient`:
```javascript ```javascript
const { LinearClient } = require('bybit-api'); const { LinearClient } = require('bybit-api');
const restInverseOptions = { const 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;
@@ -130,17 +138,25 @@ const client = new LinearClient(
// optional, uses testnet by default. Set to 'true' to use livenet. // optional, uses testnet by default. Set to 'true' to use livenet.
useLivenet, useLivenet,
// restInverseOptions, // restClientOptions,
// requestLibraryOptions // requestLibraryOptions
); );
client.changeUserLeverage({leverage: 4, symbol: 'ETHUSDT'}) client.getApiKeyInfo()
.then(result => { .then(result => {
console.log(result); console.log(result);
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
}); });
client.getOrderBook({ symbol: 'BTCUSDT' })
.then(result => {
console.log("getOrderBook linear result: ", result);
})
.catch(err => {
console.error("getOrderBook linear error: ", err);
});
``` ```
### WebSockets ### WebSockets

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "1.3.2", "version": "2.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "2.0.1", "version": "2.0.2",
"description": "Node.js connector for Bybit's Inverse & Linear REST APIs and WebSockets", "description": "Node.js connector for Bybit's Inverse & Linear REST APIs and WebSockets",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -12,22 +12,22 @@ 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 {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity * @param {RestClientOptions} [restClientOptions={}] 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: RestClientOptions = {}, restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {} requestOptions: AxiosRequestConfig = {}
) { ) {
super() super()
this.requestWrapper = new RequestWrapper( this.requestWrapper = new RequestWrapper(
key, key,
secret, secret,
getRestBaseUrl(useLivenet, restInverseOptions), getRestBaseUrl(useLivenet, restClientOptions),
restInverseOptions, restClientOptions,
requestOptions requestOptions
); );
return this; return this;

View File

@@ -12,22 +12,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} [useLivenet=false] * @param {boolean} [useLivenet=false]
* @param {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity * @param {RestClientOptions} [restClientOptions={}] 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: RestClientOptions = {}, restClientOptions: RestClientOptions = {},
requestOptions: AxiosRequestConfig = {} requestOptions: AxiosRequestConfig = {}
) { ) {
super() super()
this.requestWrapper = new RequestWrapper( this.requestWrapper = new RequestWrapper(
key, key,
secret, secret,
getRestBaseUrl(useLivenet, restInverseOptions), getRestBaseUrl(useLivenet, restClientOptions),
restInverseOptions, restClientOptions,
requestOptions requestOptions
); );
return this; return this;