openfund-taker 2.2.6__py3-none-any.whl → 2.2.7__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-2.2.6.dist-info → openfund_taker-2.2.7.dist-info}/METADATA +1 -1
- openfund_taker-2.2.7.dist-info/RECORD +16 -0
- taker/SMCSLAndTPTaker.py +62 -82
- taker/ThreeLineTradingTaker.py +3 -1
- taker/TrailingSLAndTPTaker.py +6 -4
- taker/TrailingSLTaker.py +241 -142
- taker/main.py +17 -35
- openfund_taker-2.2.6.dist-info/RECORD +0 -17
- taker/MultiAssetOldTradingBot.py +0 -300
- {openfund_taker-2.2.6.dist-info → openfund_taker-2.2.7.dist-info}/WHEEL +0 -0
- {openfund_taker-2.2.6.dist-info → openfund_taker-2.2.7.dist-info}/entry_points.txt +0 -0
- /taker/{chua_bitget.py → history_code/chua_bitget.py} +0 -0
- /taker/{chua_bn.py → history_code/chua_bn.py} +0 -0
- /taker/{chua_ok.py → history_code/chua_ok.py} +0 -0
- /taker/{chua_ok_all.py → history_code/chua_ok_all.py} +0 -0
- /taker/{chua_ok_bot.py → history_code/chua_ok_bot.py} +0 -0
- /taker/{config.py → history_code/config.py} +0 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
taker/SMCSLAndTPTaker.py,sha256=zJCtwyzIuDtbxMdLOwRbpUE60o9fKe-tNWuiuej4RGs,27621
|
2
|
+
taker/ThreeLineTradingTaker.py,sha256=NGEXd4baCfzF4ToGb9tQWXRMweFBpImyh2v4WcKLK3A,20580
|
3
|
+
taker/TrailingSLAndTPTaker.py,sha256=W-kj0BhPXqusO8z4zlDU_nb1L6L7TT8jEhCSgMkEF9U,2831
|
4
|
+
taker/TrailingSLTaker.py,sha256=j-qAy8qwqYP9lXiYp-p_qWN6hH-x7nsg80g6o8Sc2KI,53456
|
5
|
+
taker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
taker/history_code/chua_bitget.py,sha256=YY6XK5Bd-wlArsN5BnAfiqE0h1DPkti6i4TEB4F5zDA,12918
|
7
|
+
taker/history_code/chua_bn.py,sha256=GnTePWlgDwdHgroBbEp1Ajcsf5_m_Vn_RV63SYzu2jI,10668
|
8
|
+
taker/history_code/chua_ok.py,sha256=5pPAoEYbFuKxfZwqNvOO890s-2cy6n69QiI0ZA0GTCQ,12474
|
9
|
+
taker/history_code/chua_ok_all.py,sha256=2XnZM6QdB3juSE1pqQIJyh2x1XuhlTlnBKNA3owlJ9E,15267
|
10
|
+
taker/history_code/chua_ok_bot.py,sha256=9SW0ujhi6PfN4yR1JZ9NaA37HtnXJ2QAWUfW52NG68w,13109
|
11
|
+
taker/history_code/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
|
12
|
+
taker/main.py,sha256=gud7NagfxDrB4FrggmO4nKNEHbcn0_4jThCOaeGEJuw,2101
|
13
|
+
openfund_taker-2.2.7.dist-info/METADATA,sha256=2eaMRyEdfUjQ9VSlskgYA5ayYPYxNMXTfTptE9uDILM,7529
|
14
|
+
openfund_taker-2.2.7.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
15
|
+
openfund_taker-2.2.7.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
|
16
|
+
openfund_taker-2.2.7.dist-info/RECORD,,
|
taker/SMCSLAndTPTaker.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
from typing import override
|
2
|
+
from ccxt.base import precise
|
2
3
|
import pandas as pd
|
3
4
|
from decimal import Decimal
|
4
5
|
|
@@ -6,14 +7,14 @@ from decimal import Decimal
|
|
6
7
|
from taker.TrailingSLTaker import TrailingSLTaker
|
7
8
|
|
8
9
|
class SMCSLAndTPTaker(TrailingSLTaker):
|
9
|
-
def __init__(self,g_config, platform_config, feishu_webhook=None, monitor_interval=4,logger=None):
|
10
|
-
super().__init__(g_config, platform_config, feishu_webhook, monitor_interval,logger)
|
10
|
+
def __init__(self,g_config, platform_config, common_config=None, feishu_webhook=None, monitor_interval=4,logger=None):
|
11
|
+
super().__init__(g_config, platform_config, common_config, feishu_webhook, monitor_interval,logger)
|
11
12
|
self.global_symbol_take_profit_flag = {} # 记录每个symbol是否设置全局止盈标志
|
12
13
|
self.global_symbol_take_profit_price = {} # 记录每个symbol的止盈价格
|
13
14
|
self.htf_liquidities_TP = {}
|
14
15
|
self.htf_liquidities_SL = {}
|
15
|
-
self.all_TP_SL_ratio = float(platform_config.get("all_TP_SL_ratio",1.5)) #The profit-loss ratio 盈亏比
|
16
|
-
self.open_trail_profit = bool(platform_config.get("open_trail_profit",True)) # 开仓是否设置止盈
|
16
|
+
# self.all_TP_SL_ratio = float(platform_config.get("all_TP_SL_ratio",1.5)) #The profit-loss ratio 盈亏比
|
17
|
+
# self.open_trail_profit = bool(platform_config.get("open_trail_profit",True)) # 开仓是否设置止盈
|
17
18
|
|
18
19
|
@override
|
19
20
|
def check_reverse_position(self,symbol,position,pair_config):
|
@@ -45,8 +46,13 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
45
46
|
|
46
47
|
for index in range(1, len(data)):
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
prev_up = self.toDecimal(data.at[index - 1, 'Up'])
|
50
|
+
curr_high = self.toDecimal(data.at[index, 'high'])
|
51
|
+
prev_dn = self.toDecimal(data.at[index - 1, 'Dn'])
|
52
|
+
curr_low = self.toDecimal(data.at[index, 'low'])
|
53
|
+
|
54
|
+
data.at[index, 'Up'] = max(prev_up, curr_high)
|
55
|
+
data.at[index, 'Dn'] = min(prev_dn, curr_low)
|
50
56
|
data.at[index, 'pos'] = data.at[index - 1, 'pos']
|
51
57
|
data.at[index, 'iUp'] = data.at[max(0,index - 1), 'iUp'] if data.at[max(0,index - 1), 'iUp'] is not None else index
|
52
58
|
data.at[index, 'iDn'] = data.at[max(0,index - 1), 'iDn'] if data.at[max(0,index - 1), 'iDn'] is not None else index
|
@@ -56,10 +62,10 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
56
62
|
pvtLo = self.is_pivot_low(data, index, prd, check_bounds)
|
57
63
|
|
58
64
|
if pvtHi:
|
59
|
-
data.at[index, 'Up'] = data.at[index, 'high']
|
65
|
+
data.at[index, 'Up'] = self.toDecimal(data.at[index, 'high'])
|
60
66
|
data.at[index, 'iUp'] = index
|
61
67
|
if pvtLo:
|
62
|
-
data.at[index, 'Dn'] = data.at[index, 'low']
|
68
|
+
data.at[index, 'Dn'] = self.toDecimal(data.at[index, 'low'])
|
63
69
|
data.at[index, 'iDn'] = index
|
64
70
|
# 寻找Bullish结构
|
65
71
|
if data.at[index, 'Up'] > data.at[index - 1, 'Up']:
|
@@ -207,6 +213,8 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
207
213
|
pair_config: 交易对配置
|
208
214
|
kLines: K线数据
|
209
215
|
"""
|
216
|
+
|
217
|
+
|
210
218
|
|
211
219
|
if self.open_trail_profit and self.global_symbol_stop_loss_flag.get(symbol,False):
|
212
220
|
|
@@ -227,10 +235,13 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
227
235
|
ctf_df_with_struct = self.build_struct(df=ctf_df,prd=ctf_prd)
|
228
236
|
# self.logger.debug(f"{symbol} : {ctf} ctf_df_with_struct\n{ctf_df_with_struct}")
|
229
237
|
|
238
|
+
marketPrice = self.toDecimal(position['markPrice'])
|
239
|
+
|
240
|
+
|
230
241
|
# 寻找流动性
|
231
242
|
htf_liquidity_SL = self.htf_liquidities_SL.get(symbol,None)
|
232
243
|
if htf_liquidity_SL is None:
|
233
|
-
htf_liquidity_SL = self.detect_liquidity_for_SL(symbol, ctf_df_with_struct, position['side'],
|
244
|
+
htf_liquidity_SL = self.detect_liquidity_for_SL(symbol, ctf_df_with_struct, position['side'], marketPrice)
|
234
245
|
self.htf_liquidities_SL[symbol] = htf_liquidity_SL
|
235
246
|
|
236
247
|
if len(htf_liquidity_SL) == 0:
|
@@ -238,46 +249,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
238
249
|
return
|
239
250
|
|
240
251
|
sl_price = self.calculate_trailing_sl_price_by_liquidity(symbol, position, htf_liquidity_SL, self.stop_loss_pct)
|
241
|
-
|
242
|
-
|
243
|
-
# current_tier = '无'
|
244
|
-
# # 各档止盈逻辑
|
245
|
-
# # 确定当前盈利档位
|
246
|
-
# if self.open_trail_profit and total_profihtf_liquidities_SLt >= self.second_trail_profit_threshold:
|
247
|
-
# current_tier = "高档"
|
248
|
-
|
249
|
-
# elif self.open_trail_profit and total_profit>= self.first_trail_profit_threshold:
|
250
|
-
# current_tier = "中档"
|
251
|
-
|
252
|
-
# elif self.open_trail_profit and total_profit >= self.low_trail_profit_threshold:
|
253
|
-
# current_tier = "低档"
|
254
|
-
|
255
|
-
# # 根据不同档位设置止损价格,没有单独为交易对设置,用全局参数代替
|
256
|
-
# tier_config = {
|
257
|
-
# "低档": {
|
258
|
-
# "stop_loss_pct": float(pair_config.get('low_trail_stop_loss_pct',self.low_trail_stop_loss_pct)),
|
259
|
-
|
260
|
-
# },
|
261
|
-
# "中档": {
|
262
|
-
# "stop_loss_pct": float(pair_config.get('trail_stop_loss_pct',self.trail_stop_loss_pct)),
|
263
|
-
|
264
|
-
# },
|
265
|
-
# "高档": {
|
266
|
-
# "stop_loss_pct": float(pair_config.get('higher_trail_stop_loss_pct',self.higher_trail_stop_loss_pct)),
|
267
|
-
|
268
|
-
# }
|
269
|
-
# }
|
270
|
-
|
271
|
-
# if current_tier in tier_config and self.open_trail_profit:
|
272
|
-
# config = tier_config[current_tier]
|
273
|
-
|
274
|
-
|
275
|
-
# # 计算回撤止损价格
|
276
|
-
# sl_price = self.calculate_stop_loss_price(
|
277
|
-
# symbol=symbol,
|
278
|
-
# position=position,
|
279
|
-
# stop_loss_pct=config['stop_loss_pct']
|
280
|
-
# )
|
252
|
+
|
281
253
|
|
282
254
|
# 检查价格是否变化
|
283
255
|
latest_sl_price = self.global_symbol_stop_loss_price.get(symbol,0.0)
|
@@ -334,7 +306,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
334
306
|
|
335
307
|
return df[df.index == df[col_prefix]].sort_index(ascending=False)
|
336
308
|
|
337
|
-
def detect_liquidity_for_TP(self, symbol, data, side , market_price) -> pd.DataFrame:
|
309
|
+
def detect_liquidity_for_TP(self, symbol, data, side , market_price: Decimal) -> pd.DataFrame:
|
338
310
|
"""
|
339
311
|
TP校对流动性,用市场价格校验流动性是否有效,做多则流动性在市场价格之上,做空流动性要在市场价格之下。
|
340
312
|
Args:
|
@@ -374,7 +346,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
374
346
|
|
375
347
|
return df_valid_liquidities.loc[result_indices].sort_index(ascending=False)
|
376
348
|
|
377
|
-
def detect_liquidity_for_SL(self, symbol, data, side, market_price) -> pd.DataFrame:
|
349
|
+
def detect_liquidity_for_SL(self, symbol, data, side, market_price:Decimal) -> pd.DataFrame:
|
378
350
|
"""
|
379
351
|
SL校对流动性,用市场价格校验流动性是否有效,做多则流动性在市场价格之下,做空流动性要在市场价格之上。
|
380
352
|
Args:
|
@@ -449,7 +421,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
449
421
|
return took_out_df.sort_index(ascending=False)
|
450
422
|
|
451
423
|
|
452
|
-
def calculate_trailing_sl_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, offset=1) ->
|
424
|
+
def calculate_trailing_sl_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, offset=1) -> Decimal:
|
453
425
|
"""
|
454
426
|
计算回撤止损价格,根据流动性,做多则回撤止损价格在流动性之下,做空则回撤止损价格在流动性之上。
|
455
427
|
Args:
|
@@ -459,19 +431,21 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
459
431
|
stop_loss_pct (int, optional): 回撤百分比. Defaults to 2.
|
460
432
|
offset (int, optional): 偏移量. Defaults to 1.
|
461
433
|
Returns:
|
462
|
-
|
434
|
+
Decimal: 回撤止损价格
|
463
435
|
"""
|
464
436
|
sl_price = self.calculate_sl_price_by_pct(symbol, position, stop_loss_pct)
|
437
|
+
precision = self.get_precision_length(symbol)
|
438
|
+
|
465
439
|
|
466
440
|
is_buy = position['side'] == 'long'
|
467
441
|
price_col = 'Dn' if is_buy else 'Up'
|
468
|
-
self.logger.debug(f"{symbol} : SL side={position['side']} sl_price={sl_price} SL的扫荡流动性=\n {df_liquidities[['timestamp',price_col, 'is_extreme']]}")
|
442
|
+
self.logger.debug(f"{symbol} : SL side={position['side']} sl_price={sl_price:.{precision}} \n SL的扫荡流动性=\n {df_liquidities[['timestamp',price_col, 'is_extreme']]}")
|
469
443
|
|
470
|
-
valid_mask = df_liquidities[price_col] > sl_price if is_buy else df_liquidities[price_col] < sl_price
|
471
|
-
df_valid_liquidities = df_liquidities[valid_mask]
|
444
|
+
# valid_mask = df_liquidities[price_col] > sl_price if is_buy else df_liquidities[price_col] < sl_price
|
445
|
+
# df_valid_liquidities = df_liquidities[valid_mask]
|
472
446
|
# 获取止损价格
|
473
447
|
# trailing_sl = df_valid_liquidities.iloc[0][price_col] if len(df_valid_liquidities) > 0 else sl_price
|
474
|
-
trailing_sl =
|
448
|
+
trailing_sl = self.toDecimal(df_liquidities[price_col].max() if is_buy else df_liquidities[price_col].min())
|
475
449
|
|
476
450
|
# 计算移动止损价格 , 做多则止损价格在流动性之下tick_size,做空则止损价格在流动性之上tick_size。
|
477
451
|
tick_size = self.get_tick_size(symbol)
|
@@ -482,7 +456,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
482
456
|
|
483
457
|
return self.round_price_to_tick(symbol, trailing_sl)
|
484
458
|
|
485
|
-
def calculate_tp_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, tp_sl_ratio=1.5, offset=1) ->
|
459
|
+
def calculate_tp_price_by_liquidity(self, symbol, position, df_liquidities, stop_loss_pct=2, tp_sl_ratio=1.5, offset=1) -> Decimal:
|
486
460
|
"""_summary_
|
487
461
|
计算止盈价格,根据流动性,做多则止盈价格在流动性之上,做空则止盈价格在流动性之下。
|
488
462
|
Args:
|
@@ -494,10 +468,10 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
494
468
|
offset (int, optional): _description_. Defaults to 1.
|
495
469
|
|
496
470
|
Returns:
|
497
|
-
|
471
|
+
Decimal: _description_
|
498
472
|
"""
|
499
473
|
|
500
|
-
tp_price = 0.0
|
474
|
+
tp_price = Decimal('0.0')
|
501
475
|
# market_price = float(position['markPrice'])
|
502
476
|
|
503
477
|
is_buy = position['side'] == 'long'
|
@@ -505,34 +479,34 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
505
479
|
|
506
480
|
# sl_price = self.global_symbol_stop_loss_price.get(symbol, float(position['markPrice']))
|
507
481
|
# 获取开仓价格和止损价格
|
508
|
-
entry_price =
|
482
|
+
entry_price = self.toDecimal(position['entryPrice'])
|
509
483
|
sl_price = self.calculate_sl_price_by_pct(symbol, position, stop_loss_pct)
|
510
484
|
|
511
485
|
# 计算止盈阈值
|
512
|
-
threshold = 0.0
|
486
|
+
threshold = Decimal('0.0')
|
513
487
|
if sl_price <= 0:
|
514
488
|
return threshold
|
515
489
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
#
|
521
|
-
else
|
522
|
-
|
523
|
-
threshold = self.round_price_to_tick(symbol, entry_price - price_diff * Decimal(tp_sl_ratio))
|
524
|
-
|
490
|
+
|
491
|
+
# 计算开仓价格和止损价格的差值
|
492
|
+
price_diff = abs(entry_price - sl_price)
|
493
|
+
|
494
|
+
# 根据方向计算止盈阈值
|
495
|
+
target_price = entry_price + price_diff * self.toDecimal(tp_sl_ratio) if is_buy else entry_price - price_diff * self.toDecimal(tp_sl_ratio)
|
496
|
+
threshold = self.round_price_to_tick(symbol, target_price)
|
525
497
|
|
526
|
-
|
498
|
+
precision = self.get_precision_length(symbol)
|
499
|
+
|
500
|
+
# 根据方向过滤有效的流动性价格
|
501
|
+
df_liquidities[price_col] = df_liquidities[price_col].apply(self.toDecimal)
|
527
502
|
valid_mask = df_liquidities[price_col] > threshold if is_buy else df_liquidities[price_col] < threshold
|
528
503
|
df_valid_liquidities = df_liquidities[valid_mask]
|
529
|
-
|
530
|
-
|
504
|
+
|
505
|
+
self.logger.debug(f"{symbol} : TP threshold={threshold:.{precision}} sl_price={sl_price:.{precision}} 有效的流动=\n {df_valid_liquidities[['timestamp','Up','Dn']]}")
|
506
|
+
|
507
|
+
# 获取止盈价格并确保其满足方向要求
|
531
508
|
tp_price = df_valid_liquidities.iloc[0][price_col] if len(df_valid_liquidities) > 0 else threshold
|
532
|
-
if is_buy
|
533
|
-
tp_price = Decimal(max(tp_price, threshold))
|
534
|
-
else:
|
535
|
-
tp_price = Decimal(min(tp_price, threshold))
|
509
|
+
tp_price = self.toDecimal(max(tp_price, threshold) if is_buy else min(tp_price, threshold))
|
536
510
|
tick_size = self.get_tick_size(symbol)
|
537
511
|
|
538
512
|
# 计算止盈价格 , 做多则止盈价格在流动性之下tick_size,做空则止盈价格在流动性之上tick_size。
|
@@ -565,9 +539,12 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
565
539
|
"""
|
566
540
|
根据结构设置止盈
|
567
541
|
"""
|
542
|
+
|
543
|
+
presision = self.get_precision_length(symbol)
|
544
|
+
|
568
545
|
# 如果已经触发过全局止盈,则跳过
|
569
546
|
if self.global_symbol_take_profit_flag.get(symbol, False):
|
570
|
-
self.logger.info(f"{symbol} : 已经设置过全局止盈 tp_price={self.global_symbol_take_profit_price[symbol]}")
|
547
|
+
self.logger.info(f"{symbol} : 已经设置过全局止盈 tp_price={self.global_symbol_take_profit_price[symbol]:.{presision}}")
|
571
548
|
return
|
572
549
|
|
573
550
|
smc_strategy = pair_config.get('smc_strategy',{})
|
@@ -583,7 +560,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
583
560
|
# 寻找流动性
|
584
561
|
htf_liquidity = self.htf_liquidities_TP.get(symbol,None)
|
585
562
|
if htf_liquidity is None:
|
586
|
-
htf_liquidity = self.detect_liquidity_for_TP(symbol, htf_df_with_struct, position['side'], position['markPrice'])
|
563
|
+
htf_liquidity = self.detect_liquidity_for_TP(symbol, htf_df_with_struct, position['side'], self.toDecimal(position['markPrice']))
|
587
564
|
self.htf_liquidities_TP[symbol] = htf_liquidity
|
588
565
|
|
589
566
|
if len(htf_liquidity) <= 0:
|
@@ -597,7 +574,7 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
597
574
|
if self.set_take_profit(symbol, position, tp_price):
|
598
575
|
self.global_symbol_take_profit_flag[symbol] = True
|
599
576
|
self.global_symbol_take_profit_price[symbol] = tp_price
|
600
|
-
self.logger.info(f"{symbol} : [{position['side']}] 设置全局止盈价={tp_price}")
|
577
|
+
self.logger.info(f"{symbol} : [{position['side']}] 设置全局止盈价={tp_price:.{presision}}")
|
601
578
|
|
602
579
|
|
603
580
|
def check_total_profit(self, symbol, position):
|
@@ -610,7 +587,10 @@ class SMCSLAndTPTaker(TrailingSLTaker):
|
|
610
587
|
if total_profit > cur_highest_total_profit:
|
611
588
|
self.highest_total_profit[symbol] = total_profit
|
612
589
|
|
613
|
-
|
590
|
+
precision = self.get_precision_length(symbol)
|
591
|
+
entryPrice = self.toDecimal(position['entryPrice'])
|
592
|
+
marketPrice = self.toDecimal(position['markPrice'])
|
593
|
+
msg = f"{symbol} : 盈利={total_profit:.2f}% 方向={position['side']} 开仓={entryPrice:.{precision}f} 市价={marketPrice:.{precision}f}"
|
614
594
|
self.logger.info(msg)
|
615
595
|
self.send_feishu_notification(msg)
|
616
596
|
|
taker/ThreeLineTradingTaker.py
CHANGED
@@ -5,7 +5,9 @@ import logging
|
|
5
5
|
import requests
|
6
6
|
from logging.handlers import TimedRotatingFileHandler
|
7
7
|
|
8
|
-
|
8
|
+
'''
|
9
|
+
三线策略 废弃
|
10
|
+
'''
|
9
11
|
class ThreeLineTradingTaker:
|
10
12
|
def __init__(self, config, feishu_webhook=None, monitor_interval=60):
|
11
13
|
self.stop_loss_pct = config["all_stop_loss_pct"] # 全局止损百分比
|
taker/TrailingSLAndTPTaker.py
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
|
2
|
+
from decimal import Decimal
|
2
3
|
from typing import override
|
3
4
|
from taker.TrailingSLTaker import TrailingSLTaker
|
4
5
|
'''
|
5
6
|
自动设置移动止损单
|
6
7
|
'''
|
7
8
|
class TrailingSLAndTPTaker(TrailingSLTaker):
|
8
|
-
def __init__(self,g_config, platform_config, feishu_webhook=None, monitor_interval=4,logger=None):
|
9
|
-
super().__init__(g_config, platform_config, feishu_webhook, monitor_interval,logger)
|
9
|
+
def __init__(self,g_config, platform_config, common_config, feishu_webhook=None, monitor_interval=4,logger=None):
|
10
|
+
super().__init__(g_config, platform_config, common_config, feishu_webhook, monitor_interval,logger)
|
10
11
|
self.global_symbol_take_profit_flag = {} # 记录每个symbol是否设置全局止盈标志
|
11
12
|
self.global_symbol_take_profit_price = {} # 记录每个symbol的止盈价格
|
12
|
-
self.all_TP_SL_ratio = float(platform_config.get("all_TP_SL_ratio",1.5)) #The profit-loss ratio 盈亏比
|
13
|
+
# self.all_TP_SL_ratio = float(platform_config.get("all_TP_SL_ratio",1.5)) #The profit-loss ratio 盈亏比
|
14
|
+
|
13
15
|
self.all_take_profit_pct = self.stop_loss_pct * self.all_TP_SL_ratio
|
14
16
|
|
15
|
-
def set_stop_loss_take_profit(self, symbol, position, stop_loss_price=None, take_profit_price=None) -> bool:
|
17
|
+
def set_stop_loss_take_profit(self, symbol, position, stop_loss_price:Decimal=None, take_profit_price:Decimal=None) -> bool:
|
16
18
|
if not stop_loss_price and not take_profit_price:
|
17
19
|
self.logger.warning(f"{symbol}: No stop loss price or take profit price provided for {symbol}")
|
18
20
|
return False
|