A new update has just hit the tv2bt repository that changes the architecture of the module a little. As such, it worth a quick post to explain the update.
If this is your first time reading about tv2bt, you can read more about what it is and how to use it here.
tv2bt Configuration
A new file config.py
has been added to the project. It is intended to store any configuration options that are required by the flask server. At the moment it contains only a single configuration option (the server port). However, over time the amount of configurable items will grow.
Why?
The current architecture of tv2bt shares the same server between all instances of TVFeed()
added to your Backtrader script. In other words, if you want to monitorBTC/USD
andETH/USD
at the same time, we use the same server rather than creating two servers so that all Tradingview alerts are routed to the same server/port.
Adding a configuration file allows us to change the port of the server before it is initialized. The ultimate goal and reason for the change is to enable trading on multiple exchanges at the same time. To support this architecture, we need to be able change the port in our Backtrader script before initializing aTVFeed()
. This will ensure that the feeds in that particular script will then use the configuration you set rather than the default. This can all be done without needing to change the source code in the project.
Multiple Exchange Support
Although not currently supported yet, multiple exchange support is quite easy to implement following the latest update. All we need to do is create a second server outside Backtrader and tv2bt that will route any alerts from Tradingview to the correct localhost port. This will not be covered in detail here, but to give you an idea, the architecture the project is working towards will look something like this:
How to alter the tv2bt configuration in Backtrader
A simple example is provided inexample_strategy.py
within the tv2bt repository.
Simply import tv2bt.config
and change the port before you call TVFeed()
for the first time. In the example below, we do this right after the import.
import tv2bt.config tv2bt.config.PORT = 8123 import backtrader as bt
And that is it, now you can change the server port!
The change should be backwards compatible with any scripts that you may have made already with the module. However, if you do have any issues, log an issue on the GitHub repository!
Find This Post Useful?
If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.
Backtest Rookies is a registered with Brave publisher!
Brave users can drop us a tip.
Alternatively, support us by switching to Brave using this referral link and we will receive some BAT!
Referral Link
Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up!
3HxNVyh5729ieTfPnTybrtK7J7QxJD9gjD
0x9a2f88198224d59e5749bacfc23d79507da3d431
M8iUBnb8KamHR18gpgi2sSG7jopddFJi8S
Hi there, just a few questions re: port forwarding, are you able to email me?