I run into an error when developing my bot.
This is the minimum code that reproduce the error.
Could you help me?
import time
from datetime import datetime
import backtrader as bt
from ccxtbt import CCXTFeed
def main():
class TestStrategy(bt.Strategy):
params = (
('maperiod', 10),
)
def __init__(self):
self.next_runs = 0
def next(self, dt=None):
dt = dt or self.datas[0].datetime.datetime(0)
print('%s closing price: %s' % (dt.isoformat(), self.datas[0].close[0]))
self.next_runs += 1
cerebro = bt.Cerebro()
# cerebro.addstrategy(TestStrategy)
cerebro.optstrategy(TestStrategy, maperiod=[10,11], printlog=True)
# Add the feed
cerebro.adddata(CCXTFeed(exchange='binance',
dataname='BNB/USDT',
timeframe=bt.TimeFrame.Minutes,
fromdate=datetime(2019, 1, 1, 0, 0),
todate=datetime(2019, 1, 1, 0, 2),
compression=1,
ohlcv_limit=2,
currency='BNB',
retries=5,
config={'enableRateLimit': True, 'nonce': lambda: str(int(time.time() * 1000))}))
# Run the strategy
cerebro.run(maxcups=1)
if __name__ == '__main__':
main()
Error
Traceback (most recent call last):
File "PATH_TO_CODE/sam-app/app/btccxt.py", line 45, in <module>
main()
File "PATH_TO_CODE/sam-app/app/btccxt.py", line 41, in main
cerebro.run(maxcups=1)
File "PATH_TO_CODE\venv\lib\site-packages\backtrader\cerebro.py", line 1143, in run
for r in pool.imap(self, iterstrats):
File "PATH_TO_PYTHON\lib\multiprocessing\pool.py", line 748, in next
raise value
File "PATH_TO_PYTHON\lib\multiprocessing\pool.py", line 431, in _handle_tasks
put(task)
File "PATH_TO_PYTHON\lib\multiprocessing\connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "PATH_TO_PYTHON\lib\multiprocessing\reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
AttributeError: Can't pickle local object 'main.<locals>.<lambda>'
I run into an error when developing my bot. This is the minimum code that reproduce the error.
Could you help me?
Error