fewfef
This commit is contained in:
@@ -5,19 +5,14 @@ BitMart 被动做市/高频刷单策略
|
||||
"""
|
||||
|
||||
import time
|
||||
import datetime
|
||||
from typing import Optional, Dict, List, Tuple
|
||||
from dataclasses import dataclass
|
||||
from loguru import logger
|
||||
from threading import Lock
|
||||
import requests
|
||||
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
from dataclasses import dataclass
|
||||
from bitmart.api_contract import APIContract
|
||||
from bitmart.lib.cloud_exceptions import APIException
|
||||
from typing import Optional, Dict, List, Tuple
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
|
||||
|
||||
# from 交易.tools import send_dingtalk_message
|
||||
from bit_tools import openBrowser
|
||||
|
||||
|
||||
# ================================================================
|
||||
@@ -26,6 +21,7 @@ from bitmart.lib.cloud_exceptions import APIException
|
||||
|
||||
@dataclass
|
||||
class MarketMakingConfig:
|
||||
bit_id: str = "f2320f57e24c45529a009e1541e25961"
|
||||
"""做市策略配置"""
|
||||
# API配置(仅用于查询,不下单)
|
||||
api_key: str = "a0fb7b98464fd9bcce67e7c519d58ec10d0c38a8"
|
||||
@@ -119,7 +115,8 @@ class PendingOrder:
|
||||
class BrowserManager:
|
||||
"""浏览器管理器:负责浏览器的启动、接管和标签页管理"""
|
||||
|
||||
def __init__(self, config: MarketMakingConfig):
|
||||
def __init__(self, config: MarketMakingConfig, bit_id="f2320f57e24c45529a009e1541e25961"):
|
||||
self.bit_id = "f2320f57e24c45529a009e1541e25961"
|
||||
self.config = config
|
||||
self.tge_port: Optional[int] = None
|
||||
self.page: Optional[ChromiumPage] = None
|
||||
@@ -127,14 +124,10 @@ class BrowserManager:
|
||||
def open_browser(self) -> bool:
|
||||
"""打开浏览器并获取端口"""
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{self.config.tge_url}/api/browser/start",
|
||||
json={"envId": self.config.tge_id},
|
||||
headers=self.config.tge_headers,
|
||||
timeout=10
|
||||
)
|
||||
self.tge_port = response.json()["data"]["port"]
|
||||
logger.success(f"成功打开浏览器,端口:{self.tge_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 Exception as e:
|
||||
logger.error(f"打开浏览器失败: {e}")
|
||||
@@ -580,7 +573,8 @@ class BitMartMarketMakerAPI:
|
||||
class MarketMakingStrategy:
|
||||
"""被动做市策略(使用浏览器自动化下单,获取高返佣)"""
|
||||
|
||||
def __init__(self, config: MarketMakingConfig):
|
||||
def __init__(self, config: MarketMakingConfig, bit_id=None):
|
||||
self.bit_id = bit_id
|
||||
self.config = config
|
||||
self.api = BitMartMarketMakerAPI(config) # 仅用于查询
|
||||
|
||||
@@ -615,10 +609,10 @@ class MarketMakingStrategy:
|
||||
logger.error("打开浏览器失败")
|
||||
return False
|
||||
|
||||
# 接管浏览器
|
||||
if not self.browser_manager.take_over_browser():
|
||||
logger.error("接管浏览器失败")
|
||||
return False
|
||||
# # 接管浏览器
|
||||
# if not self.browser_manager.take_over_browser():
|
||||
# logger.error("接管浏览器失败")
|
||||
# return False
|
||||
|
||||
# 关闭多余标签页
|
||||
self.browser_manager.close_extra_tabs()
|
||||
@@ -967,7 +961,7 @@ class MarketMakingStrategy:
|
||||
if __name__ == '__main__':
|
||||
config = MarketMakingConfig(
|
||||
contract_symbol="ETHUSDT",
|
||||
tge_id=196495, # TGE浏览器ID
|
||||
bit_id="f2320f57e24c45529a009e1541e25961", # TGE浏览器ID
|
||||
trading_url="https://derivatives.bitmart.com/zh-CN/futures/ETHUSDT",
|
||||
spread_percent=0.01, # 0.01%价差
|
||||
order_size_usdt=0.1, # 每单10 USDT
|
||||
@@ -976,7 +970,7 @@ if __name__ == '__main__':
|
||||
order_timeout=60.0, # 60秒超时
|
||||
max_daily_loss=50.0, # 每日最大亏损50 USDT
|
||||
max_daily_trades=1000, # 每日最大1000笔
|
||||
leverage="30",
|
||||
leverage="35",
|
||||
open_type="cross"
|
||||
)
|
||||
|
||||
@@ -988,6 +982,5 @@ if __name__ == '__main__':
|
||||
logger.error(f"程序异常: {e}")
|
||||
# send_dingtalk_message(f"做市策略异常: {e}", error=True)
|
||||
|
||||
|
||||
# 9359,53
|
||||
# 14.35
|
||||
# 14.35
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user