Routes are how you define which symbol to trade, in which time frame, at which exchange, and which strategy to use.
Routes are located at the
routes.py file in your project.
# Basic syntax
You must implement at least one route. Here is the basic syntax:
(exchange, symbol, timeframe, strategy)
from jesse.enums import exchanges, timeframes routes = [ ('Binance', 'BTCUSDT', '4h', 'TrendFollowingStrategy'), ]
In this example, we're telling Jesse to trade
TrendFollowingStrategy strategy at
Binance exchange in
4h time interval.
Instead of writing
'4h', you could write
timeframes.HOUR_4. This is optional but helps to prevent misspelling string.
# Trading multiple routes
You can trade more than one route at the same time. The
routes variable is a list, so we can put multiple routes in it:
from jesse.enums import exchanges, timeframes routes = [ ('Binance', 'BTCUSDT', '4h', 'TrendFollowingStrategy'), ('Binance', 'ETHUSDT', '15m', 'MeanReverseStrategy'), ]
symbol pairs must be unique.
That means you CAN trade
BTCUSDT at the same time in both
Bitfinex; but you CANNOT trade
Binance on both
4h timeframes at the same time.
Why? Because exchanges support only one position per symbol and we want to keep it simple.
# Using multiple time frames
You can use multiple time frames when writing strategies.
A typical example might be to use the daily time frame to detect the bigger trend of the market, and the hourly time frame to detect the smaller trend.
This is a common feature that professional traders use in their manual trading. However, in algorithmic trading, it gets tricky because of the Look-Ahead Bias. This issue is completely taken care of in Jesse.
All you need to do is to define extra candles. The syntax for
extra_candles is the same as
routes except no need to define the strategy name at the end.
For example, if you're trading
4h time frame, and using
1D time frame in your strategy, this is how your routes must look like:
from jesse.enums import exchanges, timeframes routes = [ ('Binance', 'BTCUSDT', '4h', 'TrendFollowingStrategy'), ] extra_candles = [ ('Binance', 'BTCUSDT', '1D'), ]
You may be thinking why not just define few extra routes and leave them be; whether or not using them. That would work; however, Jesse goes through expensive calculations to make extra candles work without the Look-Ahead Bias; hence, you will be facing longer backtest simulations.