Add Stocks and FX to a default Freqtrade
This revision is from 2024/12/12 20:13. You can Restore it.
To make a custom exchange.
sudo apt-get update
sudo apt install -y python3-pip python3-venv python3-dev python3-pandas git curl
git clone https://github.com/freqtrade/freqtrade.git
cd freqtrade
python -m venv venv
source venv/bin/activate
deactivate
./setup.sh -i
source venv/bin/activate
freqtrade create-userdir --userdir user_data
freqtrade new-config --config user_data/crypto_config.json
freqtrade new-config --config user_data/stock_config.json
freqtrade new-config --config user_data/forex_config.json
{"max_open_trades": 100,
"stake_currency": "USDT",
"stake_amount": 1000,
"dry_run": true,
"dry_run_wallet": 100000,
"cache": "none", //avoid lookahead bias
"enable_protections": false, //avoid lookahead bias
"exit_pricing":{
"price_side": "other"
},
"entry_pricing": {
"price_side": "other"
},
"exchange": {
"name": "custard_tart",
"key": "",
"secret": "",
"pair_whitelist": ["TSLA/USDT"],
"pair_blacklist": []
},
"pairlists": [
{
"method": "StaticPairList",
"pairs": ["TSLA/USDT"]
}
]
}
Run...
freqtrade backtesting -c user_data/config.json -s SMA --timerange=20240101-20240201
and
freqtrade download-data --exchange custard_tart
and
freqtrade download-data --config user_data/config.json --timeframes 1m --timerange 20240101-
- freqtrade - ERROR - Exchange "custard_tart" is not known to the ccxt library and therefore not available for the bot.
There are 3 places to edit.
Step 1: Create a Custom Exchange Class
Create a new file custom_exchange.py in the freqtrade/exchange directory. In this file, define a class custardtart.py.
freqtrade/exchange/custardtart.py
from freqtrade.exchange import Exchange
class Custardtart(Exchange):
def __init__(self, config, validate=True, exchange_config=None, load_leverage_tiers=False):
@property
def name(self):
return "custardtart"
Register it with freqtrade/exchange/__init__.py
from freqtrade.exchange.custardtart import Custardtart
Add it to /freqtrade/exchange/common.py
SUPPORTED_EXCHANGES = [
"custardtart",
]
freqtrade/exchange/check_exchange.py
from freqtrade.exchange.common import MAP_EXCHANGE_CHILDCLASS, SUPPORTED_EXCHANGES
....
exchange = config.get("exchange", {}).get("name", "").lower()
if not exchange:
raise OperationalException(
f"This command requires a configured exchange. You should either use "
f"`--exchange <exchange_name>` or specify a configuration file via `--config`.\n"
f"The following exchanges are available for Freqtrade: "
f'{", ".join(available_exchanges())}'
)
if exchange in SUPPORTED_EXCHANGES:
print("Custardtart exchange recognized")
return True
Make sure the __pycache__ is deleted.
Run the test commands, ccxt is bypassed and the handler is registered, custardtart.py. Now all the logic needs to be found in custardtart.py, API calls to the exchange and so on as freqtrade queries this file for the objects definitions.
Make it so custardtart.py exits gracefully.