v3.5.8: feat() easier env-controlled HTTP traces. Add missing properties for asset v5 types.

This commit is contained in:
tiagosiebler
2023-05-01 12:11:09 +01:00
parent 2253329a8b
commit 70adfd646a
4 changed files with 20 additions and 7 deletions

View File

@@ -305,9 +305,11 @@ See [websocket-client.ts](./src/websocket-client.ts) for further information.
--- ---
## Customise Logging ## 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. ### Customise logging
Pass a custom logger (or mutate the imported DefaultLogger class) which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired, as in the example below:
```javascript ```javascript
const { WebsocketClient, DefaultLogger } = require('bybit-api'); const { WebsocketClient, DefaultLogger } = require('bybit-api');
@@ -321,6 +323,10 @@ const customLogger = {
const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, customLogger); const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, customLogger);
``` ```
### Debug HTTP requests
In rare situations, you may want to see the raw HTTP requets being built as well as the API response. These can be enabled by setting the `BYBITTRACE` env var to `true`.
## Browser Usage ## Browser Usage
Build a bundle using webpack: Build a bundle using webpack:

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.5.7", "version": "3.5.8",
"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",

View File

@@ -39,6 +39,7 @@ export interface GetAccountCoinBalanceParamsV5 {
accountType: AccountTypeV5; accountType: AccountTypeV5;
coin: string; coin: string;
withBonus?: number; withBonus?: number;
withTransferSafeAmount?: 0 | 1;
} }
export interface GetInternalTransferParamsV5 { export interface GetInternalTransferParamsV5 {
@@ -119,6 +120,7 @@ export interface WithdrawParamsV5 {
address: string; address: string;
tag?: string; tag?: string;
amount: string; amount: string;
timestamp: number;
forceChain?: number; forceChain?: number;
accountType?: 'SPOT' | 'FUND'; accountType?: 'SPOT' | 'FUND';
} }

View File

@@ -11,11 +11,12 @@ import {
} from './requestUtils'; } from './requestUtils';
import { signMessage } from './node-support'; import { signMessage } from './node-support';
if ( const ENABLE_HTTP_TRACE =
typeof process === 'object' && typeof process === 'object' &&
typeof process.env === 'object' && typeof process.env === 'object' &&
process.env.BYBITTRACE process.env.BYBITTRACE;
) {
if (ENABLE_HTTP_TRACE) {
// axios.interceptors.request.use((request) => { // axios.interceptors.request.use((request) => {
// console.log( // console.log(
// new Date(), // new Date(),
@@ -209,7 +210,7 @@ export default abstract class BaseRestClient {
if (this.options.syncTimeBeforePrivateRequests) { if (this.options.syncTimeBeforePrivateRequests) {
this.timeOffset = await this.fetchTimeOffset(); this.timeOffset = await this.fetchTimeOffset();
} }
return this.signRequest(params || {}, method, signMethod); return this.signRequest(params || {}, method, signMethod);
} }
@@ -314,6 +315,10 @@ export default abstract class BaseRestClient {
isPublicApi, isPublicApi,
); );
if (ENABLE_HTTP_TRACE) {
console.log('full request: ', options);
}
// Dispatch request // Dispatch request
return axios(options) return axios(options)
.then((response) => { .then((response) => {