From c49cb102f52014bb291f9ca544b13fa349f2f88e Mon Sep 17 00:00:00 2001 From: euler90h Date: Wed, 9 Nov 2022 14:28:12 -0500 Subject: [PATCH] Added actives functions to StreamClient. --- tda/streaming.py | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/tda/streaming.py b/tda/streaming.py index 613b14b5..89ba4b42 100644 --- a/tda/streaming.py +++ b/tda/streaming.py @@ -1929,3 +1929,126 @@ def add_news_headline_handler(self, handler): ''' self._handlers['NEWS_HEADLINE'].append( self._BookHandler(handler, self.NewsHeadlineFields)) + + ########################################################################## + # ACTIVES + + class ActivesFields(_BaseFieldEnum): + ''' + `Official documentation `__ + ''' + SYMBOL = 0 + ACTIVES_DATA = 1 + + async def actives_options_subs(self, keys): + ''' + `Official documentation `__ + + Subscribe to the day's top traded option symbols. + ''' + await self._service_op(keys, 'ACTIVES_OPTIONS', 'SUBS', + self.ActivesFields, + fields=self.ActivesFields.all_fields()) + + async def actives_options_unsubs(self, keys): + ''' + `Official documentation `__ + + Un-Subscribe from active option symbols. + ''' + await self._service_op(keys, 'ACTIVES_OPTIONS', 'UNSUBS') + + def add_actives_options_handler(self, handler): + ''' + Register a function to handle active options as they are provided. See + :ref:`registering_handlers` for details. + ''' + self._handlers['ACTIVES_OPTIONS'].append(_Handler(handler, + self.ActivesFields)) + + async def actives_otcbb_subs(self, keys): + ''' + `Official documentation `__ + + Subscribe to the most active OTCBB symbols. + ''' + await self._service_op(keys, 'ACTIVES_OTCBB', 'SUBS', + self.ActivesFields, + fields=self.ActivesFields.all_fields()) + + async def actives_otcbb_unsubs(self, keys): + ''' + `Official documentation `__ + + Un-Subscribe from the most active OTCBB symbols. + ''' + await self._service_op(keys, 'ACTIVES_OTCBB', 'UNSUBS') + + def add_actives_otcbb_handler(self, handler): + ''' + Register a function to handle actives as they are provided. See + :ref:`registering_handlers` for details. + ''' + self._handlers['ACTIVES_OTCBB'].append(_Handler(handler, + self.ActivesFields)) + + async def actives_nyse_subs(self, keys): + ''' + `Official documentation `__ + + Subscribe to the NYSE's most active symbols. + ''' + await self._service_op(keys, 'ACTIVES_NYSE', 'SUBS', + self.ActivesFields, + fields=self.ActivesFields.all_fields()) + + async def actives_nyse_unsubs(self, keys): + ''' + `Official documentation `__ + + Un-Subscribe from NYSE actives. + ''' + await self._service_op(keys, 'ACTIVES_NYSE', 'UNSUBS') + + def add_actives_nyse_handler(self, handler): + ''' + Register a function to handle actives as they are provided. See + :ref:`registering_handlers` for details. + ''' + self._handlers['ACTIVES_NYSE'].append(_Handler(handler, + self.ActivesFields)) + + async def actives_nasdaq_subs(self, keys): + ''' + `Official documentation `__ + + Subscribe to the NASDAQ's most active symbols. + ''' + await self._service_op(keys, 'ACTIVES_NASDAQ', 'SUBS', + self.ActivesFields, + fields=self.ActivesFields.all_fields()) + + async def actives_nasdaq_unsubs(self, keys): + ''' + `Official documentation `__ + + Un-Subscribe from NASDAQ actives. + ''' + await self._service_op(keys, 'ACTIVES_NASDAQ', 'UNSUBS') + + def add_actives_nasdaq_handler(self, handler): + ''' + Register a function to handle actives as they are provided. See + :ref:`registering_handlers` for details. + ''' + self._handlers['ACTIVES_NASDAQ'].append(_Handler(handler, + self.ActivesFields))