openfund-taker 1.1.0__py3-none-any.whl → 1.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.
- {openfund_taker-1.1.0.dist-info → openfund_taker-1.1.2.dist-info}/METADATA +1 -1
- {openfund_taker-1.1.0.dist-info → openfund_taker-1.1.2.dist-info}/RECORD +5 -5
- taker/MultiAssetNewTradingBot.py +45 -24
- {openfund_taker-1.1.0.dist-info → openfund_taker-1.1.2.dist-info}/WHEEL +0 -0
- {openfund_taker-1.1.0.dist-info → openfund_taker-1.1.2.dist-info}/entry_points.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
taker/MultiAssetNewTradingBot.py,sha256=
|
1
|
+
taker/MultiAssetNewTradingBot.py,sha256=L3XSiQFcKUTJLpgorsGhKn47b9ijIGFi457gmQS1CvI,37058
|
2
2
|
taker/MultiAssetOldTradingBot.py,sha256=uBh_BxglvcbaHIsWHM7GI9Qa_QjzsxXaXJAAWEOMO5c,15315
|
3
3
|
taker/ThreeLineTradingBot.py,sha256=oXIoQ8z9AzKzk0z13d0ufj2KGBOk5iHJTJNZQRDKA5U,20625
|
4
4
|
taker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -9,7 +9,7 @@ taker/chua_ok_all.py,sha256=2XnZM6QdB3juSE1pqQIJyh2x1XuhlTlnBKNA3owlJ9E,15267
|
|
9
9
|
taker/chua_ok_bot.py,sha256=9SW0ujhi6PfN4yR1JZ9NaA37HtnXJ2QAWUfW52NG68w,13109
|
10
10
|
taker/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
|
11
11
|
taker/main.py,sha256=8cLWzEvQDeELbY5Av7JqkEyYbaNqSbAbVl1tQHXzU8s,1954
|
12
|
-
openfund_taker-1.1.
|
13
|
-
openfund_taker-1.1.
|
14
|
-
openfund_taker-1.1.
|
15
|
-
openfund_taker-1.1.
|
12
|
+
openfund_taker-1.1.2.dist-info/METADATA,sha256=U-ZZhuVxcRcSzG-o8-euHgs_FwChYv_qmrKFhgbRLcM,7502
|
13
|
+
openfund_taker-1.1.2.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
14
|
+
openfund_taker-1.1.2.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
|
15
|
+
openfund_taker-1.1.2.dist-info/RECORD,,
|
taker/MultiAssetNewTradingBot.py
CHANGED
@@ -213,19 +213,19 @@ class MultiAssetNewTradingBot:
|
|
213
213
|
# 获取配置参数
|
214
214
|
period = int(pair_config.get('ema_range_period', 3))
|
215
215
|
|
216
|
-
|
216
|
+
ema_diff = ema.diff().tail(period)
|
217
217
|
|
218
218
|
direction = None
|
219
|
-
if
|
219
|
+
if ema_diff.iloc[-1] < 0:
|
220
220
|
# 下降趋势
|
221
221
|
direction = 0
|
222
|
-
elif
|
222
|
+
elif ema_diff.iloc[-1] > 0:
|
223
223
|
# 上升趋势
|
224
224
|
direction = 1
|
225
225
|
else:
|
226
226
|
# 震荡趋势
|
227
227
|
direction = -1
|
228
|
-
self.logger.debug(f"{symbol}: K线极差={
|
228
|
+
self.logger.debug(f"{symbol}: K线极差={ema_diff.map('{:.9f}'.format).values} ,K线方向={direction}")
|
229
229
|
return direction
|
230
230
|
|
231
231
|
def check_reverse_position(self,symbol,position,pair_config):
|
@@ -256,16 +256,30 @@ class MultiAssetNewTradingBot:
|
|
256
256
|
kline_direction = self.judge_k_line_direction(symbol=symbol, pair_config=pair_config, ema=fastk, klines=klines)
|
257
257
|
# if_inner_range = self.judge_range_diff(symbol=symbol, pair_config=pair_config, prices=fastk)
|
258
258
|
|
259
|
-
self.logger.debug(f"{symbol} cross={last_cross_direction},两线收缩={is_apex},持仓方向={side}")
|
260
|
-
|
259
|
+
self.logger.debug(f"{symbol} cross={last_cross_direction},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction}")
|
260
|
+
order_stop_loss_pct = None
|
261
|
+
# 20250213 增加趋势顶部/底部判断
|
262
|
+
# 金叉逻辑 ,如果是金叉,且是周期顶部,且K线方向是空头,
|
261
263
|
if last_cross_direction and last_cross_direction['cross'] == 1 and is_apex and side == 'long' and kline_direction == 0:
|
262
|
-
self.logger.debug(f"{symbol} 金叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,开始清理多单!!")
|
263
|
-
self.close_all_positions(symbol=symbol, position=position)
|
264
|
+
self.logger.debug(f"{symbol} 金叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction} ,开始清理多单!!")
|
265
|
+
# self.close_all_positions(symbol=symbol, position=position)
|
266
|
+
order_stop_loss_pct = self.stop_loss_pct / 2
|
267
|
+
self.logger.debug(f"{symbol} 全局止损阈值-修正后= {self.stop_loss_pct:.2f} -> {order_stop_loss_pct:.2f}%")
|
268
|
+
|
264
269
|
|
265
270
|
# 死叉逻辑 ,如果是死叉,且是周期底部,且K线方向是多头,就清仓空单
|
266
|
-
|
267
|
-
self.logger.debug(f"{symbol} 死叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,开始清理空单!!")
|
268
|
-
self.close_all_positions(symbol=symbol, position=position)
|
271
|
+
if last_cross_direction and last_cross_direction['cross'] == 0 and is_apex and side == 'short' and kline_direction == 1:
|
272
|
+
self.logger.debug(f"{symbol} 死叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction} ,开始清理空单!!")
|
273
|
+
# self.close_all_positions(symbol=symbol, position=position)
|
274
|
+
order_stop_loss_pct = self.stop_loss_pct / 2
|
275
|
+
self.logger.debug(f"{symbol} 全局止损阈值-修正后= {self.stop_loss_pct:.2f} -> {order_stop_loss_pct:.2f}%")
|
276
|
+
|
277
|
+
# 根据情况 重新修正 止损
|
278
|
+
if order_stop_loss_pct is not None :
|
279
|
+
self.global_symbol_stop_loss_flag[symbol] = False
|
280
|
+
self.set_global_stop_loss(symbol=symbol,position=position,stop_loss_pct=order_stop_loss_pct)
|
281
|
+
else :
|
282
|
+
self.global_symbol_stop_loss_flag[symbol] = False
|
269
283
|
|
270
284
|
except KeyboardInterrupt:
|
271
285
|
self.logger.info("程序收到中断信号,开始退出...")
|
@@ -456,7 +470,7 @@ class MultiAssetNewTradingBot:
|
|
456
470
|
self.logger.warning(f"!! {symbol} 设置止损单时重试次数用完仍未成功设置成功。 ")
|
457
471
|
return False
|
458
472
|
|
459
|
-
def set_global_stop_loss(self, symbol, position,
|
473
|
+
def set_global_stop_loss(self, symbol, position, stop_loss_pct=None):
|
460
474
|
"""设置全局止损
|
461
475
|
|
462
476
|
Args:
|
@@ -470,26 +484,31 @@ class MultiAssetNewTradingBot:
|
|
470
484
|
|
471
485
|
return
|
472
486
|
else :
|
473
|
-
self.logger.debug(f"{symbol} - 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)}
|
474
|
-
|
487
|
+
self.logger.debug(f"{symbol} - 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)} ")
|
488
|
+
if stop_loss_pct is None :
|
489
|
+
stop_loss_pct = self.stop_loss_pct
|
490
|
+
|
475
491
|
# 根据持仓方向计算止损价格
|
492
|
+
side = position['side']
|
476
493
|
if side == 'long':
|
477
|
-
stop_loss_price = position['entryPrice'] * (1 -
|
494
|
+
stop_loss_price = position['entryPrice'] * (1 - stop_loss_pct/100)
|
478
495
|
elif side == 'short':
|
479
|
-
stop_loss_price = position['entryPrice'] * (1 +
|
496
|
+
stop_loss_price = position['entryPrice'] * (1 + stop_loss_pct/100)
|
497
|
+
|
498
|
+
order_price = float(self.round_price_to_tick(symbol, stop_loss_price))
|
480
499
|
|
481
500
|
try:
|
482
501
|
# 设置止损单
|
483
502
|
if_success = self.set_stop_loss_take_profit(
|
484
503
|
symbol=symbol,
|
485
504
|
position=position,
|
486
|
-
stop_loss_price=
|
505
|
+
stop_loss_price=order_price
|
487
506
|
)
|
488
507
|
if if_success:
|
489
508
|
# 设置全局止损标志
|
490
|
-
self.logger.debug(f"{symbol} - {side} 设置全局止损价: {
|
509
|
+
self.logger.debug(f"{symbol} - {side} 设置全局止损价: {order_price}")
|
491
510
|
self.global_symbol_stop_loss_flag[symbol] = True
|
492
|
-
self.global_symbol_take_profit_price[symbol] =
|
511
|
+
self.global_symbol_take_profit_price[symbol] = order_price
|
493
512
|
|
494
513
|
except Exception as e:
|
495
514
|
error_msg = f"{symbol} - 设置止损时发生错误: {str(e)}"
|
@@ -689,9 +708,8 @@ class MultiAssetNewTradingBot:
|
|
689
708
|
return
|
690
709
|
else :
|
691
710
|
self.logger.info(f"{symbol} 全局止损阈值: {self.stop_loss_pct:.2f}%")
|
692
|
-
|
693
|
-
|
694
|
-
self.set_global_stop_loss(symbol, position, side, stop_loss_algo)
|
711
|
+
|
712
|
+
self.set_global_stop_loss(symbol, position)
|
695
713
|
|
696
714
|
return
|
697
715
|
|
@@ -701,6 +719,7 @@ class MultiAssetNewTradingBot:
|
|
701
719
|
abs(float(position['contracts'])) for position in self.fetch_positions()) # 初始总仓位大小
|
702
720
|
while True:
|
703
721
|
try:
|
722
|
+
|
704
723
|
positions = self.fetch_positions()
|
705
724
|
# 检查是否有仓位
|
706
725
|
if not positions:
|
@@ -709,6 +728,7 @@ class MultiAssetNewTradingBot:
|
|
709
728
|
self.reset_take_profie()
|
710
729
|
time.sleep(1)
|
711
730
|
continue
|
731
|
+
self.logger.info("+" * 60)
|
712
732
|
# 检查仓位总规模变化
|
713
733
|
current_position_size = sum(abs(float(position['contracts'])) for position in self.fetch_positions())
|
714
734
|
if current_position_size > previous_position_size:
|
@@ -722,10 +742,11 @@ class MultiAssetNewTradingBot:
|
|
722
742
|
for position in positions:
|
723
743
|
symbol = position['symbol']
|
724
744
|
self.check_total_profit(symbol, position)
|
725
|
-
|
745
|
+
time.sleep(0.1)
|
746
|
+
# 检查仓位和挂单是否有问题
|
726
747
|
self.check_position(symbol, position)
|
727
748
|
|
728
|
-
|
749
|
+
self.logger.info("-" * 60)
|
729
750
|
time.sleep(self.monitor_interval)
|
730
751
|
|
731
752
|
except Exception as e:
|
File without changes
|
File without changes
|