openfund-taker 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl

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: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Openfund-taker
5
5
  Requires-Python: >=3.9,<4.0
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,8 +1,8 @@
1
1
  taker/MultiAssetOldTradingBot.py,sha256=uBh_BxglvcbaHIsWHM7GI9Qa_QjzsxXaXJAAWEOMO5c,15315
2
- taker/SMCSLAndTPTaker.py,sha256=rCWoZX3ajjXCeMvBRfGy_WCClsv9UBRc4Ki5CWhRpqY,20670
2
+ taker/SMCSLAndTPTaker.py,sha256=ad8C94XKiJOdQxZw1vj7RI4iZhjwJ-CWkcpTWx6tRPY,21055
3
3
  taker/ThreeLineTradingTaker.py,sha256=ElD9pKDO4nxw5VKNRrvXqyiU0gkV_1Mg_zk-hftfaPs,20553
4
4
  taker/TrailingSLAndTPTaker.py,sha256=OPD1ZNqyM8jZ7Im-bWm_6Cu4_qfwKmNZ30XpbP6-l00,2746
5
- taker/TrailingSLTaker.py,sha256=RF6Kip3SNw7glzwbI0Wcg5Zm1LKPrd-4uPqyvwDd0xw,47231
5
+ taker/TrailingSLTaker.py,sha256=Luz2Ph2-iD3cN9XqOeJCKyiPB4Y6m_3YeQRxQT2L_58,47314
6
6
  taker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  taker/chua_bitget.py,sha256=YY6XK5Bd-wlArsN5BnAfiqE0h1DPkti6i4TEB4F5zDA,12918
8
8
  taker/chua_bn.py,sha256=GnTePWlgDwdHgroBbEp1Ajcsf5_m_Vn_RV63SYzu2jI,10668
@@ -11,7 +11,7 @@ taker/chua_ok_all.py,sha256=2XnZM6QdB3juSE1pqQIJyh2x1XuhlTlnBKNA3owlJ9E,15267
11
11
  taker/chua_ok_bot.py,sha256=9SW0ujhi6PfN4yR1JZ9NaA37HtnXJ2QAWUfW52NG68w,13109
12
12
  taker/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
13
13
  taker/main.py,sha256=Ulz22BV34Mp8ugh-Dior1mIS8n8si8bMi5RCBit2G4U,2774
14
- openfund_taker-2.1.0.dist-info/METADATA,sha256=h9SUZZ3vuoYTqPjjeeVgh9UdIwO_DmwECi1YDLYVEPw,7527
15
- openfund_taker-2.1.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
- openfund_taker-2.1.0.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
17
- openfund_taker-2.1.0.dist-info/RECORD,,
14
+ openfund_taker-2.1.2.dist-info/METADATA,sha256=vpEluDSD2KO5q5OM68AyeupRN4eLp0HNyTfHM_i5yC0,7527
15
+ openfund_taker-2.1.2.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
+ openfund_taker-2.1.2.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
17
+ openfund_taker-2.1.2.dist-info/RECORD,,
taker/SMCSLAndTPTaker.py CHANGED
@@ -283,7 +283,10 @@ class SMCSLAndTPTaker(TrailingSLTaker):
283
283
  else:
284
284
 
285
285
  # 默认全局止损
286
- self.set_global_stop_loss(symbol=symbol, position=position, pair_config=pair_config ,kLines = kLines)
286
+ if_success = self.set_global_stop_loss(symbol=symbol, position=position, pair_config=pair_config ,kLines = kLines)
287
+ if if_success:
288
+ # 更新回撤止损价格
289
+ self.global_symbol_take_profit_flag[symbol] = False
287
290
 
288
291
  def find_liquidity(self, symbol, data, side) -> pd.DataFrame:
289
292
  """
@@ -338,14 +341,15 @@ class SMCSLAndTPTaker(TrailingSLTaker):
338
341
 
339
342
  return df_valid_liquidities.loc[result_indices].sort_index(ascending=False)
340
343
 
341
- def calculate_tp_price_by_liquidity(self, symbol, position, df_liquidities, tp_sl_ratio=1.5, offset=1) -> float:
344
+ def calculate_tp_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, tp_sl_ratio=1.5, offset=1) -> float:
342
345
  """_summary_
343
346
  计算止盈价格,根据流动性,做多则止盈价格在流动性之上,做空则止盈价格在流动性之下。
344
347
  Args:
345
348
  symbol (_type_): _description_
346
349
  position (_type_): _description_
347
350
  df_liquidities (_type_): _description_
348
- strategy (_type_): _description_
351
+ stop_loss_pct (int, optional): _description_. Defaults to 2.
352
+ tp_sl_ratio (float, optional): _description_. Defaults to 1.5.
349
353
  offset (int, optional): _description_. Defaults to 1.
350
354
 
351
355
  Returns:
@@ -358,8 +362,9 @@ class SMCSLAndTPTaker(TrailingSLTaker):
358
362
  is_buy = position['side'] == 'long'
