Merge pull request #2 from tiagosiebler/updates
v1.0.2: fix header, misc cleaning
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bitget-api",
|
"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.",
|
"description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
||||||
import { API_ERROR_CODE } from '../constants/enum';
|
|
||||||
import { RestClientType } from '../types';
|
import { RestClientType } from '../types';
|
||||||
|
|
||||||
import { signMessage } from './node-support';
|
import { signMessage } from './node-support';
|
||||||
@@ -8,30 +7,7 @@ import {
|
|||||||
serializeParams,
|
serializeParams,
|
||||||
getRestBaseUrl,
|
getRestBaseUrl,
|
||||||
} from './requestUtils';
|
} from './requestUtils';
|
||||||
|
import { neverGuard } from './websocket-util';
|
||||||
// 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;
|
|
||||||
// });
|
|
||||||
|
|
||||||
interface SignedRequest<T extends object | undefined = {}> {
|
interface SignedRequest<T extends object | undefined = {}> {
|
||||||
originalParams: T;
|
originalParams: T;
|
||||||
@@ -48,7 +24,7 @@ interface UnsignedRequest<T extends object | undefined = {}> {
|
|||||||
paramsWithSign: T;
|
paramsWithSign: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignMethod = 'keyInBody' | 'usdc' | 'bitget';
|
type SignMethod = 'bitget';
|
||||||
|
|
||||||
export default abstract class BaseRestClient {
|
export default abstract class BaseRestClient {
|
||||||
private options: RestClientOptions;
|
private options: RestClientOptions;
|
||||||
@@ -56,7 +32,6 @@ export default abstract class BaseRestClient {
|
|||||||
private globalRequestOptions: AxiosRequestConfig;
|
private globalRequestOptions: AxiosRequestConfig;
|
||||||
private apiKey: string | undefined;
|
private apiKey: string | undefined;
|
||||||
private apiSecret: string | undefined;
|
private apiSecret: string | undefined;
|
||||||
private clientType: RestClientType;
|
|
||||||
private apiPass: string | undefined;
|
private apiPass: string | undefined;
|
||||||
|
|
||||||
/** Defines the client type (affecting how requests & signatures behave) */
|
/** Defines the client type (affecting how requests & signatures behave) */
|
||||||
@@ -71,8 +46,6 @@ export default abstract class BaseRestClient {
|
|||||||
restOptions: RestClientOptions = {},
|
restOptions: RestClientOptions = {},
|
||||||
networkOptions: AxiosRequestConfig = {}
|
networkOptions: AxiosRequestConfig = {}
|
||||||
) {
|
) {
|
||||||
this.clientType = this.getClientType();
|
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
recvWindow: 5000,
|
recvWindow: 5000,
|
||||||
/** Throw errors if any request params are empty */
|
/** 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
|
// custom request options based on axios specs - see: https://github.com/axios/axios#request-config
|
||||||
...networkOptions,
|
...networkOptions,
|
||||||
headers: {
|
headers: {
|
||||||
'X-CHANNEL-CODE': '3tem',
|
'X-CHANNEL-API-CODE': '3tem',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
locale: 'en-US',
|
locale: 'en-US',
|
||||||
},
|
},
|
||||||
@@ -257,6 +230,11 @@ export default abstract class BaseRestClient {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
new Date(),
|
||||||
|
neverGuard(signMethod, `Unhandled sign method: "${signMessage}"`)
|
||||||
|
);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user