@@ -88,7 +88,8 @@ def __init__(
8888
8989 self ._dbn_queue : DBNQueue = DBNQueue (maxsize = DEFAULT_QUEUE_SIZE )
9090 self ._metadata : SessionMetadata = SessionMetadata ()
91- self ._user_callbacks : list [UserCallback ] = []
91+ self ._symbology_map : dict [int , str | int ] = {}
92+ self ._user_callbacks : list [UserCallback ] = [self ._map_symbol ]
9293 self ._user_streams : list [IO [bytes ]] = []
9394
9495 def factory () -> _SessionProtocol :
@@ -237,6 +238,23 @@ def port(self) -> int:
237238 """
238239 return self ._port
239240
241+ @property
242+ def symbology_map (self ) -> dict [int , str | int ]:
243+ """
244+ Return the symbology map for this client session. A symbol mapping is
245+ added when the client receives a SymbolMappingMsg.
246+
247+ This can be used to transform an `instrument_id` in a DBN record
248+ to the input symbology.
249+
250+ Returns
251+ -------
252+ dict[int, str | int]
253+ A mapping of the exchange's instrument_id to the subscription symbology.
254+
255+ """
256+ return self ._symbology_map
257+
240258 @property
241259 def ts_out (self ) -> bool :
242260 """
@@ -548,3 +566,11 @@ async def _shutdown(self) -> None:
548566 if self ._session is None :
549567 return
550568 await self ._session .wait_for_close ()
569+ self ._symbology_map .clear ()
570+
571+ def _map_symbol (self , record : DBNRecord ) -> None :
572+ if isinstance (record , databento_dbn .SymbolMappingMsg ):
573+ out_symbol = record .stype_out_symbol
574+ instrument_id = record .instrument_id
575+ self ._symbology_map [instrument_id ] = record .stype_out_symbol
576+ logger .info ("added symbology mapping %s to %d" , out_symbol , instrument_id )
0 commit comments