freqtrade 框架安装配置-1
一、介绍
源码安装
cd cd /Users/kaiyi/Work/develop/Code/
git clone https://github.com/freqtrade/freqtrade.git
cd /Users/kaiyi/Work/develop/Code/freqtrade
# 安装
./setup.sh -i
# 安装好之后,激活环境
source .venv/bin/activate
You can now use the bot by executing 'source .venv/bin/activate; freqtrade <subcommand>'.
You can see the list of available bot sub-commands by executing 'source .venv/bin/activate; freqtrade --help'.
You verify that freqtrade is installed successfully by running 'source .venv/bin/activate; freqtrade --version'.
# 初始化配置(创建 user_data 目录)
# Step 1 - Initialize user folder
# freqtrade create-userdir --userdir user_data
# Step 2 - Create a new configuration file
freqtrade new-config --config user_data/config.json
# 启动bot
freqtrade trade --config user_data/config.json --strategy SampleStrategy
配置文件 user_data/config.json
{
"$schema": "https://schema.freqtrade.io/schema.json",
"max_open_trades": 3,
"stake_currency": "USDT",
"stake_amount": "unlimited",
"tradable_balance_ratio": 0.99,
"fiat_display_currency": "USD",
"dry_run": true,
"dry_run_wallet": 1000,
"cancel_open_orders_on_exit": false,
"trading_mode": "futures",
"margin_mode": "isolated",
"unfilledtimeout": {
"entry": 10,
"exit": 10,
"exit_timeout_count": 0,
"unit": "minutes"
},
"entry_pricing": {
"price_side": "same",
"use_order_book": true,
"order_book_top": 1,
"price_last_balance": 0.0,
"check_depth_of_market": {
"enabled": false,
"bids_to_ask_delta": 1
}
},
"exit_pricing":{
"price_side": "same",
"use_order_book": true,
"order_book_top": 1
},
"exchange": {
"name": "binance",
"key": "",
"secret": "",
"ccxt_config": {},
"ccxt_async_config": {},
"pair_whitelist": [
],
"pair_blacklist": [
"BNB/.*"
]
},
"pairlists": [
{
"method": "VolumePairList",
"number_assets": 20,
"sort_key": "quoteVolume",
"min_value": 0,
"refresh_period": 1800
}
],
"telegram": {
"enabled": false,
"token": "",
"chat_id": ""
},
"api_server": {
"enabled": true,
"listen_ip_address": "127.0.0.1",
"listen_port": 8081,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "ec48ea45e030281600eae894132be75ec4c180b1ac7be7e9562bcae79d62aa96",
"ws_token": "cp0OdhMokv9d3hC6b1g3puGKytewMdUZAA",
"CORS_origins": [],
"username": "freqtraderlocal",
"password": "fredtrader_local"
},
"bot_name": "freqtrade",
"initial_state": "running",
"force_entry_enable": false,
"internals": {
"process_throttle_secs": 5
}
}
freqtrade 执行命令:
(base) ➜ bin git:(develop) cat freqtrade
#!/Users/kaiyi/Work/develop/Code/freqtrade/.venv/bin/python3.12
# -*- coding: utf-8 -*-
import re
import sys
from freqtrade.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
(base) ➜ bin git:(develop)
解读 freqtrade/main.py 源代码:
# /Users/kaiyi/Work/develop/Code/freqtrade/freqtrade/main.py
#!/usr/bin/env python3
"""
Main Freqtrade bot script.
Read the documentation to know what cli arguments you need.
"""
import logging
import sys
from typing import Any
# check min. python version
if sys.version_info < (3, 10): # pragma: no cover # noqa: UP036
sys.exit("Freqtrade requires Python version >= 3.10")
from freqtrade import __version__
from freqtrade.commands import Arguments
from freqtrade.constants import DOCS_LINK
from freqtrade.exceptions import ConfigurationError, FreqtradeException, OperationalException
from freqtrade.loggers import setup_logging_pre
from freqtrade.system import asyncio_setup, gc_set_threshold, print_version_info
logger = logging.getLogger("freqtrade")
def main(sysargv: list[str] | None = None) -> None:
"""
This function will initiate the bot and start the trading loop.
:return: None
"""
return_code: Any = 1
try:
setup_logging_pre()
asyncio_setup()
arguments = Arguments(sysargv)
args = arguments.get_parsed_arg()
# print args
logger.info(f"main: parsed_args: {str(args)}")
# Call subcommand.
if args.get("version") or args.get("version_main"):
print_version_info()
return_code = 0
elif "func" in args:
logger.info(f"freqtrade {__version__}")
gc_set_threshold()
return_code = args["func"](args)
else:
# No subcommand was issued.
raise OperationalException(
"Usage of Freqtrade requires a subcommand to be specified.\n"
"To have the bot executing trades in live/dry-run modes, "
"depending on the value of the `dry_run` setting in the config, run Freqtrade "
"as `freqtrade trade [options...]`.\n"
"To see the full list of options available, please use "
"`freqtrade --help` or `freqtrade <command> --help`."
)
except SystemExit as e: # pragma: no cover
return_code = e
except KeyboardInterrupt:
logger.info("SIGINT received, aborting ...")
return_code = 0
except ConfigurationError as e:
logger.error(
f"Configuration error: {e}\n"
f"Please make sure to review the documentation at {DOCS_LINK}."
)
except FreqtradeException as e:
logger.error(str(e))
return_code = 2
except Exception:
logger.exception("Fatal exception!")
finally:
sys.exit(return_code)
if __name__ == "__main__": # pragma: no cover
main()
执行命令:
(.venv) (base) ➜ freqtrade git:(develop) ✗ freqtrade trade --config user_data/config.json --strategy MyStrategy
2025-04-20 23:49:02,218 - freqtrade - INFO - parsed_args: {'version_main': False, 'command': 'trade', 'verbosity': None, 'print_colorized': True, 'logfile': None, 'version':
False, 'config': ['user_data/config.json'], 'datadir': None, 'user_data_dir': None, 'strategy': 'MyStrategy', 'strategy_path': None, 'recursive_strategy_search': False,
'freqaimodel': None, 'freqaimodel_path': None, 'db_url': None, 'sd_notify': False, 'dry_run': False, 'dry_run_wallet': None, 'fee': None, 'func': <function start_trading at
0x10cadd4e0>}
2025-04-20 23:49:02,219 - freqtrade - INFO - freqtrade 2025.4-dev-82cd343fc
2025-04-20 23:49:02,607 - numexpr.utils - INFO - NumExpr defaulting to 12 threads.
2025-04-20 23:49:04,752 - freqtrade.worker - INFO - Starting worker 2025.4-dev-82cd343fc
单独执行 pairlist :
(.venv) (base) ➜ freqtrade git:(develop) ✗ freqtrade test-pairlist --config user_data/config/my_config.json
2025-04-21 00:42:04,501 - freqtrade - INFO - main: parsed_args: {'version_main': False, 'command': 'test-pairlist', 'user_data_dir': None, 'verbosity': None, 'config':
['user_data/config/my_config.json'], 'quote_currencies': None, 'print_one_column': False, 'list_pairs_print_json': False, 'exchange': None, 'func': <function start_test_pairlist
at 0x1016c8ae0>}
2025-04-21 00:42:04,502 - freqtrade - INFO - freqtrade 2025.4-dev-82cd343fc
2025-04-21 00:42:04,846 - numexpr.utils - INFO - NumExpr defaulting to 12 threads.
2025-04-21 00:42:06,474 - freqtrade.configuration.load_config - INFO - Using config: user_data/config/my_config.json ...
终于找到 pairlist 配置是在 freqtrade/constants.py
文件中,在上边的命令中会去检查判断:
相关文章:
Github | freqtrade/freqtrade
freqtrade | 本地安装教程
为者常成,行者常至
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)