Skip to content

Here you can find a link for new backtrader with 3 commits !! You can post your commits in my repository - I will apply them! #472

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

Merged
merged 13 commits into from
Apr 16, 2023
Merged
30 changes: 30 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
Why use this BackTrader repo from WISEPLAT?
===========================================

Here is a backtrader with 3 new commits !! You can post your commits in my repository - I will apply them ASAP!

To install backtrader from my repository::

pip install git+https://github.com/WISEPLAT/backtrader.git


By this link https://github.com/WISEPLAT/backtrader you can suggest your commits, I will apply them ASAP.
This suggestion is made here, because of no one from original project doesn't want to continue this cool project!

1st commit: Option to change background for plotted value tags for dark theme - to get dark theme)))
When you use dark theme you need to change background for plotted value tags.

2nd commit: Fix: In last Python versions collections.Iterable -> collections.abc.Iterable - to work with Python 3.11+

3rd commit: Fix: The set_view_interval, set_data_interval ... are removed. Now you can work with matplotlib > 3.6.x

Recently I have created Binance API integration with Backtrader
===============================================================
With this integration you can do:

- Backtesting your strategy on historical data from the exchange Binance + Backtrader // Backtesting
- Launch trading systems for automatic trading on the exchange Binance + Backtrader // Live trading
- Download historical data for cryptocurrencies from the exchange Binance
To make it easier to figure out how everything works, many examples have been made.
Here is the code: https://github.com/WISEPLAT/backtrader_binance

backtrader
==========

Expand Down
7 changes: 6 additions & 1 deletion backtrader/cerebro.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import itertools
import multiprocessing

try: # For new Python versions
collectionsAbc = collections.abc # collections.Iterable -> collections.abc.Iterable
except AttributeError: # For old Python versions
collectionsAbc = collections # Используем collections.Iterable

import backtrader as bt
from .utils.py3 import (map, range, zip, with_metaclass, string_types,
integer_types)
Expand Down Expand Up @@ -330,7 +335,7 @@ def iterize(iterable):
for elem in iterable:
if isinstance(elem, string_types):
elem = (elem,)
elif not isinstance(elem, collections.Iterable):
elif not isinstance(elem, collectionsAbc.Iterable): # Different functions will be called for different Python versions
elem = (elem,)

niterable.append(elem)
Expand Down
1 change: 1 addition & 0 deletions backtrader/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def next(self, datamaster=None, ticks=True):
if self.lines.datetime[0] > datamaster.lines.datetime[0]:
# can't deliver new bar, too early, go back
self.rewind()
return False
else:
if ticks:
self._tick_fill()
Expand Down
15 changes: 13 additions & 2 deletions backtrader/plot/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,19 @@ def get_locator(self, dmin, dmax):

locator.set_axis(self.axis)

locator.set_view_interval(*self.axis.get_view_interval())
locator.set_data_interval(*self.axis.get_data_interval())
try:
# try for matplotlib < 3.6.0
locator.set_view_interval(*self.axis.get_view_interval())
locator.set_data_interval(*self.axis.get_data_interval())
except Exception as e:
try:
# try for matplotlib >= 3.6.0
self.axis.set_view_interval(*self.axis.get_view_interval())
self.axis.set_data_interval(*self.axis.get_data_interval())
locator.set_axis(self.axis)
except Exception as e:
print("Error:", e)

return locator


Expand Down
8 changes: 6 additions & 2 deletions backtrader/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Plot_OldSync(with_metaclass(MetaParams, object)):
def __init__(self, **kwargs):
for pname, pvalue in kwargs.items():
setattr(self.p.scheme, pname, pvalue)
if not hasattr(self.p.scheme, 'locbg'):
setattr(self.p.scheme, 'locbg', 'white')
setattr(self.p.scheme, 'locbgother', 'white')

def drawtag(self, ax, x, y, facecolor, edgecolor, alpha=0.9, **kwargs):

Expand Down Expand Up @@ -487,7 +490,7 @@ def plotind(self, iref, ind,
if linetag and not math.isnan(lplot[-1]):
# line has valid values, plot a tag for the last value
self.drawtag(ax, len(self.pinf.xreal), lplot[-1],
facecolor='white',
facecolor=self.pinf.sch.locbgother,
edgecolor=self.pinf.color(ax))

farts = (('_gt', operator.gt), ('_lt', operator.lt), ('', None),)
Expand Down Expand Up @@ -732,7 +735,8 @@ def plotdata(self, data, indicators):
vtags = data.plotinfo._get('plotvaluetags', True)
if self.pinf.sch.valuetags and vtags:
self.drawtag(ax, len(self.pinf.xreal), closes[-1],
facecolor='white', edgecolor=self.pinf.sch.loc)
facecolor=self.pinf.sch.locbg,
edgecolor=self.pinf.sch.loc)

ax.yaxis.set_major_locator(mticker.MaxNLocator(prune='both'))
# make sure "over" indicators do not change our scale
Expand Down
7 changes: 6 additions & 1 deletion backtrader/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import itertools
import sys

try: # For new Python versions
collectionsAbc = collections.abc # collections.Iterable -> collections.abc.Iterable
except AttributeError: # For old Python versions
collectionsAbc = collections # Используем collections.Iterable

import backtrader as bt
from backtrader.utils.py3 import (map, with_metaclass, string_types,
integer_types)
Expand Down Expand Up @@ -205,7 +210,7 @@ def writedict(self, dct, level=0, recurse=False):
self.writelineseparator(level=level)
self.writeline(kline)
self.writedict(val, level=level + 1, recurse=True)
elif isinstance(val, (list, tuple, collections.Iterable)):
elif isinstance(val, (list, tuple, collectionsAbc.Iterable)): # Для разных версий Python будут вызываться разные функции
line = ', '.join(map(str, val))
self.writeline(kline + ' ' + line)
else:
Expand Down