fix(#240): fix sign error on parallel requests due to pointer mutation
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.5.2",
|
"version": "3.5.3",
|
||||||
"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",
|
||||||
|
|||||||
@@ -11,16 +11,19 @@ import {
|
|||||||
} from './requestUtils';
|
} from './requestUtils';
|
||||||
import { signMessage } from './node-support';
|
import { signMessage } from './node-support';
|
||||||
|
|
||||||
// axios.interceptors.request.use((request) => {
|
|
||||||
// console.log(new Date(), 'Starting Request', JSON.stringify(request, null, 2));
|
|
||||||
// return request;
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof process === 'object' &&
|
typeof process === 'object' &&
|
||||||
typeof process.env === 'object' &&
|
typeof process.env === 'object' &&
|
||||||
process.env.BYBITTRACE
|
process.env.BYBITTRACE
|
||||||
) {
|
) {
|
||||||
|
// axios.interceptors.request.use((request) => {
|
||||||
|
// console.log(
|
||||||
|
// new Date(),
|
||||||
|
// 'Starting Request',
|
||||||
|
// JSON.stringify(request, null, 2)
|
||||||
|
// );
|
||||||
|
// return request;
|
||||||
|
// });
|
||||||
axios.interceptors.response.use((response) => {
|
axios.interceptors.response.use((response) => {
|
||||||
console.log(new Date(), 'Response:', {
|
console.log(new Date(), 'Response:', {
|
||||||
request: {
|
request: {
|
||||||
@@ -242,21 +245,26 @@ export default abstract class BaseRestClient {
|
|||||||
isPublicApi
|
isPublicApi
|
||||||
);
|
);
|
||||||
|
|
||||||
options.headers['X-BAPI-SIGN-TYPE'] = 2;
|
const headers = {
|
||||||
options.headers['X-BAPI-API-KEY'] = this.key;
|
'X-BAPI-SIGN-TYPE': 2,
|
||||||
options.headers['X-BAPI-TIMESTAMP'] = signResult.timestamp;
|
'X-BAPI-API-KEY': this.key,
|
||||||
options.headers['X-BAPI-SIGN'] = signResult.sign;
|
'X-BAPI-TIMESTAMP': signResult.timestamp,
|
||||||
options.headers['X-BAPI-RECV-WINDOW'] = signResult.recvWindow;
|
'X-BAPI-SIGN': signResult.sign,
|
||||||
|
'X-BAPI-RECV-WINDOW': signResult.recvWindow,
|
||||||
|
...options.headers,
|
||||||
|
};
|
||||||
|
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
|
headers,
|
||||||
params: signResult.originalParams,
|
params: signResult.originalParams,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
|
headers,
|
||||||
data: signResult.originalParams,
|
data: signResult.originalParams,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -391,10 +399,14 @@ export default abstract class BaseRestClient {
|
|||||||
: JSON.stringify(res.originalParams);
|
: JSON.stringify(res.originalParams);
|
||||||
|
|
||||||
const paramsStr = timestamp + key + recvWindow + signRequestParams;
|
const paramsStr = timestamp + key + recvWindow + signRequestParams;
|
||||||
|
|
||||||
res.sign = await signMessage(paramsStr, this.secret);
|
res.sign = await signMessage(paramsStr, this.secret);
|
||||||
res.serializedParams = signRequestParams;
|
res.serializedParams = signRequestParams;
|
||||||
|
|
||||||
// console.log('sign req: ', paramsStr);
|
// console.log('sign req: ', {
|
||||||
|
// req: paramsStr,
|
||||||
|
// sign: res.sign,
|
||||||
|
// });
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,10 @@ describe('Private Linear REST API GET Endpoints', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('getActiveOrderList()', async () => {
|
it('getActiveOrderList()', async () => {
|
||||||
expect(await api.getActiveOrderList({ symbol: symbol })).toMatchObject(
|
expect(await api.getActiveOrderList({ symbol: symbol })).toMatchObject({
|
||||||
successResponseObject()
|
...successResponseObject(),
|
||||||
);
|
// ret_msg: 'ok',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('queryActiveOrder()', async () => {
|
it('queryActiveOrder()', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user