Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with optstrategy? #19

Open
tsuga opened this issue Aug 25, 2019 · 0 comments
Open

Incompatible with optstrategy? #19

tsuga opened this issue Aug 25, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@tsuga
Copy link

tsuga commented Aug 25, 2019

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>'
@Dave-Vallance Dave-Vallance added the enhancement New feature or request label Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants