openfund-taker 2.1.14__py3-none-any.whl → 2.1.16__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.14
3
+ Version: 2.1.16
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=7Gfq4v6nnK-zVdXKe1-lhLlzfTg8BOEmhlRJ81vjDLA,20743
2
+ taker/SMCSLAndTPTaker.py,sha256=wIm8UNlEwET9D5XtthEv7HPqEATZTENgOPU2eDgacNU,23823
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=CIjlYqIM_1h4GTMGnCV67SQnk0QryPDL3u_kXJ3qioc,47853
5
+ taker/TrailingSLTaker.py,sha256=m2ltc3A8CaKKuaq4Zb-6bxYVjrHgmSuqA0rxmyzMXrc,47150
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=-EdrzLG6xK0nauItj3eRC8_xva2PnS9CQdzeFJI-6Wc,2769
14
- openfund_taker-2.1.14.dist-info/METADATA,sha256=gDxo5iUe4Pl5pNdTwkzpL6iBbq6bxdADoQ2bCbIQDiI,7528
15
- openfund_taker-2.1.14.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
- openfund_taker-2.1.14.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
17
- openfund_taker-2.1.14.dist-info/RECORD,,
14
+ openfund_taker-2.1.16.dist-info/METADATA,sha256=LyNQFiOpfWhMC85pj-yth_qeoP2-ckYD8lAxKAU7u9I,7528
15
+ openfund_taker-2.1.16.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
16
+ openfund_taker-2.1.16.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
17
+ openfund_taker-2.1.16.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.0.1
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
taker/SMCSLAndTPTaker.py CHANGED
@@ -202,6 +202,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
202
202
  position: 仓位信息
203
203
  profit: 利润
204
204
  pair_config: 交易对配置
205
+ kLines: K线数据
205
206
  """
206
207
 
207
208
  total_profit = profit
@@ -278,26 +279,25 @@ class SMCSLAndTPTaker(TrailingSLTaker):
278
279
  # 更新回撤止损价格
279
280
  self.global_symbol_take_profit_flag[symbol] = False
280
281
 
281
- def find_liquidity(self, symbol, data, side) -> pd.DataFrame:
282
+ def find_liquidity(self, symbol, data, liquidity_type="BSL") -> pd.DataFrame:
282
283
  """
283
284
  寻找流动性,根据side判断是做多还是做空,做多则寻找iUp,做空则寻找iDn
284
285
  Args:
285
286
  symbol (str): 交易对
286
287
  data (pd.DataFrame): 数据
287
- side (str): 交易方向,'long' 或'short'
288
+ liquidity_type (str): 流动性类型,'BSL' 或 'BSL'
289
+
288
290
  """
289
291
  df = data.copy()
290
292
 
291
- is_buy = side == 'long'
292
-
293
- col_prefix = 'iUp' if is_buy else 'iDn'
294
- price_col = 'Up' if is_buy else 'Dn'
293
+ is_buy = liquidity_type == 'BSL'
294
+ col_prefix = 'iDn' if is_buy else 'iUp'
295
295
 
296
296
  return df[df.index == df[col_prefix]].sort_index(ascending=False)
297
297
 
298
- def detect_liquidity(self, symbol, data, side , market_price) -> pd.DataFrame:
298
+ def detect_liquidity_for_TP(self, symbol, data, side , market_price) -> pd.DataFrame:
299
299
  """
300
- 校对流动性,用市场价格校验流动性是否有效,做多则流动性在市场价格之上,做空流动性要在市场价格之下。
300
+ TP校对流动性,用市场价格校验流动性是否有效,做多则流动性在市场价格之上,做空流动性要在市场价格之下。
301
301
  Args:
302
302
  symbol (str): 交易对
303
303
  side (str): 交易方向,'long' 或 'short'
@@ -305,13 +305,17 @@ class SMCSLAndTPTaker(TrailingSLTaker):
305
305
  market_price (float): 当前市场价格
306
306
 
