@@ -65,7 +65,7 @@ def stop(self):
6565 def add_heartbeat_subscription (self , callback ):
6666 """Subscribe to [Heartbeat] messages (keep alive)
6767
68- [Heartbeat]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.HeartBeat
68+ [Heartbeat]: https://docs.barchart.com/openfeed/#/proto?id=heartbeat
6969 """
7070 self .heartbeat_handlers .append (callback )
7171
@@ -74,7 +74,7 @@ def add_heartbeat_subscription(self, callback):
7474 def add_symbol_subscription (self , symbol : Union [str , list ], callback , service = "REAL_TIME" , subscription_type = ["QUOTE" ], snapshot_interval_seconds = 60 ):
7575 """Subscribe to [Market Data] by Barchart Symbols
7676
77- Complete list of [SubscriptionTypes]. List of [Service] types.
77+ Complete list of [SubscriptionTypes]. List of [Service] types. List of [InstrumentTypes].
7878
7979 Parameters
8080 ----------
@@ -84,10 +84,13 @@ def add_symbol_subscription(self, symbol: Union[str, list], callback, service="R
8484 Your callback function for Market Data messages
8585 subscription_type: list, optional
8686 Default is ['QUOTE']. Can contain any of: 'ALL', 'QUOTE', 'QUOTE_PARTICIPANT', 'DEPTH_PRICE', 'DEPTH_ORDER', 'TRADES', 'OHLC'
87+ instrument_type: list, optional
88+ Spreads and Options must be explicitly requested. Can contain any of: 'SPREAD', 'OPTION', 'FUTURE', 'FOREX', 'EQUITY', 'INDEX', 'MUTUAL_FUND', 'MONEY_MARKET', 'MONEY_MARKET_FUND'
8789
88- [Market Data]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.MarketUpdate
89- [SubscriptionTypes]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.SubscriptionType
90- [Service]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.Service
90+ [Market Data]: https://docs.barchart.com/openfeed/#/proto?id=marketupdate
91+ [SubscriptionTypes]: https://docs.barchart.com/openfeed/#/proto?id=subscriptiontype
92+ [Service]: https://docs.barchart.com/openfeed/#/proto?id=service
93+ [InstrumentTypes]: https://docs.barchart.com/openfeed/#/proto?id=instrumentdefinitioninstrumenttype
9194 """
9295 symbols = []
9396
@@ -109,16 +112,16 @@ def add_symbol_subscription(self, symbol: Union[str, list], callback, service="R
109112
110113 return self
111114
112- def add_exchange_subscription (self , exchange : Union [str , list ], callback , service = "REAL_TIME" , subscription_type = ["QUOTE" ], snapshot_interval_seconds = 60 ):
115+ def add_exchange_subscription (self , exchange : Union [str , list ], callback , service = "REAL_TIME" , subscription_type = ["QUOTE" ], instrument_type = [], snapshot_interval_seconds = 60 ):
113116 """Subscribe to [Market Data] by Barchart Exchange code(s).
114117
115118 Complete list of [SubscriptionTypes]. List of [Service] types.
116119
117120 Note: your credentials must have the correct service level (FEED) for this operation.
118121
119- [Market Data]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.MarketUpdate
120- [SubscriptionTypes]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.SubscriptionType
121- [Service]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.Service
122+ [Market Data]: https://docs.barchart.com/openfeed/#/proto?id=marketupdate
123+ [SubscriptionTypes]: https://docs.barchart.com/openfeed/#/proto?id=subscriptiontype
124+ [Service]: https://docs.barchart.com/openfeed/#/proto?id=service
122125 """
123126 exchanges = []
124127
@@ -132,18 +135,18 @@ def add_exchange_subscription(self, exchange: Union[str, list], callback, servic
132135 self .exchange_handlers [exch ] = []
133136
134137 self .exchange_handlers [exch ].append (Listener (
135- exchange = exch , callback = callback , service = service , subscription_type = subscription_type , snapshot_interval_seconds = snapshot_interval_seconds ))
138+ exchange = exch , callback = callback , service = service , subscription_type = subscription_type , instrument_type = instrument_type , snapshot_interval_seconds = snapshot_interval_seconds ))
136139
137140 if self .token is not None :
138141 self ._send_message (
139- self .__create_subscription_request (exchanges = exchanges , service = service , subscription_type = subscription_type , snapshot_interval_seconds = snapshot_interval_seconds ))
142+ self .__create_subscription_request (exchanges = exchanges , service = service , subscription_type = subscription_type , instrument_type = instrument_type , snapshot_interval_seconds = snapshot_interval_seconds ))
140143
141144 return self
142145
143146 def request_available_exchanges (self , callback ):
144147 """Request a list of available [Exchanges] for subscription.
145148
146- [Exchanges]: https://github. com/openfeed-org/proto/blob/master/openfeed_api.proto#L159-L173
149+ [Exchanges]: https://docs.barchart. com/openfeed/#/openfeed_streaming?id=requesting-exchanges
147150 """
148151 rid = random .getrandbits (32 )
149152 req = self .__create_exchange_request (rid )
@@ -158,7 +161,7 @@ def request_available_exchanges(self, callback):
158161 def request_instruments_for_exchange (self , exchange , callback ):
159162 """Request a list of [Instrument Definitions] actively trading trading on an exchange.
160163
161- [Instrument Definitions]: https://openfeed-org.github.io/documentation/Message%20Specification/# openfeed_instrumentproto
164+ [Instrument Definitions]: https://docs.barchart.com/openfeed/#/proto?id= openfeed_instrumentproto
162165 """
163166
164167 rid = random .getrandbits (32 )
@@ -176,8 +179,8 @@ def request_instruments(self, callback, symbol=None, market_id=None, exchange=No
176179
177180 See [Instrument Request]
178181
179- [Instrument Definitions]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentDefinition
180- [Instrument Request]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentRequest
182+ [Instrument Definitions]: https://docs.barchart.com/openfeed/#/proto?id=openfeed_instrumentproto
183+ [Instrument Request]: https://docs.barchart.com/openfeed/#/proto?id=instrumentrequest
181184 """
182185
183186 rid = random .getrandbits (32 )
@@ -194,22 +197,22 @@ def request_instruments(self, callback, symbol=None, market_id=None, exchange=No
194197 def get_instrument_definitions (self ):
195198 """Returns a dict of Openfeed [Instrument Definitions] keyed by MarketID
196199
197- [Instrument Definitions]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentDefinition
200+ [Instrument Definitions]: https://docs.barchart.com/openfeed/#/proto?id=openfeed_instrumentproto
198201 """
199202 return self .instrument_definitions
200203
201204 def get_instrument_definition (self , id ):
202205 """Returns an [Instrument Definition] for a Market ID
203206
204- [Instrument Definition]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentDefinition
207+ [Instrument Definition]: https://docs.barchart.com/openfeed/#/proto?id=openfeed_instrumentproto
205208 """
206209 return self .instrument_definitions [id ].instrumentDefinition
207210
208211 def get_instrument_definition_by_symbol (self , symbol ):
209212 """Returns an [Instrument Definition] for a [Symbol] string
210213
211- [Instrument Definition]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentDefinition
212- [Symbol]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.InstrumentDefinition.Symbol
214+ [Instrument Definition]: https://docs.barchart.com/openfeed/#/proto?id=openfeed_instrumentproto
215+ [Symbol]: https://docs.barchart.com/openfeed/#/proto?id=instrumentdefinitionsymbol
213216 """
214217 return self .instruments_by_symbol [symbol ].instrumentDefinition
215218
@@ -459,7 +462,7 @@ def __send_existing_interest(self):
459462 listeners_by_service = interest [l .service ]
460463 if l .key () not in listeners_by_service :
461464 listeners_by_service [l .key ()] = Listener (
462- symbol = l .symbol , exchange = l .exchange , service = l .service , subscription_type = l .subscription_type , snapshot_interval_seconds = l .snapshot_interval_seconds )
465+ symbol = l .symbol , exchange = l .exchange , service = l .service , subscription_type = l .subscription_type , instrument_type = l . instrument_type , snapshot_interval_seconds = l .snapshot_interval_seconds )
463466 else :
464467 existing = listeners_by_service [l .key ()]
465468 existing .subscription_type = list (set (
@@ -469,13 +472,13 @@ def __send_existing_interest(self):
469472 for service in interest .keys ():
470473 for i in interest [service ].values ():
471474 self ._send_message (
472- self .__create_subscription_request (exchanges = i .exchanges (), symbols = i .symbols (), service = service , subscription_type = i .subscription_type , snapshot_interval_seconds = i .snapshot_interval_seconds ))
475+ self .__create_subscription_request (exchanges = i .exchanges (), symbols = i .symbols (), service = service , subscription_type = i .subscription_type , instrument_type = i . get_instrument_types (), snapshot_interval_seconds = i .snapshot_interval_seconds ))
473476
474477 # send other rpc requests
475478 for req in self .request_id_handlers .values ():
476479 req .send (self )
477480
478- def __create_subscription_request (self , exchanges = [], symbols = [], service = "REAL_TIME" , subscription_type = ["QUOTE" ], snapshot_interval_seconds = 60 ):
481+ def __create_subscription_request (self , exchanges = [], symbols = [], service = "REAL_TIME" , subscription_type = ["QUOTE" ], instrument_type = [], snapshot_interval_seconds = 60 ):
479482 requests = []
480483
481484 if len (exchanges ) > 0 :
@@ -484,7 +487,9 @@ def __create_subscription_request(self, exchanges=[], symbols=[], service="REAL_
484487 exchange = exch ,
485488 subscriptionType = [openfeed_api_pb2 .SubscriptionType .Value (
486489 t ) for t in subscription_type ],
487- snapshotIntervalSeconds = snapshot_interval_seconds
490+ snapshotIntervalSeconds = snapshot_interval_seconds ,
491+ instrumentType = [openfeed_instrument_pb2 .InstrumentDefinition .InstrumentType .Value (
492+ t ) for t in instrument_type ]
488493 ))
489494
490495 if len (symbols ) > 0 :
@@ -565,12 +570,13 @@ def __callback(self, callback, *args):
565570
566571
567572class Listener (object ):
568- def __init__ (self , symbol = "" , exchange = "" , callback = None , service = "REAL_TIME" , subscription_type = ["QUOTE" ], snapshot_interval_seconds = 60 ):
573+ def __init__ (self , symbol = "" , exchange = "" , callback = None , service = "REAL_TIME" , subscription_type = ["QUOTE" ], instrument_type = [], snapshot_interval_seconds = 60 ):
569574 self .symbol = symbol
570575 self .exchange = exchange
571576 self .callback = callback
572577 self .service = service
573578 self .subscription_type = subscription_type
579+ self .instrument_type = instrument_type
574580 self .snapshot_interval_seconds = snapshot_interval_seconds
575581
576582 def key (self ):
@@ -588,6 +594,11 @@ def exchanges(self):
588594 return [self .exchange ]
589595 return []
590596
597+ def get_instrument_types (self ):
598+ if len (self .exchange ) > 0 :
599+ return self .instrument_type
600+ return []
601+
591602 def has_same_interest (self , other ):
592603 return collections .Counter (self .subscription_type ) == collections .Counter (other .subscription_type )
593604
0 commit comments