forked from singlesly/bingx-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbingx-request.ts
More file actions
41 lines (36 loc) · 1.33 KB
/
Copy pathbingx-request.ts
File metadata and controls
41 lines (36 loc) · 1.33 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { EndpointInterface } from 'bingx-api/bingx/endpoints/endpoint.interface';
import { lastValueFrom } from 'rxjs';
import { BingxRequestInterface } from 'bingx-api/bingx/endpoints/bingx-request.interface';
import { HttpService } from '@nestjs/axios';
import axios from 'axios';
import * as JSONBigNumber from 'json-bignumber';
import { axiosTransformResponse } from 'bingx-api/bingx/axios-transform-response/axios-transform-response';
export class BingxRequest<R> implements BingxRequestInterface<R> {
private readonly http = new HttpService(
axios.create({
baseURL: 'https://open-api.bingx.com',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
transformResponse: axiosTransformResponse,
}),
);
constructor(private readonly endpoint: EndpointInterface<R>) {}
async getResponse(): Promise<Readonly<R>> {
const response = await lastValueFrom(
this.http.request({
method: this.endpoint.method(),
params: {
...this.endpoint.parameters().asRecord(),
signature: this.endpoint.signature().toString(),
},
headers: this.endpoint.apiKey().asHeader(),
url: this.endpoint.path(),
}),
);
return response.data;
}
async getEndpoint(): Promise<Readonly<EndpointInterface<R>>> {
return this.endpoint;
}
}