btgsolutions-dataservices-python-client 2.11.2__tar.gz → 2.11.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {btgsolutions_dataservices_python_client-2.11.2/btgsolutions_dataservices_python_client.egg-info → btgsolutions_dataservices_python_client-2.11.4}/PKG-INFO +9 -1
  2. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/README.md +8 -0
  3. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/historical_candles.py +29 -1
  4. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/websocket/market_data_feed.py +33 -15
  5. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4/btgsolutions_dataservices_python_client.egg-info}/PKG-INFO +9 -1
  6. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/setup.py +1 -1
  7. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/LICENSE +0 -0
  8. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/MANIFEST.in +0 -0
  9. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/__init__.py +0 -0
  10. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/config.py +0 -0
  11. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/exceptions.py +0 -0
  12. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/__init__.py +0 -0
  13. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/authenticator.py +0 -0
  14. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/bulk_data.py +0 -0
  15. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/company_data.py +0 -0
  16. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/corporate_events.py +0 -0
  17. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/hfn.py +0 -0
  18. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/intraday_candles.py +0 -0
  19. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/intraday_tick_data.py +0 -0
  20. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/public_sources.py +0 -0
  21. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/quotes.py +0 -0
  22. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/reference_data.py +0 -0
  23. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/rest/ticker_last_event.py +0 -0
  24. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/websocket/__init__.py +0 -0
  25. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/websocket/hfn_websocket_client.py +0 -0
  26. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/websocket/market_data_websocket_client.py +0 -0
  27. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices/websocket/websocket_default_functions.py +0 -0
  28. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices_python_client.egg-info/SOURCES.txt +0 -0
  29. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices_python_client.egg-info/dependency_links.txt +0 -0
  30. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices_python_client.egg-info/requires.txt +0 -0
  31. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/btgsolutions_dataservices_python_client.egg-info/top_level.txt +0 -0
  32. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/pyproject.toml +0 -0
  33. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/requirements.txt +0 -0
  34. {btgsolutions_dataservices_python_client-2.11.2 → btgsolutions_dataservices_python_client-2.11.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: btgsolutions-dataservices-python-client
3
- Version: 2.11.2
3
+ Version: 2.11.4
4
4
  Summary: Python package containing several classes and data for extracting and manipulating market and trading data.
5
5
  Home-page: https://github.com/BTG-Pactual-Solutions/btgsolutions-dataservices-python-client
6
6
  Author: BTG Solutions Data Services powered by BTG Pactual Solutions
@@ -242,6 +242,14 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
242
242
  hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
243
243
  ```
244
244
 
245
+ ##### Available Tickers
246
+
247
+ ```python
248
+ import btgsolutions_dataservices as btg
249
+ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
250
+ hist_candles.get_available_tickers(market_type='stocks', date='2025-05-29')
251
+ ```
252
+
245
253
  ##### Plot Candles
246
254
 
247
255
  ```python
@@ -219,6 +219,14 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
219
219
  hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
220
220
  ```
221
221
 
222
+ ##### Available Tickers
223
+
224
+ ```python
225
+ import btgsolutions_dataservices as btg
226
+ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
227
+ hist_candles.get_available_tickers(market_type='stocks', date='2025-05-29')
228
+ ```
229
+
222
230
  ##### Plot Candles
223
231
 
224
232
  ```python
@@ -158,4 +158,32 @@ class HistoricalCandles:
158
158
  return response_data if raw_data else pd.DataFrame(response_data)
159
159
 
160
160
  response = json.loads(response.text)
161
- raise BadResponse(f'Error: {response.get("ApiClientError", "")}.\n{response.get("SuggestedAction", "")}')
161
+ raise BadResponse(f'Error: {response.get("ApiClientError", "")}.\n{response.get("SuggestedAction", "")}')
162
+
163
+ def get_available_tickers(
164
+ self,
165
+ market_type:str,
166
+ date:str,
167
+ ):
168
+ """
169
+ This method provides all tickers available for query.
170
+
171
+ Parameters
172
+ ----------------
173
+ market_type: str
174
+ Market type.
175
+ Options: 'stocks', 'derivatives' or 'indices'.
176
+ Field is required.
177
+ date: string<date>
178
+ Date of requested data. Format: "YYYY-MM-DD".
179
+ Field is required. Example: '2023-10-06'.
180
+ """
181
+
182
+ if market_type not in ['stocks', 'derivatives', 'indices']: raise MarketTypeError(f"Must provide a valid 'market_type' parameter. Input: '{market_type}'. Accepted values: 'stocks', 'derivatives' or 'indices'.")
183
+
184
+ url = f"{url_apis_v3}/marketdata/history/candles/available-tickers/{market_type}?date={date}"
185
+
186
+ response = requests.request("GET", url, headers=self.headers)
187
+ if response.status_code == 200: return response.json()
188
+ response = response.json()
189
+ raise BadResponse(f'Error: {response.get("ApiClientError", "") or response.get("ApiServerMessage", "")}.\n{response.get("SuggestedAction", "")}')
@@ -4,6 +4,7 @@ import time
4
4
  from datetime import date
5
5
  import multiprocessing
6
6
  import logging
7
+ from logging.handlers import QueueHandler, QueueListener
7
8
  import json
8
9
  import ssl
9
10
  import threading
@@ -89,6 +90,11 @@ class MarketDataFeed:
89
90
  2. close_msg.
90
91
  - Field is not required.
91
92
  - Default: prints a message that the connection was closed.
93
+ log_level: str
94
+ Log level sets how much information the program will print to the log file.
95
+ Options: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'NOTSET'.
96
+ 'DEBUG' provides the most detailed logs, with verbosity decreasing through each level down to 'NOTSET', which disables all logging.
97
+ Field is not required. Default: 'DEBUG'.
92
98
  """
93
99
 
94
100
  def __init__(
@@ -105,6 +111,7 @@ class MarketDataFeed:
105
111
  on_message: Optional[Callable]=None,
106
112
  on_error: Optional[Callable]=None,
107
113
  on_close: Optional[Callable]=None,
114
+ log_level: str="DEBUG",
108
115
  ):
109
116
 
110
117
  if feed == FEED_B:
@@ -131,35 +138,46 @@ class MarketDataFeed:
131
138
 
132
139
  self.server_message_queue = multiprocessing.Queue()
133
140
  self.client_message_queue = multiprocessing.Queue()
141
+ self.log_queue = multiprocessing.Queue()
142
+
143
+ log_level = getattr(logging, log_level)
144
+ self.log_level = log_level
145
+
146
+ log_handler = logging.FileHandler(filename=f"MarketDataFeed_{date.today().isoformat()}.log")
147
+ log_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
148
+
149
+ log_queue_listener = QueueListener(self.log_queue, log_handler)
150
+ log_queue_listener.start()
151
+
152
+ self.logger = logging.getLogger("main")
153
+ self.logger.setLevel(log_level)
154
+ self.logger.addHandler(QueueHandler(self.log_queue))
155
+
134
156
  self.process = None
135
157
  self.running = False
136
158
 
137
- self.logger = logging.getLogger("MarketDataFeed")
138
- self.logger.setLevel(logging.INFO)
139
- log_file = f"MarketDataFeed_{date.today().isoformat()}.log"
140
- handler = logging.FileHandler(log_file)
141
- formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
142
- handler.setFormatter(formatter)
143
- self.logger.addHandler(handler)
159
+ def _ws_client_process(self, server_message_queue: multiprocessing.Queue, client_message_queue: multiprocessing.Queue, log_queue: multiprocessing.Queue, log_level: int):
144
160
 
145
- def _ws_client_process(self, server_message_queue: multiprocessing.Queue, client_message_queue: multiprocessing.Queue, logger: logging.Logger):
161
+ logger = logging.getLogger("client")
162
+ logger.setLevel(log_level)
163
+ logger.addHandler(QueueHandler(log_queue))
146
164
 
147
165
  def on_message(ws, message):
148
166
  server_message_queue.put(json.loads(message))
149
167
 
150
168
  def on_error(ws, error):
151
- logger.info(f"On Error | {error}")
169
+ logger.error(f"On Error | {error}")
152
170
  self.on_error(error)
153
171
 
154
172
  def on_close(ws, close_status_code, close_msg):
155
- logger.info(f"On Close | Connection closed")
173
+ logger.warning(f"On Close | Connection closed")
156
174
  self.on_close(close_status_code, close_msg)
157
175
  if self.reconnect:
158
176
  if self.__nro_reconnect_retries == MAX_WS_RECONNECT_RETRIES:
159
- logger.info(f"On Close | Maximum number of reconnect attempts reached")
177
+ logger.critical(f"On Close | Maximum number of reconnect attempts reached")
160
178
  return
161
179
  self.__nro_reconnect_retries += 1
162
- logger.info(f"On Close | Reconnecting... attempt: {self.__nro_reconnect_retries}/{MAX_WS_RECONNECT_RETRIES}")
180
+ logger.warning(f"On Close | Reconnecting... attempt: {self.__nro_reconnect_retries}/{MAX_WS_RECONNECT_RETRIES}")
163
181
  run_forever_new_thread()
164
182
 
165
183
  def on_open(ws):
@@ -206,7 +224,7 @@ class MarketDataFeed:
206
224
  """
207
225
  Opens a new connection with the websocket server.
208
226
  """
209
- self.process = multiprocessing.Process(target=self._ws_client_process, args=(self.server_message_queue, self.client_message_queue, self.logger))
227
+ self.process = multiprocessing.Process(target=self._ws_client_process, args=(self.server_message_queue, self.client_message_queue, self.log_queue, self.log_level))
210
228
  self.process.start()
211
229
  self.running = True
212
230
 
@@ -217,12 +235,12 @@ class MarketDataFeed:
217
235
  msg = self.server_message_queue.get()
218
236
  self.on_message(msg)
219
237
  else:
220
- time.sleep(0.1)
238
+ time.sleep(0.01)
221
239
 
222
240
  if time.time() - log_timer >= 5.0:
223
241
  server_queue_size = self.server_message_queue.qsize()
224
242
  client_queue_size = self.client_message_queue.qsize()
225
- self.logger.info(f"Server queue: {server_queue_size} | Client queue: {client_queue_size}")
243
+ self.logger.debug(f"Server queue: {server_queue_size} | Client queue: {client_queue_size}")
226
244
  log_timer = time.time()
227
245
 
228
246
  threading.Thread(target=run_on_new_thread).start()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: btgsolutions-dataservices-python-client
3
- Version: 2.11.2
3
+ Version: 2.11.4
4
4
  Summary: Python package containing several classes and data for extracting and manipulating market and trading data.
5
5
  Home-page: https://github.com/BTG-Pactual-Solutions/btgsolutions-dataservices-python-client
6
6
  Author: BTG Solutions Data Services powered by BTG Pactual Solutions
@@ -242,6 +242,14 @@ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
242
242
  hist_candles.get_intraday_history_candles(ticker='PETR4', market_type='stocks', corporate_events_adj=True, date='2023-10-06', candle='1m', rmv_after_market=True, timezone='UTC', raw_data=False)
243
243
  ```
244
244
 
245
+ ##### Available Tickers
246
+
247
+ ```python
248
+ import btgsolutions_dataservices as btg
249
+ hist_candles = btg.HistoricalCandles(api_key='YOUR_API_KEY')
250
+ hist_candles.get_available_tickers(market_type='stocks', date='2025-05-29')
251
+ ```
252
+
245
253
  ##### Plot Candles
246
254
 
247
255
  ```python
@@ -22,7 +22,7 @@ description = "Python package containing several classes and data for extracting
22
22
 
23
23
  setup(
24
24
  name='btgsolutions-dataservices-python-client',
25
- version='2.11.2',
25
+ version='2.11.4',
26
26
  description=description,
27
27
  long_description=long_description,
28
28
  long_description_content_type='text/markdown',