|
44 | 44 |
|
45 | 45 |
|
46 | 46 | class YahooCollector(BaseCollector): |
| 47 | + retry = 5 # Configuration attribute. How many times will it try to re-request the data if the network fails. |
| 48 | + |
47 | 49 | def __init__( |
48 | 50 | self, |
49 | 51 | save_dir: [str, Path], |
@@ -148,13 +150,7 @@ def _show_logging_func(): |
148 | 150 | def get_data( |
149 | 151 | self, symbol: str, interval: str, start_datetime: pd.Timestamp, end_datetime: pd.Timestamp |
150 | 152 | ) -> pd.DataFrame: |
151 | | - if hasattr(self, 'retry'): |
152 | | - retry = self.retry |
153 | | - else: |
154 | | - # Default value |
155 | | - retry = 5 |
156 | | - |
157 | | - @deco_retry(retry_sleep=self.delay, retry=retry) |
| 153 | + @deco_retry(retry_sleep=self.delay, retry=self.retry) |
158 | 154 | def _get_simple(start_, end_): |
159 | 155 | self.sleep() |
160 | 156 | _remote_interval = "1m" if interval == self.INTERVAL_1min else interval |
@@ -323,18 +319,18 @@ class YahooCollectorBR(YahooCollector, ABC): |
323 | 319 | def retry(cls): |
324 | 320 | """" |
325 | 321 | The reason to use retry=2 is due to the fact that |
326 | | - Yahoo Finance unfortunately does not keep track of the majority |
327 | | - of Brazilian stocks. |
| 322 | + Yahoo Finance unfortunately does not keep track of some |
| 323 | + Brazilian stocks. |
328 | 324 | |
329 | 325 | Therefore, the decorator deco_retry with retry argument |
330 | | - set to 5 will keep trying to get the stock data 5 times, |
| 326 | + set to 5 will keep trying to get the stock data up to 5 times, |
331 | 327 | which makes the code to download Brazilians stocks very slow. |
332 | 328 | |
333 | 329 | In future, this may change, but for now |
334 | 330 | I suggest to leave retry argument to 1 or 2 in |
335 | 331 | order to improve download speed. |
336 | 332 |
|
337 | | - In order to achieve this code logic an argument called retry_config |
| 333 | + To achieve this goal an abstract attribute (retry) |
338 | 334 | was added into YahooCollectorBR base class |
339 | 335 | """ |
340 | 336 | raise NotImplementedError |
|
0 commit comments