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.
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.
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 monitor
ETH/USDat 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 a
TVFeed(). 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 in
example_strategy.pywithin the tv2bt repository.
tv2bt.configand change the port before you call
TVFeed()for the first time. In the example below, we do this right after the import.
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!