Skip to content

Commit

Permalink
test: Add 100% code coverage for Lightstreamer API
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Feb 3, 2021
1 parent 4ec6473 commit a72c87a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lightstreamer/LightstreamerAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ export class LightstreamerAPI {

constructor(private readonly auth: Authorization) {}

private createLightStream(): void {
private createLightStream(): LightstreamerClient {
if (!this.lightstream) {
this.lightstream = new LightstreamerClient(this.auth.lightstreamerEndpoint, '');
this.lightstream.connectionDetails.setUser(this.auth.username!);
this.lightstream.connectionDetails.setPassword(
`CST-${this.auth.clientSessionToken}|XST-${this.auth.securityToken}`
);
}

return this.lightstream;
}

subscribeCandles(
epicList: string[],
resolution: ChartResolution,
onCandleUpdate: (epic: string, candle: CandleStick) => void
): void {
this.createLightStream();
const lightstream = this.createLightStream();

const fields = [
ChartFields.BID_HIGH,
Expand All @@ -45,7 +47,7 @@ export class LightstreamerAPI {
];

if (this.candleSubscription && this.candleSubscription.isSubscribed) {
this.lightstream?.unsubscribe(this.candleSubscription);
lightstream.unsubscribe(this.candleSubscription);
}
const epics = epicList.map(x => `CHART:${x}:${resolution}`);
this.candleSubscription = new Subscription('MERGE', epics, fields);
Expand Down Expand Up @@ -83,7 +85,8 @@ export class LightstreamerAPI {
onCandleUpdate(epic, candle);
},
});
this.lightstream?.connect();
this.lightstream?.subscribe(this.candleSubscription);

lightstream.connect();
lightstream.subscribe(this.candleSubscription);
}
}

0 comments on commit a72c87a

Please sign in to comment.