openfund-taker 1.3.13__tar.gz → 1.3.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openfund-taker
3
- Version: 1.3.13
3
+ Version: 1.3.14
4
4
  Summary: Openfund-taker
5
5
  Requires-Python: >=3.9,<4.0
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openfund-taker"
3
- version = "1.3.13"
3
+ version = "1.3.14"
4
4
  description = "Openfund-taker"
5
5
  authors = []
6
6
  readme = "README.md"
@@ -18,11 +18,17 @@ class TrailingSLTaker:
18
18
  self.low_trail_stop_loss_pct = platform_config["all_low_trail_stop_loss_pct"] # 第一档
19
19
  self.trail_stop_loss_pct = platform_config["all_trail_stop_loss_pct"]# 第二档
20
20
  self.higher_trail_stop_loss_pct = platform_config["all_higher_trail_stop_loss_pct"]# 第三档
21
- # 止盈阈值
21
+ # 止损阈值
22
22
  self.low_trail_profit_threshold = platform_config["all_low_trail_profit_threshold"]# 第一档
23
23
  self.first_trail_profit_threshold = platform_config["all_first_trail_profit_threshold"]# 第二档
24
24
  self.second_trail_profit_threshold = platform_config["all_second_trail_profit_threshold"]# 第三档
25
25
 
26
+ # 追踪止盈回撤
27
+ self.open_trail_tp = platform_config.get("open_trail_tp",False)# 是否开启追踪止盈
28
+ self.low_trail_tp_pct = platform_config["all_low_trail_tp_pct"]# 第一档
29
+ self.trail_tp_pct = platform_config["all_trail_tp_pct"]# 第二档
30
+ self.higher_trail_tp_pct = platform_config["all_higher_trail_tp_pct"]# 第三档
31
+
26
32
  self.feishu_webhook = feishu_webhook
27
33
  self.monitor_interval = monitor_interval # 监控循环时间是分仓监控的3倍
28
34
 
@@ -824,8 +830,9 @@ class TrailingSLTaker:
824
830
 
825
831
  total_profit = self.calculate_average_profit(symbol, position)
826
832
 
827
- self.logger.info(f"{symbol} 当前总盈利: {total_profit:.2f}%")
828
- self.send_feishu_notification(f"{symbol} 当前总盈利: {total_profit:.2f}%")
833
+ msg = f"{symbol}: 盈利= {total_profit:.2f}% 开仓= {position['entryPrice']:.10f} 市价= {position['markPrice']:.10f}"
834
+ self.logger.info(msg)
835
+ self.send_feishu_notification(msg)
829
836
 
830
837
  cur_highest_total_profit = self.highest_total_profit.get(symbol, 0.0)
831
838
 
@@ -847,7 +854,7 @@ class TrailingSLTaker:
847
854
 
848
855
  if total_profit > 0.0 :
849
856
  self.logger.info(
850
- f"{symbol} 档位[{current_tier}]: 当前总盈利: {total_profit:.2f}%,最高总盈利: {cur_highest_total_profit:.2f}%")
857
+ f"{symbol} 档位[{current_tier}]: 盈利: {total_profit:.2f}%,最高盈利: {cur_highest_total_profit:.2f}%")
851
858
 
852
859
  '''
853
860
  第一档:低档保护止盈:当盈利达到0.3%触发,要么到第二档,要么回到0.2%止盈
@@ -860,21 +867,35 @@ class TrailingSLTaker:
860
867
  # 根据不同档位设置止损价格,没有单独为交易对设置,用全局参数代替
861
868
  tier_config = {
862
869
  "低档": {
863
- "stop_loss_pct": float(pair_config.get('low_trail_stop_loss_pct',self.low_trail_stop_loss_pct))
870
+ "stop_loss_pct": float(pair_config.get('low_trail_stop_loss_pct',self.low_trail_stop_loss_pct)),
871
+ "trail_tp_pct": float(pair_config.get('low_trail_tp_pct',self.low_trail_tp_pct))
864
872
  },
865
873
  "中档": {
866
- "stop_loss_pct": float(pair_config.get('trail_stop_loss_pct',self.trail_stop_loss_pct))
874
+ "stop_loss_pct": float(pair_config.get('trail_stop_loss_pct',self.trail_stop_loss_pct)),
875
+ "trail_tp_pct": float(pair_config.get('trail_tp_pct',self.trail_tp_pct))
867
876
  },
868
877
  "高档": {
869
- "stop_loss_pct": float(pair_config.get('higher_trail_stop_loss_pct',self.higher_trail_stop_loss_pct))
878
+ "stop_loss_pct": float(pair_config.get('higher_trail_stop_loss_pct',self.higher_trail_stop_loss_pct)),
879
+ "trail_tp_pct": float(pair_config.get('higher_trail_tp_pct',self.higher_trail_tp_pct))
870
880
  }
871
881
  }
872
882
 
873
883
  if current_tier in tier_config:
874
884
  config = tier_config[current_tier]
875
885
 
886
+ # 是否追踪止盈
887
+ if self.open_trail_tp and total_profit < cur_highest_total_profit:
888
+ cur_trail_tp_pct = round((1-total_profit/cur_highest_total_profit), 3)
889
+ trail_tp_pct = float(config['trail_tp_pct'])
890
+ if cur_trail_tp_pct >= trail_tp_pct:
891
+ self.close_all_positions(symbol=symbol, position=position)
892
+ msg = f"{symbol}: 盈利【{current_tier}】保护止盈={trail_tp_pct*100}%,价格回撤 -{cur_trail_tp_pct*100}%: 利润={total_profit:.2f}%,执行止盈平仓"
893
+ self.logger.info(msg)
894
+ self.send_feishu_notification(msg)
895
+ return
896
+
876
897
  # 记录日志
877
- self.logger.debug(f"{symbol} 回撤止盈阈值: {config['stop_loss_pct']*100}%")
898
+ self.logger.debug(f"{symbol}: 回撤止盈阈值: {config['stop_loss_pct']*100}%")
878
899
 
879
900
  # 计算回撤止损价格
880
901
  sl_price = self.calculate_stop_loss_price(
@@ -886,7 +907,7 @@ class TrailingSLTaker:
886
907
  # 检查价格是否变化
887
908
  latest_sl_price = self.exchange.safe_float(self.global_symbol_stop_loss_price, symbol, 0.0)
888
909
  if sl_price == latest_sl_price:
889
- self.logger.debug(f"{symbol} 回撤止损价格{latest_sl_price}未变化,不设置")
910
+ self.logger.debug(f"{symbol}: 回撤止损价格{latest_sl_price}未变化,不设置")
890
911
  return
891
912
 
892
913
  # 设置止损
@@ -909,7 +930,7 @@ class TrailingSLTaker:
909
930
 
910
931
  # 默认全局止损
911
932
  self.set_global_stop_loss(symbol, position)
912
- self.logger.info(f"{symbol} 全局止损阈值: {self.stop_loss_pct:.2f}%")
933
+ self.logger.info(f"{symbol}: 全局止损阈值: {self.stop_loss_pct:.2f}%")
913
934
 
914
935
  return
915
936