1- import type { ConnectionManager } from '../connection-manager' ;
2- import { TypedEventEmitter } from '../../utils/event-emitter' ;
3- import type { Quote , MarketTrade , MarketDepth , MarketHubEvents } from './types' ;
1+ import type { ConnectionManager } from "../connection-manager" ;
2+ import { TypedEventEmitter } from "../../utils/event-emitter" ;
3+ import type {
4+ MarketQuote ,
5+ MarketTrade ,
6+ MarketDepth ,
7+ MarketHubEvents ,
8+ } from "./types" ;
49
510export class MarketHub extends TypedEventEmitter < MarketHubEvents > {
611 private subscribedQuotes = new Set < string > ( ) ;
@@ -14,22 +19,25 @@ export class MarketHub extends TypedEventEmitter<MarketHubEvents> {
1419
1520 private setupEventHandlers ( ) : void {
1621 this . connectionManager . onMarketConnection ( ( connection ) => {
17- connection . on ( 'GatewayQuote' , ( contractId : string , data : Quote [ ] ) => {
18- this . emit ( 'quote' , { contractId, data } ) ;
19- } ) ;
22+ connection . on (
23+ "GatewayQuote" ,
24+ ( contractId : string , data : MarketQuote [ ] ) => {
25+ this . emit ( "quote" , { contractId, data } ) ;
26+ } ,
27+ ) ;
2028
2129 connection . on (
22- ' GatewayTrade' ,
30+ " GatewayTrade" ,
2331 ( contractId : string , data : MarketTrade [ ] ) => {
24- this . emit ( ' trade' , { contractId, data } ) ;
25- }
32+ this . emit ( " trade" , { contractId, data } ) ;
33+ } ,
2634 ) ;
2735
2836 connection . on (
29- ' GatewayDepth' ,
37+ " GatewayDepth" ,
3038 ( contractId : string , data : MarketDepth [ ] ) => {
31- this . emit ( ' depth' , { contractId, data } ) ;
32- }
39+ this . emit ( " depth" , { contractId, data } ) ;
40+ } ,
3341 ) ;
3442 } ) ;
3543 }
@@ -53,42 +61,42 @@ export class MarketHub extends TypedEventEmitter<MarketHubEvents> {
5361 async subscribeQuotes ( contractId : string ) : Promise < void > {
5462 if ( this . subscribedQuotes . has ( contractId ) ) return ;
5563 const connection = this . connectionManager . marketConnection ;
56- await connection . invoke ( ' SubscribeContractQuotes' , contractId ) ;
64+ await connection . invoke ( " SubscribeContractQuotes" , contractId ) ;
5765 this . subscribedQuotes . add ( contractId ) ;
5866 }
5967
6068 async unsubscribeQuotes ( contractId : string ) : Promise < void > {
6169 if ( ! this . subscribedQuotes . has ( contractId ) ) return ;
6270 const connection = this . connectionManager . marketConnection ;
63- await connection . invoke ( ' UnsubscribeContractQuotes' , contractId ) ;
71+ await connection . invoke ( " UnsubscribeContractQuotes" , contractId ) ;
6472 this . subscribedQuotes . delete ( contractId ) ;
6573 }
6674
6775 async subscribeTrades ( contractId : string ) : Promise < void > {
6876 if ( this . subscribedTrades . has ( contractId ) ) return ;
6977 const connection = this . connectionManager . marketConnection ;
70- await connection . invoke ( ' SubscribeContractTrades' , contractId ) ;
78+ await connection . invoke ( " SubscribeContractTrades" , contractId ) ;
7179 this . subscribedTrades . add ( contractId ) ;
7280 }
7381
7482 async unsubscribeTrades ( contractId : string ) : Promise < void > {
7583 if ( ! this . subscribedTrades . has ( contractId ) ) return ;
7684 const connection = this . connectionManager . marketConnection ;
77- await connection . invoke ( ' UnsubscribeContractTrades' , contractId ) ;
85+ await connection . invoke ( " UnsubscribeContractTrades" , contractId ) ;
7886 this . subscribedTrades . delete ( contractId ) ;
7987 }
8088
8189 async subscribeDepth ( contractId : string ) : Promise < void > {
8290 if ( this . subscribedDepth . has ( contractId ) ) return ;
8391 const connection = this . connectionManager . marketConnection ;
84- await connection . invoke ( ' SubscribeContractMarketDepth' , contractId ) ;
92+ await connection . invoke ( " SubscribeContractMarketDepth" , contractId ) ;
8593 this . subscribedDepth . add ( contractId ) ;
8694 }
8795
8896 async unsubscribeDepth ( contractId : string ) : Promise < void > {
8997 if ( ! this . subscribedDepth . has ( contractId ) ) return ;
9098 const connection = this . connectionManager . marketConnection ;
91- await connection . invoke ( ' UnsubscribeContractMarketDepth' , contractId ) ;
99+ await connection . invoke ( " UnsubscribeContractMarketDepth" , contractId ) ;
92100 this . subscribedDepth . delete ( contractId ) ;
93101 }
94102}
0 commit comments