bybit-api
Advanced tools
Comparing version 2.0.3 to 2.0.4-beta.1
@@ -10,3 +10,2 @@ export interface RestClientOptions { | ||
export declare type GenericAPIResponse = Promise<any>; | ||
export declare function signMessage(message: string, secret: string): string; | ||
export declare function serializeParams(params?: object, strict_validation?: boolean): string; | ||
@@ -13,0 +12,0 @@ export declare function getRestBaseUrl(useLivenet: boolean, restInverseOptions: RestClientOptions): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isWsPong = exports.isPublicEndpoint = exports.getRestBaseUrl = exports.serializeParams = exports.signMessage = void 0; | ||
const crypto_1 = require("crypto"); | ||
function signMessage(message, secret) { | ||
return crypto_1.createHmac('sha256', secret) | ||
.update(message) | ||
.digest('hex'); | ||
} | ||
exports.signMessage = signMessage; | ||
; | ||
exports.isWsPong = exports.isPublicEndpoint = exports.getRestBaseUrl = exports.serializeParams = void 0; | ||
function serializeParams(params = {}, strict_validation = false) { | ||
@@ -13,0 +5,0 @@ return Object.keys(params) |
@@ -25,3 +25,3 @@ import { AxiosRequestConfig, Method } from 'axios'; | ||
*/ | ||
signRequest(data: any): any; | ||
signRequest(data: any): Promise<any>; | ||
/** | ||
@@ -28,0 +28,0 @@ * @private trigger time sync and store promise |
@@ -16,2 +16,3 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const node_support_1 = require("./node-support"); | ||
const requestUtils_1 = require("./requestUtils"); | ||
@@ -61,3 +62,3 @@ class RequestUtil { | ||
} | ||
params = this.signRequest(params); | ||
params = yield this.signRequest(params); | ||
} | ||
@@ -109,12 +110,14 @@ const options = Object.assign(Object.assign({}, this.globalRequestOptions), { url: [this.baseUrl, endpoint].join('/'), method: method, json: true }); | ||
signRequest(data) { | ||
const params = Object.assign(Object.assign({}, data), { api_key: this.key, timestamp: Date.now() + (this.timeOffset || 0) }); | ||
// Optional, set to 5000 by default. Increase if timestamp/recv_window errors are seen. | ||
if (this.options.recv_window && !params.recv_window) { | ||
params.recv_window = this.options.recv_window; | ||
} | ||
if (this.key && this.secret) { | ||
const serializedParams = requestUtils_1.serializeParams(params, this.options.strict_param_validation); | ||
params.sign = requestUtils_1.signMessage(serializedParams, this.secret); | ||
} | ||
return params; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = Object.assign(Object.assign({}, data), { api_key: this.key, timestamp: Date.now() + (this.timeOffset || 0) }); | ||
// Optional, set to 5000 by default. Increase if timestamp/recv_window errors are seen. | ||
if (this.options.recv_window && !params.recv_window) { | ||
params.recv_window = this.options.recv_window; | ||
} | ||
if (this.key && this.secret) { | ||
const serializedParams = requestUtils_1.serializeParams(params, this.options.strict_param_validation); | ||
params.sign = yield node_support_1.signMessage(serializedParams, this.secret); | ||
} | ||
return params; | ||
}); | ||
} | ||
@@ -121,0 +124,0 @@ /** |
@@ -20,2 +20,3 @@ "use strict"; | ||
const logger_1 = require("./logger"); | ||
const node_support_1 = require("./util/node-support"); | ||
const requestUtils_1 = require("./util/requestUtils"); | ||
@@ -192,3 +193,3 @@ const isomorphic_ws_1 = __importDefault(require("isomorphic-ws")); | ||
}; | ||
params.signature = requestUtils_1.signMessage('GET/realtime' + params.expires, secret); | ||
params.signature = yield node_support_1.signMessage('GET/realtime' + params.expires, secret); | ||
return '?' + requestUtils_1.serializeParams(params); | ||
@@ -195,0 +196,0 @@ } |
{ | ||
"name": "bybit-api", | ||
"version": "2.0.3", | ||
"version": "2.0.4-beta.1", | ||
"description": "Node.js connector for Bybit's Inverse & Linear REST APIs and WebSockets", | ||
@@ -9,2 +9,3 @@ "main": "lib/index.js", | ||
"lib/*", | ||
"dist/*.js", | ||
"index.js" | ||
@@ -33,7 +34,4 @@ ], | ||
"@types/node": "^14.14.7", | ||
"buffer": "^6.0.2", | ||
"crypto-browserify": "^3.12.0", | ||
"eslint": "^7.10.0", | ||
"source-map-loader": "^2.0.0", | ||
"stream-browserify": "^3.0.0", | ||
"ts-loader": "^8.0.11", | ||
@@ -40,0 +38,0 @@ "typescript": "^4.0.5", |
@@ -148,4 +148,2 @@ # bybit-api | ||
**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 | ||
@@ -152,0 +150,0 @@ <details><summary>To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample:</summary> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129173
8
40
2326
2
323