Skip to content

Commit e15b7b4

Browse files
author
ilinikh.a1
committed
feat: draft
1 parent 4f044e3 commit e15b7b4

36 files changed

+385
-680
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ module.exports = {
2121
'@typescript-eslint/explicit-function-return-type': 'off',
2222
'@typescript-eslint/explicit-module-boundary-types': 'off',
2323
'@typescript-eslint/no-explicit-any': 'off',
24+
'@typescript-eslint/no-misused-new': 'off'
2425
},
2526
};

examples/index.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { ApiAccount } from '@app/bingx/account/api-account';
2+
import { BingxRequestInterface } from '@app/bingx/endpoints/bingx-request.interface';
3+
import { BingxResponseInterface } from '@app/bingx/endpoints/bingx-response.interface';
4+
import { EndpointInterface } from '@app/bingx/endpoints/endpoint.interface';
5+
import { BingxRequest } from '@app/bingx/endpoints/bingx-request';
6+
import { BingxGenerateListenKeyEndpoint } from '@app/bingx/endpoints/bingx-generate-listen-key-endpoint';
7+
8+
async function examples() {
9+
/** Basic usage **/
10+
const account = new ApiAccount('aaaa', 'ddd');
11+
12+
const listenKeyResponseBingxResponse = await new BingxRequest(
13+
new BingxGenerateListenKeyEndpoint(account),
14+
).getResponse();
15+
16+
console.log(listenKeyResponseBingxResponse);
17+
18+
/**
19+
* {
20+
* code: 0,
21+
* msg: "success",
22+
* data: {
23+
* listenKey: 'dawddawdda'
24+
* }
25+
* }
26+
*/
27+
28+
/** Override Request Class **/
29+
class RmqCustomRequest<T> implements BingxRequestInterface<T> {
30+
constructor(private readonly endpoint: EndpointInterface<T>) {}
31+
32+
async getEndpoint(): Promise<Readonly<EndpointInterface<T>>> {
33+
return this.endpoint;
34+
}
35+
36+
getResponse(): Promise<Readonly<BingxResponseInterface<T>>> {
37+
/**
38+
* Logic to send request via rmq
39+
*/
40+
41+
return {} as never;
42+
}
43+
}
44+
45+
const response = await new RmqCustomRequest(
46+
new BingxGenerateListenKeyEndpoint(account),
47+
).getResponse();
48+
49+
console.log(response);
50+
/**
51+
* {
52+
* code: 0,
53+
* msg: "success",
54+
* data: {
55+
* listenKey: 'dawddawdda'
56+
* }
57+
* }
58+
*/
59+
}
60+
61+
examples().then();

package-lock.json

