From e7a351b5e3b81e591ba6a2bc04bfe5d9e9e3e776 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Sun, 11 Dec 2022 12:17:40 +0000 Subject: [PATCH] v1.0.2: fix header, misc cleaning --- package.json | 2 +- src/util/BaseRestClient.ts | 38 ++++++++------------------------------ 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index c00505f..dc3d7b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitget-api", - "version": "1.0.1", + "version": "1.0.2", "description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 19ba4c7..2c34d85 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -1,5 +1,4 @@ import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; -import { API_ERROR_CODE } from '../constants/enum'; import { RestClientType } from '../types'; import { signMessage } from './node-support'; @@ -8,30 +7,7 @@ import { serializeParams, getRestBaseUrl, } from './requestUtils'; - -// axios.interceptors.request.use((request) => { -// console.log( -// new Date(), -// 'Starting Request', -// JSON.stringify( -// { -// headers: request.headers, -// url: request.url, -// method: request.method, -// params: request.params, -// data: request.data, -// }, -// null, -// 2 -// ) -// ); -// return request; -// }); - -// axios.interceptors.response.use((response) => { -// console.log(new Date(), 'Response:', JSON.stringify(response, null, 2)); -// return response; -// }); +import { neverGuard } from './websocket-util'; interface SignedRequest { originalParams: T; @@ -48,7 +24,7 @@ interface UnsignedRequest { paramsWithSign: T; } -type SignMethod = 'keyInBody' | 'usdc' | 'bitget'; +type SignMethod = 'bitget'; export default abstract class BaseRestClient { private options: RestClientOptions; @@ -56,7 +32,6 @@ export default abstract class BaseRestClient { private globalRequestOptions: AxiosRequestConfig; private apiKey: string | undefined; private apiSecret: string | undefined; - private clientType: RestClientType; private apiPass: string | undefined; /** Defines the client type (affecting how requests & signatures behave) */ @@ -71,8 +46,6 @@ export default abstract class BaseRestClient { restOptions: RestClientOptions = {}, networkOptions: AxiosRequestConfig = {} ) { - this.clientType = this.getClientType(); - this.options = { recvWindow: 5000, /** Throw errors if any request params are empty */ @@ -86,7 +59,7 @@ export default abstract class BaseRestClient { // custom request options based on axios specs - see: https://github.com/axios/axios#request-config ...networkOptions, headers: { - 'X-CHANNEL-CODE': '3tem', + 'X-CHANNEL-API-CODE': '3tem', 'Content-Type': 'application/json', locale: 'en-US', }, @@ -257,6 +230,11 @@ export default abstract class BaseRestClient { return res; } + console.error( + new Date(), + neverGuard(signMethod, `Unhandled sign method: "${signMessage}"`) + ); + return res; }