1- import { OpenfeedGatewayMessage , Result , SubscriptionType } from "@gen/openfeed_api" ;
1+ import { OpenfeedGatewayMessage , Result } from "@gen/openfeed_api" ;
22import { InstrumentDefinition } from "@gen/openfeed_instrument" ;
33import Long from "long" ;
44import { ActionType , HeartBeat } from "@gen/openfeed" ;
@@ -11,9 +11,9 @@ const IDGetters: ((msg: OpenfeedGatewayMessage) => Long | undefined)[] = [
1111 ( msg ) => msg . volumeAtPrice ?. marketId ,
1212] ;
1313export class OpenFeedListeners {
14- private readonly instrumentByMarketId : Map < string , [ InstrumentDefinition ?, [ string , SubscriptionType ] [ ] ?] > = new Map <
14+ private readonly instrumentByMarketId : Map < string , [ InstrumentDefinition ?, [ string , string ] [ ] ?] > = new Map <
1515 string ,
16- [ InstrumentDefinition ?, [ string , SubscriptionType ] [ ] ?]
16+ [ InstrumentDefinition ?, [ string , string ] [ ] ?]
1717 > ( ) ;
1818
1919 constructor ( ) {
@@ -22,39 +22,44 @@ export class OpenFeedListeners {
2222
2323 private addDetails = ( message : OpenfeedGatewayMessage ) => {
2424 let def : InstrumentDefinition | undefined ;
25- let symbols : [ string , SubscriptionType ] [ ] | undefined ;
25+ let symbols : [ string , string ] [ ] | undefined ;
2626
2727 const getInstrumentDefinition = ( marketId : Long ) => {
2828 const res = this . instrumentByMarketId . get ( marketId . toString ( ) ) ;
2929
3030 return res ?? [ undefined , undefined ] ;
3131 } ;
3232
33- const includesSymbolSubscription = ( arr : [ string , SubscriptionType ] [ ] , item : [ string , SubscriptionType ] ) => {
34- return arr . some ( ( [ symbol , type ] ) => symbol === item [ 0 ] && type === item [ 1 ] ) ;
33+ const includesSymbolSubscription = ( arr : [ string , string ] [ ] , item : [ string , string ] ) => {
34+ return arr . some ( ( [ symbol , correlationId ] ) => symbol === item [ 0 ] && correlationId === item [ 1 ] ) ;
3535 } ;
3636
3737 if ( message . subscriptionResponse ) {
38- const { marketId, symbol, unsubscribe, status, subscriptionType } = message . subscriptionResponse ;
38+ const { marketId, symbol, unsubscribe, status, correlationId } = message . subscriptionResponse ;
39+ const corIdStr = correlationId . toString ( ) ;
3940 if ( marketId !== Long . ZERO ) {
4041 [ def , symbols ] = getInstrumentDefinition ( marketId ) ;
4142 if ( status ?. result === Result . SUCCESS ) {
42- const currentEntry : [ string , SubscriptionType ] = [ symbol , subscriptionType ] ;
43+ const currentEntry : [ string , string ] = [ symbol , corIdStr ] ;
44+
4345 if ( ! unsubscribe ) {
4446 if ( ! symbols ) {
4547 symbols = [ currentEntry ] ;
4648 } else if ( ! includesSymbolSubscription ( symbols , currentEntry ) ) {
4749 symbols = [ ...symbols , currentEntry ] ;
4850 }
51+ this . instrumentByMarketId . set ( marketId . toString ( ) , [ def , symbols ] ) ;
4952 } else {
53+ let symbolsToSave : [ string , string ] [ ] | undefined ;
5054 if ( symbols ) {
51- symbols = symbols . filter ( ( [ s , t ] ) => ! ( s === symbol && t === subscriptionType ) ) ;
55+ symbolsToSave = symbols . filter ( ( [ s , t ] ) => ! ( s === symbol && t === corIdStr ) ) ;
5256 }
53- if ( ! symbols ) {
57+ if ( ! symbolsToSave ?. length ) {
5458 this . instrumentByMarketId . delete ( marketId . toString ( ) ) ;
59+ } else {
60+ this . instrumentByMarketId . set ( marketId . toString ( ) , [ def , symbolsToSave ] ) ;
5561 }
5662 }
57- this . instrumentByMarketId . set ( marketId . toString ( ) , [ def , symbols ] ) ;
5863 }
5964 }
6065 } else if ( message . instrumentDefinition ) {
0 commit comments