359
363
  price_col = 'Up' if is_buy else 'Dn'
360
364
 
361
- sl_price = self.global_symbol_stop_loss_price.get(symbol, float(position['markPrice']))
365
+ # sl_price = self.global_symbol_stop_loss_price.get(symbol, float(position['markPrice']))
362
366
  entry_price = float(position['entryPrice'])
367
+ sl_price = self.calculate_sl_price_by_pct(symbol, position['side'], stop_loss_pct)
363
368
  threshold = 0.0
364
369
  if is_buy and sl_price > 0 :
365
370
  threshold = float(self.round_price_to_tick(symbol, (entry_price - sl_price ) * tp_sl_ratio + entry_price))
@@ -432,7 +437,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
432
437
  self.logger.info(f"{symbol} : 没有找到流动性,不设置止盈")
433
438
  return
434
439
 
435
- tp_price = self.calculate_tp_price_by_liquidity(symbol, position, htf_liquidity, self.all_TP_SL_ratio)
440
+ tp_price = self.calculate_tp_price_by_liquidity(symbol, position, htf_liquidity, self.stop_loss_pct, self.all_TP_SL_ratio)
436
441
 
437
442
  self.cancel_all_algo_orders(symbol=symbol, attachType='TP')
438
443
 
taker/TrailingSLTaker.py CHANGED
@@ -661,8 +661,21 @@ class TrailingSLTaker:
661
661
 
662
662
  return True
663
663
 
664
+
665
+ def calculate_sl_price_by_pct(self, symbol, side, sl_pct) -> float:
666
+
667
+ if side == 'long':
668
+ sl_price = position['entryPrice'] * (1 - sl_pct/100)
669
+
670
+ elif side == 'short':
671
+ sl_price = position['entryPrice'] * (1 + sl_pct/100)
672
+
673
+
674
+ sl_order_price = float(self.round_price_to_tick(symbol, sl_price))
675
+
676
+ return sl_order_price
664
677
 
665
- def set_global_stop_loss(self, symbol, position, pair_config , stop_loss_pct=None, kLines=None):
678
+ def set_global_stop_loss(self, symbol, position, pair_config , stop_loss_pct=None, kLines=None) -> bool:
666
679
  """设置全局止损
667
680
 
668
681
  Args:
@@ -672,7 +685,7 @@ class TrailingSLTaker:
672
685
 
673
686
  """
674
687
  # 如果已经触发过全局止损并且有止损单,则跳过
675
- self.logger.debug(f"{symbol} : 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)} ={self.global_symbol_stop_loss_price.get(symbol, 0.0)}")
688
+ self.logger.debug(f"{symbol} : 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)} global_sl_price={self.global_symbol_stop_loss_price.get(symbol, 0.0)}")
676
689
  if self.global_symbol_stop_loss_flag.get(symbol, False):
677
690
  return
678
691
 
@@ -681,19 +694,9 @@ class TrailingSLTaker:
681
694
  stop_loss_pct = self.stop_loss_pct
682
695
 
683
696
  # 根据持仓方向计算止损价格
684
- side = position['side']
685
- mark_price = position['markPrice']
686
- if side == 'long':
687
- # tp_price = position['entryPrice'] * (1 + stop_loss_pct*2/100)
688
- sl_price = position['entryPrice'] * (1 - stop_loss_pct/100)
689
-
697
+ side = position['side']
690
698
 
691
- elif side == 'short':
692
- # tp_price = position['entryPrice'] * (1 - stop_loss_pct*2/100)
693
- sl_price = position['entryPrice'] * (1 + stop_loss_pct/100)
694
-
695
-
696
- sl_order_price = float(self.round_price_to_tick(symbol, sl_price))
699
+ sl_order_price = self.calculate_sl_price_by_pct(symbol, side, stop_loss_pct)
697
700
  # tp_order_price = float(self.round_price_to_tick(symbol, tp_price))
698
701
 
699
702
  # 验证止损价格是否合理20250312
@@ -753,6 +756,8 @@ class TrailingSLTaker:
753
756
  self.global_symbol_stop_loss_flag[symbol] = True
754
757
  self.global_symbol_stop_loss_price[symbol] = sl_order_price
755
758
 
759
+ return if_success
760
+
756
761
  except Exception as e:
757
762
  error_msg = f"{symbol} : 设置止损时发生错误, {str(e)}"
758
763
  self.logger.error(error_msg)
@@ -779,7 +784,7 @@ class TrailingSLTaker:
779
784
 
780
785
  # 计算回撤止盈价格
781
786
  def calculate_stop_loss_price(self, symbol, position, stop_loss_pct, offset=1) -> float:
782
- tick_size = float(self.exchange.market(symbol)['precision']['price'])
787
+ tick_size = float(self.get_tick_size(symbol))
783
788
  market_price = position['markPrice']
784
789
  entry_price = position['entryPrice']
785
790
  side = position['side']