@@ -65,7 +65,7 @@ def stop(self):
65
65
def add_heartbeat_subscription (self , callback ):
66
66
"""Subscribe to [Heartbeat] messages (keep alive)
67
67
68
- [Heartbeat]: https://openfeed-org.github.io/documentation/Message%20Specification/#org.openfeed.HeartBeat
68
+ [Heartbeat]: https://docs.barchart.com/openfeed/#/proto?id=heartbeat
69
69
"""
70
70
self .heartbeat_handlers .append (callback )
71
71
@@ -74,7 +74,7 @@ def add_heartbeat_subscription(self, callback):
74
74
def add_symbol_subscription (self , symbol : Union [str , list ], callback , service = "REAL_TIME" , subscription_type = ["QUOTE" ], snapshot_interval_seconds = 60 ):
75
75
"""Subscribe to [Market Data] by Barchart Symbols
76
76
77
- Complete list of [SubscriptionTypes]. List of [Service] types.
77
+ Complete list of [SubscriptionTypes]. List of [Service] types. List of [InstrumentTypes].
78
78
79
79
Parameters
80
80
----------
@@ -84,10 +84,13 @@ def add_symbol_subscription(self, symbol: Union[str, list], callback, service="R
84
84
Your callback function for Market Data messages
85
85
subscription_type: list, optional
86
86
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'
87
89
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
91
94
"""
92
95
symbols = []
93
96
@@ -109,16 +112,16 @@ def add_symbol_subscription(self, symbol: Union[str, list], callback, service="R
109
112
110
113
return self
111
114
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 ):
113
116
"""Subscribe to [Market Data] by Barchart Exchange code(s).
114
117
115
118
Complete list of [SubscriptionTypes]. List of [Service] types.
116
119
117
120
Note: your credentials must have the correct service level (FEED) for this operation.
118
121
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
122
125
"""
123
126
exchanges = []
124
127
@@ -132,18 +135,18 @@ def add_exchange_subscription(self, exchange: Union[str, list], callback, servic
132
135
self .exchange_handlers [exch ] = []
133
136
134
137
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 ))
136
139
137
140
if self .token is not None :
138
141
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 ))
140
143
141
144
return self
142
145
143
146
def request_available_exchanges (self , callback ):
144
147
"""Request a list of available [Exchanges] for subscription.
145
148
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
147
150
"""
148
151
rid = random .getrandbits (32 )
149
152
req = self .__create_exchange_request (rid )
@@ -158,7 +161,7 @@ def request_available_exchanges(self, callback):
158
161
def request_instruments_for_exchange (self , exchange , callback ):
159
162
"""Request a list of [Instrument Definitions] actively trading trading on an exchange.
160
163
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
162
165
"""
163
166
164
167
rid = random .getrandbits (32 )
@@ -176,8 +179,8 @@ def request_instruments(self, callback, symbol=None, market_id=None, exchange=No
176
179
177
180
See [Instrument Request]
178
181
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
181
184
"""
182
185
183
186
rid = random .getrandbits (32 )
@@ -194,22 +197,22 @@ def request_instruments(self, callback, symbol=None, market_id=None, exchange=No
194
197
def get_instrument_definitions (self ):
195
198
"""Returns a dict of Openfeed [Instrument Definitions] keyed by MarketID
196
199
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
198
201
"""
199
202
return self .instrument_definitions
200
203
201
204
def get_instrument_definition (self , id ):
202
205
"""Returns an [Instrument Definition] for a Market ID
203
206
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
205
208
"""
206
209
return self .instrument_definitions [id ].instrumentDefinition
207
210
208
211
def get_instrument_definition_by_symbol (self , symbol ):
209
212
"""Returns an [Instrument Definition] for a [Symbol] string
210
213
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
213
216
"""
214
217
return self .instruments_by_symbol [symbol ].instrumentDefinition
215
218
@@ -459,7 +462,7 @@ def __send_existing_interest(self):
459
462
listeners_by_service = interest [l .service ]
460
463
if l .key () not in listeners_by_service :
461
464
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 )
463
466
else :
464
467
existing = listeners_by_service [l .key ()]
465
468
existing .subscription_type = list (set (
@@ -469,13 +472,13 @@ def __send_existing_interest(self):
469
472
for service in interest .keys ():
470
473
for i in interest [service ].values ():
471
474
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 ))
473
476
474
477
# send other rpc requests
475
478
for req in self .request_id_handlers .values ():
476
479
req .send (self )
477
480
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 ):
479
482
requests = []
480
483
481
484
if len (exchanges ) > 0 :
@@ -484,7 +487,9 @@ def __create_subscription_request(self, exchanges=[], symbols=[], service="REAL_
484
487
exchange = exch ,
485
488
subscriptionType = [openfeed_api_pb2 .SubscriptionType .Value (
486
489
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 ]
488
493
))
489
494
490
495
if len (symbols ) > 0 :
@@ -565,12 +570,13 @@ def __callback(self, callback, *args):
565
570
566
571
567
572
class 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 ):
569
574
self .symbol = symbol
570
575
self .exchange = exchange
571
576
self .callback = callback
572
577
self .service = service
573
578
self .subscription_type = subscription_type
579
+ self .instrument_type = instrument_type
574
580
self .snapshot_interval_seconds = snapshot_interval_seconds
575
581
576
582
def key (self ):
@@ -588,6 +594,11 @@ def exchanges(self):
588
594
return [self .exchange ]
589
595
return []
590
596
597
+ def get_instrument_types (self ):
598
+ if len (self .exchange ) > 0 :
599
+ return self .instrument_type
600
+ return []
601
+
591
602
def has_same_interest (self , other ):
592
603
return collections .Counter (self .subscription_type ) == collections .Counter (other .subscription_type )
593
604
0 commit comments