+107-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
"test:e2e": "jest --config ./test/jest-e2e.json"
2121
},
2222
"dependencies": {
23+
"@nestjs/axios": "^3.0.0",
2324
"@nestjs/common": "^10.0.0",
2425
"@nestjs/core": "^10.0.0",
2526
"@nestjs/platform-express": "^10.0.0",
27+
"axios": "^1.5.1",
28+
"axios-request-throttle": "^1.0.0",
2629
"reflect-metadata": "^0.1.13",
27-
"rxjs": "^7.8.1"
30+
"rxjs": "^7.8.1",
31+
"ws": "^8.14.2"
2832
},
2933
"devDependencies": {
3034
"@nestjs/cli": "^10.0.0",
@@ -34,6 +38,7 @@
3438
"@types/jest": "^29.5.2",
3539
"@types/node": "^20.3.1",
3640
"@types/supertest": "^2.0.12",
41+
"@types/ws": "^8.5.6",
3742
"@typescript-eslint/eslint-plugin": "^6.0.0",
3843
"@typescript-eslint/parser": "^6.0.0",
3944
"eslint": "^8.42.0",

src/bingx/bingx.module.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Module } from '@nestjs/common';
22
import { HttpModule, HttpService } from '@nestjs/axios';
3-
import { BingxTradeService } from '@app/bingx/services/bingx.trade.service';
43
import { BingxListenKeyService } from '@app/bingx/services/bingx-listen-key.service';
54
import { BingxWebsocketClient } from '@app/bingx/websocket/bingx-websocket.client';
65
import axiosThrottle from 'axios-request-throttle';
@@ -18,13 +17,11 @@ import { BingxMarketWebsocketClient } from '@app/bingx/websocket/bingx-market-we
1817
}),
1918
],
2019
providers: [
21-
BingxTradeService,
2220
BingxListenKeyService,
2321
BingxWebsocketClient,
2422
BingxMarketWebsocketClient,
2523
],
2624
exports: [
27-
BingxTradeService,
2825
BingxListenKeyService,
2926
BingxWebsocketClient,
3027
BingxMarketWebsocketClient,
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import { Endpoint } from '@app/bingx/request/endpoint';
2-
import { EndpointInterface } from '@app/bingx/request/endpoint.interface';
1+
import { Endpoint } from '@app/bingx/endpoints/endpoint';
2+
import { EndpointInterface } from '@app/bingx/endpoints/endpoint.interface';
33
import { SignatureParametersInterface } from '@app/bingx/account/signature-parameters.interface';
4-
import { Throughput } from '@app/bingx/rate-limit/throughput';
54
import { DefaultSignatureParameters } from '@app/bingx/account/default-signature-parameters';
6-
import { MarketThroughput } from '@app/bingx/rate-limit/market-throughput';
75
import { AccountInterface } from '@app/bingx/account/account.interface';
86

9-
export class BingxCancelAllOrdersEndpoint
7+
export interface CancelAllOrdersData {
8+
success: unknown[];
9+
failed: unknown[];
10+
}
11+
12+
export class BingxCancelAllOrdersEndpoint<R = CancelAllOrdersData>
1013
extends Endpoint
11-
implements EndpointInterface
14+
implements EndpointInterface<R>
1215
{
13-
constructor(private readonly symbol: string, account: AccountInterface) {
16+
constructor(
17+
private readonly symbol: string,
18+
account: AccountInterface,
19+
) {
1420
super(account);
1521
}
1622

@@ -28,7 +34,5 @@ export class BingxCancelAllOrdersEndpoint
2834
return '/openApi/swap/v2/trade/allOpenOrders';
2935
}
3036

31-
throughput(): Throughput {
32-
return new MarketThroughput();
33-
}
37+
readonly t!: R;
3438
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { Endpoint } from '@app/bingx/request/endpoint';
2-
import { EndpointInterface } from '@app/bingx/request/endpoint.interface';
1+
import { Endpoint } from '@app/bingx/endpoints/endpoint';
2+
import { EndpointInterface } from '@app/bingx/endpoints/endpoint.interface';
33
import { SignatureParametersInterface } from '@app/bingx/account/signature-parameters.interface';
4-
import { Throughput } from '@app/bingx/rate-limit/throughput';
54
import { DefaultSignatureParameters } from '@app/bingx/account/default-signature-parameters';
6-
import { MarketThroughput } from '@app/bingx/rate-limit/market-throughput';
75

8-
export class BingxCloseAllPositionsEndpoint
6+
export interface BingxCloseAllPositionsData {
7+
success: number[];
8+
failed: number[];
9+
}
10+
11+
export class BingxCloseAllPositionsEndpoint<R = BingxCloseAllPositionsData>
912
extends Endpoint
10-
implements EndpointInterface
13+
implements EndpointInterface<R>
1114
{
15+
readonly t!: R;
1216
method(): 'get' | 'post' | 'put' | 'patch' | 'delete' {
1317
return 'post';
1418
}
@@ -20,8 +24,4 @@ export class BingxCloseAllPositionsEndpoint
2024
path(): string {
2125
return '/openApi/swap/v2/trade/closeAllPositions';
2226
}
23-
24-
throughput(): Throughput {
25-
return new MarketThroughput();
26-
}
2727
}

0 commit comments

Comments
 (0)