TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.46k stars 1.74k forks source link

break threading for talib abstract with pandas #541

Closed robcaulk closed 1 year ago

robcaulk commented 1 year ago

Illustrates #540 but does not solve the problem.

Over at freqtrade, we are using ta-lib in a multithreaded fashion and we have noticed that, on occasion, the library will throw an error that looks like this:

  File "/home/opc/freqtrade/user_data/strategies/EI3v2_RSI_CONS_TRAIL_AI.py", line 425, in populate_any_indicators
    informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t)
  File "talib/_abstract.pxi", line 439, in talib._ta_lib.Function.__call__
  File "talib/_abstract.pxi", line 350, in talib._ta_lib.Function.outputs
  File "/home/opc/freqtrade/.env/lib64/python3.9/site-packages/pandas/core/series.py", line 442, in __init__
    com.require_length_match(data, index)
  File "/home/opc/freqtrade/.env/lib64/python3.9/site-packages/pandas/core/common.py", line 557, in require_length_match
    raise ValueError(
ValueError: Length of values (4005) does not match length of index (999)

Which is due to two threads simultaneously wanting to use ta.RSI() and using the ta.abstract interface.

mrjbq7 commented 1 year ago

Added a test case in aff2469cbd744361d3ba38180f1aba77c29e8472 and confirmed that the new code passes it and the old code failed it.

robcaulk commented 1 year ago

The beauty of open-source, people find bugs, then those people write test cases to help you solve those bugs. Then they benefit from the bug fix you write.

Its a symbiotic relationship, except when you copy and paste their code into your own commit.