307
307
  """
308
- df_liquidities = self.find_liquidity(symbol, data, side)
309
-
310
- df_valid_liquidities = df_liquidities.copy()
311
308
  is_buy = side == 'long'
312
309
  col_prefix = 'iUp' if is_buy else 'iDn'
313
310
  price_col = 'Up' if is_buy else 'Dn'
314
311
 
312
+ # 设置TP,long寻找SSL,short寻找BSL
313
+ liquidity_type = 'SSL' if is_buy else 'BSL'
314
+
315
+ df_liquidities = self.find_liquidity(symbol, data, liquidity_type=liquidity_type)
316
+
317
+ df_valid_liquidities = df_liquidities.copy()
318
+
315
319
  result_indices = []
316
320
  current_price = float('-inf') if is_buy else float('inf')
317
321
  current_i = float('inf')
@@ -330,6 +334,66 @@ class SMCSLAndTPTaker(TrailingSLTaker):
330
334
  current_i = row[col_prefix]
331
335
 
332
336
  return df_valid_liquidities.loc[result_indices].sort_index(ascending=False)
337
+
338
+ def detect_liquidity_for_SL(self, symbol, data, side, market_price) -> pd.DataFrame:
339
+ """
340
+ SL校对流动性,用市场价格校验流动性是否有效,做多则流动性在市场价格之下,做空流动性要在市场价格之上。
341
+ Args:
342
+ symbol (str): 交易对
343
+ side (str): 交易方向,'long' 或'short'
344
+ df_liquidities (pd.DataFrame): 流动性数据
345
+ market_price (float): 当前市场价格
346
+
347
+ """
348
+ is_buy = side == 'long'
349
+ col_prefix = 'iDn' if is_buy else 'iUp'
350
+ price_col = 'Dn' if is_buy else 'Up'
351
+ # 设置SL,long寻找BSL,short寻找SSL
352
+ liquidity_type = 'BSL' if is_buy else 'SSL'
353
+
354
+ df_liquidities = self.find_liquidity(symbol, data, liquidity_type=liquidity_type)
355
+
356
+ df_valid_liquidities = df_liquidities.copy()
357
+ df_valid_liquidities['was_swept'] = None
358
+ df_valid_liquidities['took_out'] = None
359
+
360
+ result_indices = []
361
+ current_price = float('inf') if is_buy else float('-inf')
362
+ current_i = float('inf')
363
+ took_out_status = False
364
+
365
+ # 遍历并筛选符合条件的记录,找到扫过流动性的
366
+ for idx, row in df_valid_liquidities.iterrows():
367
+ if not is_buy:
368
+ if row[price_col] > market_price:
369
+ if row[price_col] > current_price and row[col_prefix] < current_i:
370
+ result_indices.append(idx)
371
+
372
+ if current_i != float('inf') and not df_valid_liquidities.at[current_i, 'took_out'] :
373
+ df_valid_liquidities.at[idx, 'took_out'] = True
374
+
375
+ current_price = row[price_col]
376
+ current_i = row[col_prefix]
377
+
378
+ else:
379
+ df_valid_liquidities.at[idx, 'was_swept'] = True
380
+
381
+ else:
382
+ if row[price_col] < market_price:
383
+ if row[price_col] < current_price and row[col_prefix] < current_i:
384
+ result_indices.append(idx)
385
+
386
+ if current_i != float('inf') and not df_valid_liquidities.at[current_i, 'took_out'] :
387
+ df_valid_liquidities.at[idx, 'took_out'] = True
388
+ current_price = row[price_col]
389
+ current_i = row[col_prefix]
390
+ else:
391
+ df_valid_liquidities.at[idx, 'was_swept'] = True
392
+
393
+ # 过滤出took_out为True的记录
394
+ took_out_df = df_valid_liquidities.loc[result_indices]
395
+ took_out_df = took_out_df[took_out_df['took_out'] == True]
396
+ return took_out_df.sort_index(ascending=False)
333
397
 
334
398
  def calculate_tp_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, tp_sl_ratio=1.5, offset=1) -> float:
335
399
  """_summary_
@@ -420,7 +484,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
420
484
  # 寻找流动性
421
485
  htf_liquidity = self.htf_liquidities.get(symbol,None)
422
486
  if htf_liquidity is None:
423
- htf_liquidity = self.detect_liquidity(symbol, htf_df_with_struct, position['side'], position['markPrice'])
487
+ htf_liquidity = self.detect_liquidity_for_TP(symbol, htf_df_with_struct, position['side'], position['markPrice'])
424
488
  self.htf_liquidities[symbol] = htf_liquidity
425
489
 
426
490
  if len(htf_liquidity) <= 0:
taker/TrailingSLTaker.py CHANGED
@@ -1028,26 +1028,19 @@ class TrailingSLTaker:
1028
1028
  # previous_position_size = sum(
1029
1029
  # abs(float(position['contracts'])) for position in self.fetch_positions()) # 初始总仓位大小
1030
1030
  while True:
1031
+
1032
+ # 检查是否有仓位
1031
1033
  try:
1032
-
1033
1034
  positions = self.fetch_positions()
1034
- # 检查是否有仓位
1035
- if not positions:
1036
- # self.logger.debug("没有持仓,等待下一次检查...")
1037
- self.close_all_cache()
1038
- time.sleep(1)
1039
- continue
1035
+
1036
+ except Exception as e:
1037
+ self.logger.warning(f"获取仓位信息时发生错误: {e}")
1038
+ time.sleep(1)
1039
+ continue
1040
+
1041
+ try:
1040
1042
 
1041
1043
  self.logger.info("+" * 60)
1042
- # 检查仓位总规模变化
1043
- # current_position_size = sum(abs(float(position['contracts'])) for position in self.fetch_positions())
1044
- # if current_position_size > previous_position_size:
1045
- # self.send_feishu_notification(f"检测到仓位变化操作,重置最高盈利和档位状态")
1046
- # self.logger.info("检测到新增仓位操作,重置最高盈利和档位状态")
1047
- # self.reset_highest_profit_and_tier()
1048
- # previous_position_size = current_position_size
1049
- # time.sleep(0.1)
1050
- # continue # 跳过本次循环
1051
1044
 
1052
1045
  for position in positions:
1053
1046
  symbol = position['symbol']