-
Notifications
You must be signed in to change notification settings - Fork 4
/
private_api_request.ts
25 lines (21 loc) 路 1.46 KB
/
private_api_request.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { baseAxiosRequestInterceptor, baseAxiosRequestErrorInterceptor, baseAxiosResponseInterceptor, baseAxiosResponseErrorInterceptor } from '../../base_axios_config'
import debugHelper from '../../util/debug_helper'
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
import { hitbtcAxiosConfig } from '../../hitbtc/hitbtc_axios_config'
const { debug } = debugHelper(__filename)
export const createHitBTCPrivateApiClient = (apikey = process.env.HITBTC_API_KEY || '', apiSecret = process.env.HITBTC_API_SECRET || ''): AxiosInstance => {
const privateApiClient: AxiosInstance = axios.create(hitbtcAxiosConfig)
privateApiClient.defaults.headers.Authorization = 'Basic ' + Buffer.from(`${apikey}:${apiSecret}`).toString('base64')
privateApiClient.interceptors.request.use(baseAxiosRequestInterceptor, baseAxiosRequestErrorInterceptor)
privateApiClient.interceptors.response.use(baseAxiosResponseInterceptor, baseAxiosResponseErrorInterceptor)
return privateApiClient
}
let defaultClient = createHitBTCPrivateApiClient()
export const hitbtcPrivateApiRequest = async ({ url, method, data, params }: AxiosRequestConfig): Promise<any> => {
const { data: hitBTCresponse } = await defaultClient.request({ url, method, params, data }) || {}
debug({ hitBTCresponse })
return hitBTCresponse
}
export const updateHitBTCDefaultClient = (apikey: string, apiSecret: string): void => {
defaultClient = createHitBTCPrivateApiClient(apikey, apiSecret)
}