forked from singlesly/bingx-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-account.ts
More file actions
32 lines (29 loc) · 935 Bytes
/
Copy pathapi-account.ts
File metadata and controls
32 lines (29 loc) · 935 Bytes
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
import { AccountInterface } from 'bingx-api/bingx/account/account.interface';
import { SignatureParametersInterface } from 'bingx-api/bingx/account/signature-parameters.interface';
import { SignatureInterface } from 'bingx-api/bingx/account/signature.interface';
import * as crypto from 'crypto';
export class ApiAccount implements AccountInterface {
constructor(
private readonly apiKey: string,
private readonly secretKey: string,
) {}
getApiKey(): string {
return this.apiKey;
}
sign(parameters: SignatureParametersInterface): SignatureInterface {
const message = Object.entries(parameters.asRecord())
.map(([k, v]) => `${k}=${v}`)
.join('&');
return {
toString: () => {
return crypto
.createHmac('sha256', this.secretKey)
.update(message)
.digest('hex');
},
secretKey: () => {
return this.secretKey;
},
};
}
}