女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

Freqtrade:簡單的加密貨幣自動交易機器人

科技綠洲 ? 來源:Python實用寶典 ? 作者:Python實用寶典 ? 2023-10-30 10:45 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

Freqtrade 是一個用 Python 編寫的免費開源加密貨幣交易機器人。它旨在支持所有主要交易所并通過 Telegram 或 webUI 進行控制。功能包含回測、繪圖和資金管理工具以及通過機器學習的策略優化。
特性:

1. 基于 Python 3.8+ :適用于任何操作系統 - Windows、macOS 和 Linux
2. 持久性 :持久性是通過 sqlite 實現的。
3. Dry-run :不花錢運行機器人。
4. 回測模擬買入/賣出策略。
5. 通過機器學習進行策略優化 :使用機器學習通過真實的交易所數據優化買入/賣出策略參數。
6. 邊緣頭寸規模計算您的勝率、風險回報率、最佳止損位并在為每個特定市場建立頭寸之前調整頭寸規模。
7. 白名單加密貨幣 :選擇你要交易的加密貨幣或使用動態白名單。
8. 黑名單加密貨幣 :選擇你想要避免的加密貨幣。
9. 內置 WebUI :內置 Web UI 來管理你的機器人。
10. 可通過 Telegram管理:使用 Telegram 管理機器人。
11. 以法定貨幣顯示盈虧 :以法定貨幣顯示你的盈虧。
12. 表現狀態報告 :提供你當前交易的表現狀態。

1.準備

開始之前,你要確保Python和pip已經成功安裝在電腦上,如果沒有,可以訪問這篇文章:超詳細Python安裝指南 進行安裝。

**(可選1) **如果你用Python的目的是數據分析,可以直接安裝Anaconda:Python數據分析與挖掘好幫手—Anaconda,它內置了Python和pip.

**(可選2) **此外,推薦大家用VSCode編輯器,它有許多的優點:Python 編程的最好搭檔—VSCode 詳細指南

在Linux/MacOS下,三行命令就能完成安裝:

git clone -b develop https://github.com/freqtrade/freqtrade.git
cd freqtrade
./setup.sh --install

Windows環境下打開Cmd(開始—運行—CMD),輸入命令安裝依賴:

git clone https://github.com/freqtrade/freqtrade.git
cd freqtrade
# 安裝ta-lib
pip install build_helpers/TA_Lib-0.4.24-cp38-cp38-win_amd64.whl
pip install -r requirements.txt
pip install -e .
freqtrade

請注意,此處安裝ta-lib時項目方提供了python3.8/3.9/3.10,其他Python版本請自行搜索下載。

輸入freqtrade時,顯示以下信息說明安裝成功:

