bitmart优化完成
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -736,4 +736,3 @@ class WeexTransaction:
|
||||
if __name__ == '__main__':
|
||||
transaction = WeexTransaction(tge_id=191303)
|
||||
transaction.action()
|
||||
|
||||
|
||||
@@ -66,16 +66,16 @@ class KlineAnalyzer:
|
||||
|
||||
# 前跌后涨包住 -> 做多
|
||||
if (KlineAnalyzer.is_bullish(curr) and
|
||||
KlineAnalyzer.is_bearish(prev) and
|
||||
int(c_open) <= int(p_close) and
|
||||
int(c_close) >= int(p_open)):
|
||||
KlineAnalyzer.is_bearish(prev) and
|
||||
int(c_open) <= int(p_close) and
|
||||
int(c_close) >= int(p_open)):
|
||||
return "long", "bear_bull_engulf"
|
||||
|
||||
# 前涨后跌包住 -> 做空
|
||||
if (KlineAnalyzer.is_bearish(curr) and
|
||||
KlineAnalyzer.is_bullish(prev) and
|
||||
int(c_open) >= int(p_close) and
|
||||
int(c_close) <= int(p_open)):
|
||||
KlineAnalyzer.is_bullish(prev) and
|
||||
int(c_open) >= int(p_close) and
|
||||
int(c_close) <= int(p_open)):
|
||||
return "short", "bull_bear_engulf"
|
||||
|
||||
return None, None
|
||||
@@ -163,9 +163,9 @@ class WEEXApiClient:
|
||||
self.headers = headers
|
||||
|
||||
def get_kline_data(self, contract_id: str = Config.CONTRACT_ID,
|
||||
product_code: str = Config.PRODUCT_CODE,
|
||||
kline_type: str = Config.KLINE_TYPE,
|
||||
limit: int = Config.KLINE_LIMIT) -> List[Dict]:
|
||||
product_code: str = Config.PRODUCT_CODE,
|
||||
kline_type: str = Config.KLINE_TYPE,
|
||||
limit: int = Config.KLINE_LIMIT) -> List[Dict]:
|
||||
"""
|
||||
获取K线数据
|
||||
|
||||
@@ -403,7 +403,7 @@ class TradingExecutor:
|
||||
"""
|
||||
# 检查是否已经持有相同方向的仓位
|
||||
if (direction == "long" and current_position == PositionManager.POSITION_LONG) or \
|
||||
(direction == "short" and current_position == PositionManager.POSITION_SHORT):
|
||||
(direction == "short" and current_position == PositionManager.POSITION_SHORT):
|
||||
logger.info(f"已持有{direction}方向仓位,无需重复开仓")
|
||||
return True # 返回True表示"状态正常",虽然没有执行交易
|
||||
|
||||
@@ -445,8 +445,8 @@ class PositionManager:
|
||||
|
||||
# 持仓状态常量
|
||||
POSITION_SHORT = -1 # 做空
|
||||
POSITION_NONE = 0 # 无持仓
|
||||
POSITION_LONG = 1 # 做多
|
||||
POSITION_NONE = 0 # 无持仓
|
||||
POSITION_LONG = 1 # 做多
|
||||
|
||||
def __init__(self, trading_executor: TradingExecutor):
|
||||
self.trading_executor = trading_executor
|
||||
@@ -489,7 +489,7 @@ class PositionManager:
|
||||
# 持多仓,连续两根阴线,平多
|
||||
if self.current_position == self.POSITION_LONG:
|
||||
if (KlineAnalyzer.is_bearish(kline_1) and
|
||||
KlineAnalyzer.is_bearish(kline_2)):
|
||||
KlineAnalyzer.is_bearish(kline_2)):
|
||||
logger.success(
|
||||
f"{datetime.datetime.now()},止损信号:连续两根阴线,平多"
|
||||
)
|
||||
@@ -500,7 +500,7 @@ class PositionManager:
|
||||
# 持空仓,连续两根阳线,平空
|
||||
elif self.current_position == self.POSITION_SHORT:
|
||||
if (KlineAnalyzer.is_bullish(kline_1) and
|
||||
KlineAnalyzer.is_bullish(kline_2)):
|
||||
KlineAnalyzer.is_bullish(kline_2)):
|
||||
logger.success(
|
||||
f"{datetime.datetime.now()},止损信号:连续两根阳线,平空"
|
||||
)
|
||||
@@ -538,8 +538,8 @@ class MessageSender:
|
||||
|
||||
@staticmethod
|
||||
def format_position_message(position_data: Optional[Dict],
|
||||
current_price: float,
|
||||
available_balance: float) -> str:
|
||||
current_price: float,
|
||||
available_balance: float) -> str:
|
||||
"""
|
||||
格式化持仓信息消息
|
||||
|
||||
@@ -790,7 +790,7 @@ class WeexTransaction:
|
||||
# 检查是否已经持有相同方向的仓位
|
||||
current_pos = self.position_manager.current_position
|
||||
if (direction == "long" and current_pos == PositionManager.POSITION_LONG) or \
|
||||
(direction == "short" and current_pos == PositionManager.POSITION_SHORT):
|
||||
(direction == "short" and current_pos == PositionManager.POSITION_SHORT):
|
||||
logger.info(f"已持有{direction}方向仓位,继续持仓,不执行新开仓操作")
|
||||
# 继续持仓,不发送开仓信息,直接返回继续执行后续的持仓信息发送
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user