关于freqtrade交易机器人的一些用法整理,杠杆设置,等等等.聚合页面,专业填坑,不断更新

freqtrade官方使用说明
https://www.freqtrade.io/en/stable/

使用Docker进行安装后,启动 和 关闭容器的方式

docker-compose up -d   #启动容器
docker-compose down  #关闭容器   

使用Docker进行安装后,进入容器执行命令的方法
https://www.bgegao.com/2022/05/2309.html

使用Docker进行安装后,不进入容器直接执行命令,比如下面这条下载交易数据的命令

docker-compose run --rm freqtrade download-data --pairs XRP/USDT BTC/USDT ETH/USDT --exchange binance --days 5 -t 1h

关于Docker的更多操作 参考官方
https://www.freqtrade.io/en/stable/docker_quickstart/

webui打不开
https://www.bgegao.com/2022/05/2306.html

回测出现错误 VolumePairList not allowed for backtesting. Please use StaticPairlist instead
把你的 config.json 文件中的 “method”: “VolumePairList” 改成 “method”: “StaticPairList”

下载指定交易对的数据用于回测

freqtrade download-data --exchange binance --pairs XRP/USDT BTC/USDT

docker-compose run --rm freqtrade download-data --exchange binance --pairs .*/USDT --timerange 20210101- --timeframes 1m 5m
#这个是用docker-compose下载,表示下载所有USDT交易对,时间是从2020-01-01至今,timeframes为 1分钟和5分钟

更详细参考官方:https://www.freqtrade.io/en/stable/data-download/

回测命令

freqtrade  backtesting --strategy SampleStrategy

使用 docker-compose 进行回测

docker-compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m

docker-compose run --rm freqtrade backtesting --config user_data/backtest_config.json --strategy OnlyShortStrategy  -i 5m --timerange 20220101-
#这个表示测试20220101至今的所有数据

回测参数优化

docker-compose run --rm freqtrade hyperopt --config user_data/backtest_config.json --hyperopt-loss SampleHyperOptLoss --strategy OnlyShortStrategy -e 500 --timerange 20220501- --spaces buy sell roi stoploss

-e 500 表示 测试次数
–timerange 20220501- 表示测试周期
–spaces buy sell roi stoploss 表示测试哪几种类型

更详细参考官方:https://www.freqtrade.io/en/stable/backtesting/

查看当前可用的策略列表

docker-compose run --rm freqtrade list-strategies

为策略寻找最佳参数
https://www.freqtrade.io/en/stable/hyperopt/

我需要用通配符的方式 批量禁止某些交易对,如何操作?
config.json文件中

        "pair_blacklist": [
            "BNB/.*",
            ".*DOWN/BTC",
            ".*UP/BTC"
        ]

在Docker中,创建一个新配置文件

docker-compose run --rm freqtrade new-strategy --strategy MyStrategy

如何删除所有交易数据?
首先停止机器人,然后删除下面这三个文件即可
tradesv3.sqlite
tradesv3.sqlite-wal
tradesv3.sqlite-shm
—————————————-
关于杠杆设置,这的确是个大坑
杠杆我在官网找了好久都没找到说明 比如这里 https://www.freqtrade.io/en/stable/leverage/ ,这个页面虽然是一个专门的杠杆说明,但是它却没有教你如何设置杠杆
找了好久,我终于找到一段代码,把下面这个放到策略的class里就行了
这段代码出处在这里,https://www.freqtrade.io/en/stable/strategy-callbacks/#leverage-callback

    #设置杠杆  return 5.0 表示5倍
    def leverage(self, pair: str, current_time: 'datetime', current_rate: float,
                 proposed_leverage: float, max_leverage: float, side: str,
                 **kwargs) -> float:
        """
        Customize leverage for each new trade.

        :param pair: Pair that's currently analyzed
        :param current_time: datetime object, containing the current datetime
        :param current_rate: Rate, calculated based on pricing settings in exit_pricing.
        :param proposed_leverage: A leverage proposed by the bot.
        :param max_leverage: Max leverage allowed on this pair
        :param side: 'long' or 'short' - indicating the direction of the proposed trade
        :return: A leverage amount, which is between 1.0 and max_leverage.
        """
        return 5.0    

特别注意:在config.json文件里
“stake_amount”: 20,
这个后面的20就是你的本金出多少,加上前面的杠杆5.0就表示你加上杠杆的总金额是20×5=100,如果你stake_amount设置成100,加上杠杆就变成500了,要特别注意这个

加杠杆后的止盈止损也要注意
比如你不用杠杆时的 止损为5%,在你加了5倍杠杆后就要把止损设置成25%(不加杠杆止损x杠杆倍数),如果你不这样做,当价格下降1% 你就会被止损,止盈也是同样的道理.


freqtrade交易机器人中关于止损几种模式的解释stoploss的用法
http://www.bgegao.com/2022/06/2326.html
官方文档
https://www.freqtrade.io/en/stable/stoploss/
自定义止损范围 和 ROI
https://www.bgegao.com/2022/06/2362.html

 

为什么修改配置文件后只有部分生效?
不要使用 start/stop 的方式重新启动,应该使用reload配置文件的方式,或者是直接把容器停了,再重新启动容器

如何列出币安交易所 所有合约交易对

docker-compose run --rm freqtrade list-pairs --exchange binance --trading-mode futures --quote USDT
#[--trading-mode 选项 {spot,margin,futures}]

官方文档 https://www.freqtrade.io/en/stable/utils/
列出后你可能还要对数据进一步处理
可以利用Emeditor参考 https://www.bgegao.com/2022/06/2324.html

更多免费的策略 在 user_data 文件夹下面
https://github.com/freqtrade/freqtrade-strategies

一些简单的示例策略供学习研究
https://github.com/freqtrade/freqtrade-strategies/blob/master/user_data/strategies/BreakEven.py
https://github.com/freqtrade/freqtrade-strategies/blob/master/user_data/strategies/berlinguyinca/Simple.py



发表评论

您的电子邮箱地址不会被公开。

45 − 40 =