openfund-taker 1.3.1__py3-none-any.whl → 1.3.4__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.3.1.dist-info → openfund_taker-1.3.4.dist-info}/METADATA +1 -1
- {openfund_taker-1.3.1.dist-info → openfund_taker-1.3.4.dist-info}/RECORD +8 -7
- taker/{ThreeLineTradingBot.py → ThreeLineTradingTaker.py} +1 -3
- taker/TrailingSLAndTPTaker.py +22 -0
- taker/TrailingSLTaker.py +22 -21
- taker/main.py +3 -2
- {openfund_taker-1.3.1.dist-info → openfund_taker-1.3.4.dist-info}/WHEEL +0 -0
- {openfund_taker-1.3.1.dist-info → openfund_taker-1.3.4.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
taker/MultiAssetOldTradingBot.py,sha256=uBh_BxglvcbaHIsWHM7GI9Qa_QjzsxXaXJAAWEOMO5c,15315
|
2
|
-
taker/
|
3
|
-
taker/
|
2
|
+
taker/ThreeLineTradingTaker.py,sha256=ElD9pKDO4nxw5VKNRrvXqyiU0gkV_1Mg_zk-hftfaPs,20553
|
3
|
+
taker/TrailingSLAndTPTaker.py,sha256=rx3tw9TwFCpqnz3e0WlTtFVcn8mBbPHtp62n3RF86Kg,1144
|
4
|
+
taker/TrailingSLTaker.py,sha256=og_H02pTmUJISPAsHlLIBmNyTD3DLXuTnOTE-XnkkOY,42598
|
4
5
|
taker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
6
|
taker/chua_bitget.py,sha256=YY6XK5Bd-wlArsN5BnAfiqE0h1DPkti6i4TEB4F5zDA,12918
|
6
7
|
taker/chua_bn.py,sha256=GnTePWlgDwdHgroBbEp1Ajcsf5_m_Vn_RV63SYzu2jI,10668
|
@@ -8,8 +9,8 @@ taker/chua_ok.py,sha256=5pPAoEYbFuKxfZwqNvOO890s-2cy6n69QiI0ZA0GTCQ,12474
|
|
8
9
|
taker/chua_ok_all.py,sha256=2XnZM6QdB3juSE1pqQIJyh2x1XuhlTlnBKNA3owlJ9E,15267
|
9
10
|
taker/chua_ok_bot.py,sha256=9SW0ujhi6PfN4yR1JZ9NaA37HtnXJ2QAWUfW52NG68w,13109
|
10
11
|
taker/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
|
11
|
-
taker/main.py,sha256=
|
12
|
-
openfund_taker-1.3.
|
13
|
-
openfund_taker-1.3.
|
14
|
-
openfund_taker-1.3.
|
15
|
-
openfund_taker-1.3.
|
12
|
+
taker/main.py,sha256=QCEjINu3IgwWEGcuquHzeYjKJYAQrPe8ctQhMoIb9SA,2561
|
13
|
+
openfund_taker-1.3.4.dist-info/METADATA,sha256=pumU5NKxk5BBlZrKwsY2OvWKi_gKSIZ_3yUHcneouz0,7527
|
14
|
+
openfund_taker-1.3.4.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
15
|
+
openfund_taker-1.3.4.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
|
16
|
+
openfund_taker-1.3.4.dist-info/RECORD,,
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
import ccxt
|
3
|
-
from ccxt.base.exchange import Exchange
|
4
|
-
from ccxt.base.types import Order
|
5
3
|
import time
|
6
4
|
import logging
|
7
5
|
import requests
|
8
6
|
from logging.handlers import TimedRotatingFileHandler
|
9
7
|
|
10
8
|
|
11
|
-
class
|
9
|
+
class ThreeLineTradingTaker:
|
12
10
|
def __init__(self, config, feishu_webhook=None, monitor_interval=60):
|
13
11
|
self.stop_loss_pct = config["all_stop_loss_pct"] # 全局止损百分比
|
14
12
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
from taker.TrailingSLTaker import TrailingSLTaker
|
3
|
+
'''
|
4
|
+
自动设置移动止损单
|
5
|
+
'''
|
6
|
+
class TrailingSLAndTPTaker(TrailingSLTaker):
|
7
|
+
def __init__(self,g_config, platform_config, feishu_webhook=None, monitor_interval=4,logger=None):
|
8
|
+
super().__init__(g_config, platform_config, feishu_webhook, monitor_interval,logger)
|
9
|
+
self.all_TP_LS_ratio = float(platform_config.get("all_TP_LS_ratio",1.5)) #The profit-loss ratio 盈亏比
|
10
|
+
self.all_take_profit_pct = self.stop_loss_pct * self.all_TP_LS_ratio
|
11
|
+
|
12
|
+
def set_stop_loss_take_profit(self, symbol, position, stop_loss_price=None, take_profit_price=None) -> bool:
|
13
|
+
is_successful = super().set_stop_loss_take_profit(symbol, position, stop_loss_price, take_profit_price)
|
14
|
+
# take_profile_pct = self.stop_loss_pct * 2
|
15
|
+
order_take_profit_price = take_profit_price
|
16
|
+
if take_profit_price is None:
|
17
|
+
order_take_profit_price = self.calculate_take_profile_price(symbol, position, self.all_take_profit_pct)
|
18
|
+
is_successful = self.set_take_profit(symbol, position, order_take_profit_price)
|
19
|
+
|
20
|
+
|
21
|
+
return is_successful
|
22
|
+
|
taker/TrailingSLTaker.py
CHANGED
@@ -13,8 +13,8 @@ class TrailingSLTaker:
|
|
13
13
|
self.trading_pairs_config = g_config.get('tradingPairs', {})
|
14
14
|
|
15
15
|
|
16
|
-
self.stop_loss_pct = platform_config
|
17
|
-
#
|
16
|
+
self.stop_loss_pct = float(platform_config.get("all_stop_loss_pct",2)) # 全局止损百分比
|
17
|
+
# 回撤比例
|
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"]# 第三档
|
@@ -52,6 +52,9 @@ class TrailingSLTaker:
|
|
52
52
|
})
|
53
53
|
self.logger = logger
|
54
54
|
self.position_mode = self.get_position_mode() # 获取持仓模式
|
55
|
+
|
56
|
+
def get_pair_config(self,symbol):
|
57
|
+
return self.trading_pairs_config.get(symbol,{})
|
55
58
|
# 获取市场信息
|
56
59
|
def getMarket(self,symbol):
|
57
60
|
self.exchange.load_markets()
|
@@ -467,7 +470,7 @@ class TrailingSLTaker:
|
|
467
470
|
while retry_count < max_retries:
|
468
471
|
try:
|
469
472
|
|
470
|
-
self.logger.debug(f"{symbol}: {orderSide} - TP at {
|
473
|
+
self.logger.debug(f"{symbol}: {orderSide} - TP at {adjusted_price} Starting.... ")
|
471
474
|
|
472
475
|
self.exchange.create_order(
|
473
476
|
symbol=symbol,
|
@@ -479,7 +482,7 @@ class TrailingSLTaker:
|
|
479
482
|
params=tp_params
|
480
483
|
)
|
481
484
|
|
482
|
-
self.logger.info(f"{symbol}: TP at {
|
485
|
+
self.logger.info(f"{symbol}: TP at {adjusted_price} Done.")
|
483
486
|
break
|
484
487
|
|
485
488
|
|
@@ -550,7 +553,7 @@ class TrailingSLTaker:
|
|
550
553
|
while retry_count < max_retries:
|
551
554
|
try:
|
552
555
|
|
553
|
-
self.logger.debug(f"{symbol}: {orderSide} - Pre SL at {
|
556
|
+
self.logger.debug(f"{symbol}: {orderSide} - Pre SL at {adjusted_price} Starting.... ")
|
554
557
|
|
555
558
|
self.exchange.create_order(
|
556
559
|
symbol=symbol,
|
@@ -562,7 +565,7 @@ class TrailingSLTaker:
|
|
562
565
|
amount=amount,
|
563
566
|
params=sl_params
|
564
567
|
)
|
565
|
-
self.logger.info(f"{symbol}: SL at {
|
568
|
+
self.logger.info(f"{symbol}: SL at {adjusted_price} Done.")
|
566
569
|
break
|
567
570
|
|
568
571
|
|
@@ -675,17 +678,15 @@ class TrailingSLTaker:
|
|
675
678
|
# 计算止盈价格。
|
676
679
|
|
677
680
|
if side == 'long':
|
678
|
-
|
679
|
-
base_price = entry_price * (1-take_profile_pct)
|
680
|
-
take_profile_price = entry_price + base_price - offset * tick_size
|
681
|
+
take_profile_price = entry_price * (1+take_profile_pct/100) - offset * tick_size
|
681
682
|
|
682
683
|
|
683
684
|
elif side == 'short':
|
684
685
|
|
685
|
-
base_price = entry_price * (1-take_profile_pct)
|
686
|
-
take_profile_price = entry_price -
|
686
|
+
# base_price = entry_price * (1-take_profile_pct)
|
687
|
+
take_profile_price = entry_price * (1-take_profile_pct/100) + offset * tick_size
|
687
688
|
|
688
|
-
return take_profile_price
|
689
|
+
return float(self.round_price_to_tick(symbol,take_profile_price))
|
689
690
|
|
690
691
|
# 计算回撤止盈价格
|
691
692
|
def calculate_stop_loss_price(self, symbol, position, stop_loss_pct, offset=1) -> float:
|
@@ -711,7 +712,7 @@ class TrailingSLTaker:
|
|
711
712
|
stop_loss_price = entry_price - base_price + offset * tick_size
|
712
713
|
if latest_stop_loss_price :
|
713
714
|
stop_loss_price = min(stop_loss_price,latest_stop_loss_price)
|
714
|
-
return stop_loss_price
|
715
|
+
return float(self.round_price_to_tick(symbol,stop_loss_price))
|
715
716
|
|
716
717
|
# 市价仓位平仓
|
717
718
|
def close_all_positions(self,symbol,position):
|
@@ -790,9 +791,9 @@ class TrailingSLTaker:
|
|
790
791
|
self.check_reverse_position(symbol=symbol, position=position, pair_config=pair_config)
|
791
792
|
|
792
793
|
# 检查止损是否触发止盈
|
793
|
-
if self.check_stop_loss_trigger(symbol, position):
|
794
|
-
|
795
|
-
|
794
|
+
# if self.check_stop_loss_trigger(symbol, position):
|
795
|
+
# self.close_all_positions(symbol=symbol, position=position)
|
796
|
+
# return
|
796
797
|
|
797
798
|
|
798
799
|
def check_total_profit(self, symbol, position):
|
@@ -834,17 +835,17 @@ class TrailingSLTaker:
|
|
834
835
|
|
835
836
|
'''
|
836
837
|
# 各档止盈逻辑
|
837
|
-
|
838
|
-
#
|
838
|
+
pair_config = self.get_pair_config(symbol)
|
839
|
+
# 根据不同档位设置止损价格,没有单独为交易对设置,用全局参数代替
|
839
840
|
tier_config = {
|
840
841
|
"低档": {
|
841
|
-
"stop_loss_pct": float(self.low_trail_stop_loss_pct)
|
842
|
+
"stop_loss_pct": float(pair_config.get('low_trail_stop_loss_pct',self.low_trail_stop_loss_pct))
|
842
843
|
},
|
843
844
|
"中档": {
|
844
|
-
"stop_loss_pct": float(self.trail_stop_loss_pct)
|
845
|
+
"stop_loss_pct": float(pair_config.get('trail_stop_loss_pct',self.trail_stop_loss_pct))
|
845
846
|
},
|
846
847
|
"高档": {
|
847
|
-
"stop_loss_pct": float(self.higher_trail_stop_loss_pct)
|
848
|
+
"stop_loss_pct": float(pair_config.get('higher_trail_stop_loss_pct',self.higher_trail_stop_loss_pct))
|
848
849
|
}
|
849
850
|
}
|
850
851
|
|
taker/main.py
CHANGED
@@ -3,7 +3,8 @@ import yaml
|
|
3
3
|
from logging.handlers import TimedRotatingFileHandler
|
4
4
|
|
5
5
|
from taker.TrailingSLTaker import TrailingSLTaker
|
6
|
-
from taker.
|
6
|
+
from taker.TrailingSLAndTPTaker import TrailingSLAndTPTaker
|
7
|
+
from taker.ThreeLineTradingTaker import ThreeLineTradingTaker
|
7
8
|
|
8
9
|
def build_logger(log_config) -> logging.Logger:
|
9
10
|
# 配置日志
|
@@ -56,7 +57,7 @@ def main():
|
|
56
57
|
package_name = __package__ or "taker"
|
57
58
|
|
58
59
|
logger.info(f" ++ {package_name}:{version} is doing...")
|
59
|
-
bot =
|
60
|
+
bot = TrailingSLAndTPTaker(config_data, platform_config, feishu_webhook=feishu_webhook_url, monitor_interval=monitor_interval,logger=logger)
|
60
61
|
bot.monitor_total_profit()
|
61
62
|
# bot = ThreeLineTradingBot(platform_config, feishu_webhook=feishu_webhook_url, monitor_interval=monitor_interval)
|
62
63
|
# bot.monitor_klines()
|
File without changes
|
File without changes
|