bitmart优化完成
This commit is contained in:
@@ -6,11 +6,11 @@ import requests
|
||||
from tqdm import tqdm
|
||||
from loguru import logger
|
||||
from dataclasses import dataclass
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
|
||||
from bitmart.api_contract import APIContract
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
from bitmart.lib.cloud_exceptions import APIException
|
||||
|
||||
from bit_tools import openBrowser
|
||||
from 交易.tools import send_dingtalk_message
|
||||
|
||||
|
||||
@@ -109,15 +109,9 @@ class StrategyConfig:
|
||||
|
||||
|
||||
class BitmartFuturesMeanReversionBot:
|
||||
def __init__(self, cfg: StrategyConfig, tge_id=None):
|
||||
def __init__(self, cfg: StrategyConfig, bit_id=None):
|
||||
|
||||
self.tge_url = "http://127.0.0.1:50326"
|
||||
self.tge_id = tge_id
|
||||
|
||||
self.tge_headers = {
|
||||
"Authorization": "Bearer asp_174003986c9b0799677c5b2c1adb76e402735d753bc91a91",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
self.bit_id = bit_id
|
||||
|
||||
self.page: ChromiumPage | None = None
|
||||
|
||||
@@ -169,7 +163,7 @@ class BitmartFuturesMeanReversionBot:
|
||||
def ding(self, msg, error=False):
|
||||
prefix = "❌bitmart:" if error else "🔔bitmart:"
|
||||
if error:
|
||||
for _ in range(3):
|
||||
for _ in range(1):
|
||||
send_dingtalk_message(f"{prefix}{msg}")
|
||||
else:
|
||||
send_dingtalk_message(f"{prefix}{msg}")
|
||||
@@ -572,7 +566,7 @@ class BitmartFuturesMeanReversionBot:
|
||||
else:
|
||||
self.click_safe('x://span[normalize-space(text()) ="市价"]')
|
||||
|
||||
# if resp.get("code") == 1000:
|
||||
# if resp.get("code") == 1000:
|
||||
return True
|
||||
|
||||
# self.ding(f"下单失败: {resp}", error=True)
|
||||
@@ -778,12 +772,11 @@ class BitmartFuturesMeanReversionBot:
|
||||
def openBrowser(self):
|
||||
"""打开 TGE 对应浏览器实例"""
|
||||
try:
|
||||
res = requests.post(
|
||||
f"{self.tge_url}/api/browser/start",
|
||||
json={"envId": self.tge_id},
|
||||
headers=self.tge_headers
|
||||
)
|
||||
self.tge_port = res.json()["data"]["port"]
|
||||
bit_port = openBrowser(id=self.bit_id)
|
||||
co = ChromiumOptions()
|
||||
co.set_local_port(port=bit_port)
|
||||
|
||||
self.page = ChromiumPage(addr_or_opts=co)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
@@ -865,10 +858,10 @@ class BitmartFuturesMeanReversionBot:
|
||||
return
|
||||
logger.info("TGE 端口获取成功")
|
||||
|
||||
# 2. 接管浏览器
|
||||
if not self.take_over_browser():
|
||||
self.ding("接管浏览器失败!", error=True)
|
||||
return
|
||||
# # 2. 接管浏览器
|
||||
# if not self.take_over_browser():
|
||||
# self.ding("接管浏览器失败!", error=True)
|
||||
# return
|
||||
logger.info("浏览器接管成功")
|
||||
self.page.get("https://derivatives.bitmart.com/zh-CN/futures/ETHUSDT")
|
||||
|
||||
@@ -963,7 +956,7 @@ if __name__ == "__main__":
|
||||
export BITMART_MEMO "合约交易"
|
||||
"""
|
||||
cfg = StrategyConfig()
|
||||
bot = BitmartFuturesMeanReversionBot(cfg, tge_id=196495)
|
||||
bot = BitmartFuturesMeanReversionBot(cfg, bit_id="f2320f57e24c45529a009e1541e25961")
|
||||
|
||||
# 设置日志级别为INFO以便查看详细计算过程
|
||||
logger.remove()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
telegram/bot_session.session-journal
Normal file
BIN
telegram/bot_session.session-journal
Normal file
Binary file not shown.
BIN
telegram/sign.db
BIN
telegram/sign.db
Binary file not shown.
Reference in New Issue
Block a user