添加策略
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# flake8: noqa: F401
|
||||
# isort: skip_file
|
||||
# --- Do not remove these imports ---
|
||||
from dingtalk import DingTalkBot
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from datetime import datetime, timedelta, timezone
|
||||
@@ -37,12 +38,22 @@ import talib.abstract as ta
|
||||
from technical import qtpylib
|
||||
|
||||
|
||||
webhook = "https://oapi.dingtalk.com/robot/send?access_token=21de667159edadd33172c6ec414a2addf9c6359189350ffd36819d2a20e8a0f4" # 填写你的webhook
|
||||
secret = "SEC43a0fa0b29717f98637a119b92a0bd5f7b2b6da671bdd2bd1279ed8323454d5e" # 填写你的加签token(如果有),否则留空
|
||||
|
||||
# CTA 群机器人
|
||||
# webhook = "https://oapi.dingtalk.com/robot/send?access_token=87c7abfcdd69b699c32da4e4f5981cd2ca6b0445474fc6ffb36f2ed0f6262fbb"
|
||||
# secret = "SECf3d6b43f2f8a87ab91feffd052e71ec314fbf57a1842e483fe07af3c0a0e5aa6"
|
||||
dingtalk = DingTalkBot(webhook, secret)
|
||||
|
||||
|
||||
class CCIMultiTimeframeSpotStrategy(IStrategy):
|
||||
# 策略参数
|
||||
INTERFACE_VERSION = 3
|
||||
|
||||
minimal_roi = {"0": 100}
|
||||
stoploss = -1
|
||||
use_custom_stoploss = False
|
||||
trailing_stop = False
|
||||
timeframe = '4h'
|
||||
|
||||
@@ -50,6 +61,37 @@ class CCIMultiTimeframeSpotStrategy(IStrategy):
|
||||
exit_profit_only = False
|
||||
ignore_roi_if_entry_signal = False
|
||||
|
||||
def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:
|
||||
# 交易对
|
||||
trading_pair = pair
|
||||
|
||||
# 时间
|
||||
fill_time = order.order_filled_date or current_time
|
||||
|
||||
# 价格
|
||||
fill_price = order.average or order.price
|
||||
|
||||
# 买入还是卖出
|
||||
side = order.ft_order_side # 'buy' 或 'sell'
|
||||
|
||||
# 仓位(当前持仓数量)
|
||||
position = trade.amount
|
||||
|
||||
# 或者使用日志
|
||||
logger.info(
|
||||
f"订单成交 - 交易对: {trading_pair}, "
|
||||
f"时间: {fill_time}, "
|
||||
f"价格: {fill_price}, "
|
||||
f"方向: {side}, "
|
||||
f"仓位: {position}"
|
||||
)
|
||||
# if self.config["runmode"].value in ("live", "dry_run"):
|
||||
logger.info(f"11111111{self.config['runmode']}")
|
||||
# dingtalk.send_text(
|
||||
# content=f"订单成交 - 交易对: {trading_pair}, 时间: {fill_time}, 价格: {fill_price}, 方向: {side}, 仓位: {position}")
|
||||
|
||||
return None
|
||||
|
||||
def TD(self, dataframe:DataFrame):
|
||||
close = dataframe['close'].to_list()
|
||||
td = [0,0,0,0]
|
||||
@@ -98,6 +140,7 @@ class CCIMultiTimeframeSpotStrategy(IStrategy):
|
||||
|
||||
# dataframe['adx_hist_4h'] = ta.ADX(dataframe['macdhist_4h'])
|
||||
dataframe['TD'] = self.TD(dataframe)
|
||||
dataframe["atr"] = ta.ATR(dataframe, timeperiod=14)
|
||||
|
||||
logger.info(dataframe.tail())
|
||||
return dataframe
|
||||
@@ -132,3 +175,14 @@ class CCIMultiTimeframeSpotStrategy(IStrategy):
|
||||
|
||||
return dataframe
|
||||
|
||||
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,
|
||||
current_rate: float, current_profit: float, after_fill: bool,
|
||||
**kwargs) -> float | None:
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
candle = dataframe.iloc[-1].squeeze()
|
||||
side = 1 if trade.is_short else -1
|
||||
return stoploss_from_absolute(current_rate + (side * candle["atr"] * 3),
|
||||
current_rate=current_rate,
|
||||
is_short=trade.is_short,
|
||||
leverage=trade.leverage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user