diff --git a/src/bingx-client/services/listen-key.service.spec.ts b/src/bingx-client/services/listen-key.service.spec.ts new file mode 100644 index 0000000..3b38689 --- /dev/null +++ b/src/bingx-client/services/listen-key.service.spec.ts @@ -0,0 +1,25 @@ +import { ApiAccount } from 'bingx-api/bingx/account/api-account'; +import { BingxDeleteListenKeyEndpoint } from 'bingx-api/bingx/endpoints/bingx-delete-listen-key-endpoint'; +import { RequestExecutorInterface } from 'bingx-api/bingx/request-executor/request-executor.interface'; +import { ListenKeyService } from 'bingx-api/bingx-client/services/listen-key.service'; + +describe('listen key service', () => { + it('must delete listen key', async () => { + const account = new ApiAccount('api-key', 'secret-key'); + const requestExecutor: RequestExecutorInterface = { + execute: jest.fn().mockResolvedValue(undefined), + }; + const service = new ListenKeyService(requestExecutor); + + await service.deleteListenKey(account, 'listen-key'); + + expect(requestExecutor.execute).toHaveBeenCalledTimes(1); + const endpoint = (requestExecutor.execute as jest.Mock).mock.calls[0][0]; + expect(endpoint).toBeInstanceOf(BingxDeleteListenKeyEndpoint); + expect(endpoint.method()).toBe('delete'); + expect(endpoint.path()).toBe('/openApi/user/auth/userDataStream'); + expect(endpoint.parameters().asRecord()).toMatchObject({ + listenKey: 'listen-key', + }); + }); +}); diff --git a/src/bingx-client/services/listen-key.service.ts b/src/bingx-client/services/listen-key.service.ts index 6535d93..c5386fe 100644 --- a/src/bingx-client/services/listen-key.service.ts +++ b/src/bingx-client/services/listen-key.service.ts @@ -1,4 +1,5 @@ import { AccountInterface } from 'bingx-api/bingx/account/account.interface'; +import { BingxDeleteListenKeyEndpoint } from 'bingx-api/bingx/endpoints/bingx-delete-listen-key-endpoint'; import { BingxGenerateListenKeyEndpoint } from 'bingx-api/bingx/endpoints/bingx-generate-listen-key-endpoint'; import { BingxGenerateListenKeyResponse } from 'bingx-api/bingx/endpoints/bingx-generate-listen-key-response'; import { RequestExecutorInterface } from 'bingx-api/bingx/request-executor/request-executor.interface'; @@ -13,4 +14,13 @@ export class ListenKeyService { new BingxGenerateListenKeyEndpoint(account), ); } + + async deleteListenKey( + account: AccountInterface, + listenKey: string, + ): Promise { + return this.requestExecutor.execute( + new BingxDeleteListenKeyEndpoint(listenKey, account), + ); + } } diff --git a/src/bingx/endpoints/bingx-delete-listen-key-endpoint.ts b/src/bingx/endpoints/bingx-delete-listen-key-endpoint.ts new file mode 100644 index 0000000..129517e --- /dev/null +++ b/src/bingx/endpoints/bingx-delete-listen-key-endpoint.ts @@ -0,0 +1,33 @@ +import { AccountInterface } from 'bingx-api/bingx/account/account.interface'; +import { DefaultSignatureParameters } from 'bingx-api/bingx/account/default-signature-parameters'; +import { SignatureParametersInterface } from 'bingx-api/bingx/account/signature-parameters.interface'; +import { EndpointInterface } from 'bingx-api/bingx/endpoints/endpoint.interface'; +import { Endpoint } from 'bingx-api/bingx/endpoints/endpoint'; + +export class BingxDeleteListenKeyEndpoint + extends Endpoint + implements EndpointInterface +{ + constructor( + private readonly listenKey: string, + account: AccountInterface, + ) { + super(account); + } + + method(): 'get' | 'post' | 'put' | 'patch' | 'delete' { + return 'delete'; + } + + parameters(): SignatureParametersInterface { + return new DefaultSignatureParameters({ + listenKey: this.listenKey, + }); + } + + path(): string { + return '/openApi/user/auth/userDataStream'; + } + + readonly t!: R; +} diff --git a/src/bingx/endpoints/index.ts b/src/bingx/endpoints/index.ts index 6866f8b..eab3777 100644 --- a/src/bingx/endpoints/index.ts +++ b/src/bingx/endpoints/index.ts @@ -1,5 +1,6 @@ export * from './bingx-cancel-all-orders-endpoint'; export * from './bingx-close-all-positions-endpoint'; +export * from './bingx-delete-listen-key-endpoint'; export * from './bingx-generate-listen-key-endpoint'; export * from './bingx-generate-listen-key-response'; export * from './bingx-get-perpetual-swap-account-asset-endpoint';