From 9118556ad283fb4ce50ba0560830ffc0b89dc09b Mon Sep 17 00:00:00 2001 From: andrelcgt <67286018+andrelcgt@users.noreply.github.com> Date: Fri, 3 Jul 2020 08:54:20 -0300 Subject: [PATCH] trade.py upgraded to be able to be unpickled. (#406) * trade.py upgraded to be able to be unpickled. * Excluded .idea from .gitignore * Fixed .gitignore * Delete backtrader.iml * Delete profiles_settings.xml * Delete modules.xml --- .gitignore | 2 ++ backtrader/trade.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 70d0912db..37c83965c 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,5 @@ samples2/ # Ignore test files in Datas datas/*.py + +.idea/ diff --git a/backtrader/trade.py b/backtrader/trade.py index 8bc037bb0..c49b7b332 100644 --- a/backtrader/trade.py +++ b/backtrader/trade.py @@ -56,7 +56,7 @@ class TradeHistory(AutoOrderedDict): ''' def __init__(self, - status, dt, barlen, size, price, value, pnl, pnlcomm, tz): + status, dt, barlen, size, price, value, pnl, pnlcomm, tz, event=None): '''Initializes the object to the current status of the Trade''' super(TradeHistory, self).__init__() self.status.status = status @@ -68,6 +68,13 @@ def __init__(self, self.status.pnl = pnl self.status.pnlcomm = pnlcomm self.status.tz = tz + if event is not None: + self.event = event + + def __reduce__(self): + return (self.__class__, (self.status.status, self.status.dt, self.status.barlen, self.status.size, + self.status.price, self.status.value, self.status.pnl, self.status.pnlcomm, + self.status.tz, self.event, )) def doupdate(self, order, size, price, commission): '''Used to fill the ``update`` part of the history entry'''