Skip to content

Commit

Permalink
trade.py upgraded to be able to be unpickled. (#406)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andrelcgt authored Jul 3, 2020
1 parent 343ca28 commit 9118556
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ samples2/

# Ignore test files in Datas
datas/*.py

.idea/
9 changes: 8 additions & 1 deletion backtrader/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'''
Expand Down

0 comments on commit 9118556

Please sign in to comment.