using typeguards and removed useless logging

This commit is contained in:
Caius Citiriga
2023-05-10 20:48:02 +02:00
parent 75a97fc9d4
commit 4bf527bef8
6 changed files with 51 additions and 29 deletions

View File

@@ -43,6 +43,7 @@ import {
serializeParams,
} from './util';
import { RestClientV5 } from './rest-client-v5';
import { WebsocketTopicSubscriptionConfirmationEvent } from './types/ws-events/topic-subscription-confirmation';
const loggerCategory = { category: 'bybit-ws' };
@@ -1069,20 +1070,19 @@ export class WebsocketClient extends EventEmitter {
}
}
private updatePendingTopicSubscriptionStatus(wsKey: string, msg: any) {
const requestsIds = msg['req_id'] as string;
private updatePendingTopicSubscriptionStatus(
wsKey: string,
msg: WebsocketTopicSubscriptionConfirmationEvent,
) {
const requestsIds = msg.req_id as string;
const pendingTopicsSubscriptions = this.pendingTopicsSubscriptions.find(
(s) => s.wsKey === wsKey,
);
if (!pendingTopicsSubscriptions) {
throw new Error(
`Could not find "${wsKey}" within pending topics subscriptions.`,
);
}
const subscriptionSuccess = isTopicSubscriptionSuccess(msg);
if (!pendingTopicsSubscriptions) return;
const splitRequestsIds = requestsIds.split(',');
if (!subscriptionSuccess) {
if (!isTopicSubscriptionSuccess(msg)) {
splitRequestsIds.forEach((req_id) =>
pendingTopicsSubscriptions.failedTopicsSubscriptions.add(req_id),
);