(freqtrade) D:CODEtraderfreqtrade >freqtrade
2022-02-17 19:40:50,174 - freqtrade - ERROR - Usage of Freqtrade requires a subcommand to be specified.
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...]`.
To see the full list of options available, please use `freqtrade --help` or `freqtrade < command > --help`.

2.快速開始

下面教你如何開發一個簡單的交易策略。

一個策略文件往往包含這些東西:

  • 指標
  • 購買規則
  • 賣出規則
  • 建議最低投資回報率
  • 強烈推薦止損

Freqtrade使用 Pandas 作為基礎數據結構,它底層的OHLCV都是以Dataframe的格式存儲的。

Dataframe數據流中每一行數據代表圖表上的一根K線,最新的K線始終是數據庫中最后一根。

dataframe.head()
                       date open high low close volume
0 2021-11-09 23:25:00+00:00  67279.67  67321.84  67255.01  67300.97   44.62253
1 2021-11-09 23:30:00+00:00  67300.97  67301.34  67183.03  67187.01   61.38076
2 2021-11-09 23:35:00+00:00  67187.02  67187.02  67031.93  67123.81  113.42728
3 2021-11-09 23:40:00+00:00  67123.80  67222.40  67080.33  67160.48   78.96008
4 2021-11-09 23:45:00+00:00  67160.48  67160.48  66901.26  66943.37  111.39292

Pandas 提供了計算指標的快速方法。為了從這種速度中受益,建議不要使用循環,而是使用矢量化方法。

矢量化操作在整個數據范圍內執行計算,因此,與遍歷每一行相比,在計算指標時要快得多。

dataframe.loc[(dataframe['rsi'] > 30), 'buy'] = 1

類似于上面這樣的賦值方法,會自動設置rsi大于30的數據的buy列的值為1。

買入規則

def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) - > DataFrame:
    """
    Based on TA indicators, populates the buy signal for the given dataframe
    :param dataframe: DataFrame populated with indicators
    :param metadata: Additional information, like the currently traded pair
    :return: DataFrame with buy column
    """
    dataframe.loc[
        (
            (qtpylib.crossed_above(dataframe['rsi'], 30)) & # Signal: RSI crosses above 30
            (dataframe['tema'] <= dataframe['bb_middleband']) & # Guard
            (dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
            (dataframe['volume'] > 0) # Make sure Volume is not 0
        ),
        'buy'] = 1

    return dataframe

請注意,一定要不修改并返回"open", "high", "low", "close", "volume"列,這些是基礎行情數據,如果返回錯誤的數據將可能會導致一些奇怪數據的產生。

如上所示的方法中,符合條件的數據的buy值會被設為1代表買入,否則為0或nan值。

賣出規則

def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) - > DataFrame:
    """
    Based on TA indicators, populates the sell signal for the given dataframe
    :param dataframe: DataFrame populated with indicators
    :param metadata: Additional information, like the currently traded pair
    :return: DataFrame with buy column
    """
    dataframe.loc[
        (
            (qtpylib.crossed_above(dataframe['rsi'], 70)) & # Signal: RSI crosses above 70
            (dataframe['tema'] > dataframe['bb_middleband']) & # Guard
            (dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
            (dataframe['volume'] > 0) # Make sure Volume is not 0
        ),
        'sell'] = 1
    return dataframe

與買入類似,這里不贅述了。

最小投資回報率

在類中增加這個初始化變量,能控制投資回報率:

minimal_roi = {
    "40": 0.0,
    "30": 0.01,
    "20": 0.02,
    "0": 0.04
}

上述配置意味著:

  • 只要達到 4% 的利潤就賣出
  • 達到 2% 利潤時賣出(20 分鐘后生效)
  • 達到 1% 利潤時賣出(30 分鐘后生效)
  • 交易未虧損時賣出(40 分鐘后生效)

此處的計算包含費用。

要完全禁用 ROI,請將其設置為一個非常高的數字:

minimal_roi = {
    "0": 100
}

雖然從技術上講并沒有完全禁用,但一旦交易達到 10000% 利潤,它就會賣出。

止損

強烈建議設置止損,以保護資金免受不利的劇烈波動。

設置 10% 止損的示例:

stoploss = -0.10

一個完整代碼如下:

上滑查看更多代碼

# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
# flake8: noqa: F401
# isort: skip_file
# --- Do not remove these libs ---
from reimport A
import numpyas np# noqa
import pandasas pd# noqa
from pandasimport DataFrame

from freqtrade.strategyimport (BooleanParameter, CategoricalParameter, DecimalParameter,
IStrategy, IntParameter)

# --------------------------------
# 你自己所需要的模塊放在這里
import talib.abstractas ta
import freqtrade.vendor.qtpylib.indicatorsas qtpylib


# This class is a sample. Feel free to customize it.
class SampleStrategy(IStrategy):
"""
This is a sample strategy to inspire you.
More information in https://www.freqtrade.io/en/latest/strategy-customization/
You can:
:return: a Dataframe with all mandatory indicators for the strategies
- Rename the class name (Do not forget to update class_name)
- Add any methods you want to build your strategy
- Add any lib you need to build your strategy
You must keep:
- the lib in the section "Do not remove these libs"
- the methods: populate_indicators, populate_buy_trend, populate_sell_trend
You should keep:
- timeframe, minimal_roi, stoploss, trailing_*
"""

# Strategy interface version - allow new iterations of the strategy interface.
# Check the documentation or the Sample strategy to get the latest version.
INTERFACE_VERSION =2

# 設定最小投資回報
minimal_roi = {
"60":0.01,
"30":0.02,
"0":0.04
}

# 止損
stoploss =-0.10

# 指標參數
buy_rsi = IntParameter(low=1, high=50, default=30, space='buy', optimize=True, load=True)
sell_rsi = IntParameter(low=50, high=100, default=70, space='sell', optimize=True, load=True)

# K線時間
timeframe ='5m'

# 在新K線出現時執行
process_only_new_candles =False

# These values can be overridden in the "ask_strategy" section in the config.
use_sell_signal =True
sell_profit_only =False
ignore_roi_if_buy_signal =False

# 預準備K線數
startup_candle_count: int =30

# 下單類型
order_types = {
'buy':'limit',
'sell':'limit',
'stoploss':'market',
'stoploss_on_exchange':False
}

# 訂單有效時間(gtc: 除非取消否則一直有效)
order_time_in_force = {
'buy':'gtc',
'sell':'gtc'
}

plot_config = {
'main_plot': {
'tema': {},
'sar': {'color':'white'},
},
'subplots': {
"MACD": {
'macd': {'color':'blue'},
'macdsignal': {'color':'orange'},
},
"RSI": {
'rsi': {'color':'red'},
}
}
}

def informative_pairs(self):
"""
Define additional, informative pair/interval combinations to be cached from the exchange.
These pair/interval combinations are non-tradeable, unless they are part
of the whitelist as well.
For more information, please consult the documentation
:return: List of tuples in the format (pair, interval)
Sample: return [("ETH/USDT", "5m"),
("BTC/USDT", "15m"),
]
"""

return []

def populate_indicators(self, dataframe: DataFrame, metadata: dict) - > DataFrame:
"""
Adds several different TA indicators to the given DataFrame
Performance Note: For the best performance be frugal on the number of indicators
you are using. Let uncomment only the indicator you are using in your strategies
or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
:param dataframe: Dataframe with data from the exchange
:param metadata: Additional information, like the currently traded pair
:return: a Dataframe with all mandatory indicators for the strategies
"""


# Momentum Indicators
# ------------------------------------

dataframe['adx'] = ta.ADX(dataframe)
dataframe['rsi'] = ta.RSI(dataframe)
stoch_fast = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch_fast['fastd']
dataframe['fastk'] = stoch_fast['fastk']

# MACD
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']

# MFI
dataframe['mfi'] = ta.MFI(dataframe)

# Bollinger Bands
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_middleband'] = bollinger['mid']
dataframe['bb_upperband'] = bollinger['upper']
dataframe["bb_percent"] = (
(dataframe["close"] - dataframe["bb_lowerband"]) /
(dataframe["bb_upperband"] - dataframe["bb_lowerband"])
)
dataframe["bb_width"] = (
(dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"]
)

# Parabolic SAR
dataframe['sar'] = ta.SAR(dataframe)

# TEMA - Triple Exponential Moving Average
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)

hilbert = ta.HT_SINE(dataframe)
dataframe['htsine'] = hilbert['sine']
dataframe['htleadsine'] = hilbert['leadsine']

return dataframe

def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) - > DataFrame:
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame populated with indicators
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with buy column
"""

dataframe.loc[
(
# Signal: RSI crosses above 30
(qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)) &
(dataframe['tema'] <= dataframe['bb_middleband']) &# Guard: tema below BB middle
(dataframe['tema'] > dataframe['tema'].shift(1)) &# Guard: tema is raising
(dataframe['volume'] >0)# Make sure Volume is not 0
),'buy'] =1

return dataframe

def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) - > DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame populated with indicators
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with sell column
"""

dataframe.loc[
(
# Signal: RSI crosses above 70
(qtpylib.crossed_above(dataframe['rsi'], self.sell_rsi.value)) &
(dataframe['tema'] > dataframe['bb_middleband']) &# Guard: tema above BB middle
(dataframe['tema'] < dataframe['tema'].shift(1)) &# Guard: tema is falling
(dataframe['volume'] >0)# Make sure Volume is not 0
),'sell'] =1
return dataframe

3.啟動機器人

啟動機器人前還需要設定配置,配置模板在 config/examples 下面。

比如幣安的配置,你還需要輸入key和secret:

"exchange": {
        "name": "binance",
        "key": "your_exchange_key",
        "secret": "your_exchange_secret",
        ......
  }
}

啟動機器人:

freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory -c path/far/far/away/config.json

--strategy-path 指定策略文件位置

-c 參數指定配置文件位置

比如我把策略放在了user_data/strategies下,配置放在了config_examples下,這么輸入命令啟動機器人即可:

freqtrade trade --strategy SampleStrategy --strategy-path user_data/strategies -c config_examples/config_binance.example.json

由于篇幅問題,本文只是介紹了freqtrade的冰山一角,在啟動機器人前,一定要進行回測并進行模擬交易。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 機器人
    +關注

    關注

    213

    文章

    29728

    瀏覽量

    212819
  • 數據
    +關注

    關注

    8

    文章

    7256

    瀏覽量

    91820
  • 操作系統
    +關注

    關注

    37

    文章

    7144

    瀏覽量

    125564
  • python
    +關注

    關注

    56

    文章

    4827

    瀏覽量

    86701
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    自動接水機器人

    這個機器人比較高大,但也是由金屬拼裝件套件拼裝而成。控制板是蘋果板,機器人的底部安裝有巡線傳感器,可以自動循黑線前進,這樣只需從你的房間或者辦公位置布置一條黑線到飲水機,機器人就可以沿
    發表于 03-25 14:28

    工業機器人應用廣泛

    和壓機的加工設備中。碼垛機:工業機器人將瓦楞紙箱或其他包裝物品以規定的圖案裝載到托盤上。機器人碼垛機依靠固定位置或具有特殊工具的頂置式龍門架機器人,與各個負載組件相連接,構建簡單到托盤
    發表于 09-07 17:20

    幣圈熊市之下如何進行投資?炒幣機器人幣小秘為你答疑

    ` 在數字貨幣市場中是否存在智能化的量化交易炒幣機器人或系統,而這些炒幣機器人又是否真實有效是很大投資者迫切想要了解的,現在有一款智能數資管家橫空出世,它叫做幣小秘。根據財經網
    發表于 06-30 16:10

    加密貨幣交易機器人日益流行的原因是什么?

    機器執行任務的速度比人類快得多。事實上,眾所周知,99%的華爾街交易是由機器人進行的。根據加密貨幣市場,由
    發表于 09-11 14:27 ?798次閱讀

    加密貨幣市場正在引入交易機器人以滿足交易的需求

    機器人可以讓交易者成功地交易并使用可定制的參數監控他們的頭寸,而無需一直粘在屏幕上。。此外,人類情感錯誤方面以及無法與機器人在多個交易所同時
    發表于 11-27 14:33 ?1016次閱讀

    跨平臺加密貨幣交易所Exenium介紹

    Exenium是一個跨平臺加密貨幣交易所,旨在解決當前高度波動的加密市場面臨的復雜問題。 作為世界上第一個聊天機器人
    發表于 12-19 13:44 ?898次閱讀

    2019年全球最佳數字貨幣智能自動搬磚套利機器人指南

    貨幣交易并不容易。然而,有許多人每天都在磨練比特幣和山寨幣的交易藝術。許多數字貨幣交易者使用交易
    發表于 02-19 18:12 ?1092次閱讀

    自動智能交易機器人軟件有哪些種類?

    貨幣自動交易機器人軟件的新時代已經使許多人獲得了財務自由。現代技術不需要您接受個人培訓,您不必閱讀大量有關證券的書籍,您也不必并試圖了解您所在國家政策和經濟。分析是
    發表于 02-21 17:14 ?675次閱讀

    94%數字貨幣交易將引入智能機器人、 你的對手或許不再是人類

    問卷,有94表示未來三年內將引入機器人自動化數字貨幣交易程序。其中,62%的人表示目前已有1/4的
    發表于 02-28 12:35 ?324次閱讀

    數字貨幣通證經濟催生殺手級應用——云端智能交易機器人

    。? ? ? ?2019將成為區塊鏈3.0元年,區塊鏈3.0時代的到來將催生出各個行業通證經濟市場的藍海。 伴隨著數字貨幣、人工智能、大數據、機器學習等技術的發展,尤其是數字貨幣智能交易
    發表于 02-28 18:24 ?330次閱讀

    阿爾法:全自動智能搬磚機器人軟件有哪些種類?

    。? ? ? ??數字貨幣自動交易機器人軟件的新時代已經使許多人獲得了財務自由。現代技術不需要您接受個人培訓,您不必閱讀大量有關證券的書籍,您也不必并試圖了解您所在國家政策和經濟。分析
    發表于 03-06 10:46 ?549次閱讀

    什么是加密貨幣交易機器人

    加密貨幣交易機器人是一種計算機程序,可以在適當的時間內自動進行各種加密
    發表于 08-29 10:36 ?1417次閱讀

    如何利用機器人加密貨幣交易中獲得實際利潤

    目前有幾種類型的交易機器人,包括套利機器人在內,能從不同交易所的價格差異中套利。通常每個交易所的比特幣價格都會有所不同;例如,Bitstam
    發表于 09-05 14:17 ?1275次閱讀

    加密貨幣交易機器人是怎樣運作起來的

    加密貨幣交易機器人通過訪問交易平臺上的數據來為用戶工作。
    發表于 09-16 10:20 ?859次閱讀

    Freqtrade加密貨幣算法交易軟件

    freqtrade.zip
    發表于 06-06 15:37 ?2次下載
    <b class='flag-5'>Freqtrade</b><b class='flag-5'>加密</b><b class='flag-5'>貨幣</b>算法<b class='flag-5'>交易</b>軟件