fewfef
This commit is contained in:
@@ -1,27 +1,17 @@
|
||||
import time
|
||||
import uuid
|
||||
import datetime
|
||||
import openBrowser
|
||||
|
||||
import requests
|
||||
from DrissionPage import ChromiumPage
|
||||
from DrissionPage import ChromiumOptions
|
||||
from tqdm import tqdm
|
||||
from loguru import logger
|
||||
from bit_tools import openBrowser
|
||||
from DrissionPage import ChromiumPage
|
||||
from DrissionPage import ChromiumOptions
|
||||
|
||||
from bitmart.api_contract import APIContract
|
||||
from bitmart.lib.cloud_exceptions import APIException
|
||||
from 交易.tools import send_dingtalk_message
|
||||
|
||||
|
||||
class BitmartFuturesTransaction:
|
||||
def __init__(self, tge_id):
|
||||
|
||||
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"
|
||||
}
|
||||
def __init__(self, bit_id):
|
||||
|
||||
self.page: ChromiumPage | None = None
|
||||
|
||||
@@ -47,6 +37,8 @@ class BitmartFuturesTransaction:
|
||||
self.open_avg_price = None # 开仓价格
|
||||
self.current_amount = None # 持仓量
|
||||
|
||||
self.bit_id = bit_id
|
||||
|
||||
def get_klines(self):
|
||||
"""获取最近3根30分钟K线(step=30)"""
|
||||
try:
|
||||
@@ -155,12 +147,10 @@ class BitmartFuturesTransaction:
|
||||
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
|
||||
@@ -230,6 +220,9 @@ class BitmartFuturesTransaction:
|
||||
self.page.ele('x://*[@id="size_0"]').input(1)
|
||||
self.click_safe('x://span[normalize-space(text()) ="买入/做多"]')
|
||||
|
||||
def ding(self, text, error=False):
|
||||
logger.info(text)
|
||||
|
||||
def action(self):
|
||||
# 启动时设置全仓高杠杆
|
||||
if not self.set_leverage():
|
||||
@@ -242,18 +235,12 @@ class BitmartFuturesTransaction:
|
||||
return
|
||||
logger.info("TGE 端口获取成功")
|
||||
|
||||
# 2. 接管浏览器
|
||||
if not self.take_over_browser():
|
||||
self.ding("接管浏览器失败!", error=True)
|
||||
return
|
||||
logger.info("浏览器接管成功")
|
||||
|
||||
self.get_klines()
|
||||
|
||||
# self.close_extra_tabs()
|
||||
# self.page.get("https://derivatives.bitmart.com/zh-CN/futures/ETHUSDT")
|
||||
#
|
||||
# self.click_safe('x://button[normalize-space(text()) ="市价"]')
|
||||
self.click_safe('x://button[normalize-space(text()) ="市价"]')
|
||||
# self.click_safe('x://button[normalize-space(text()) ="限价"]')
|
||||
#
|
||||
# self.page.ele('x://*[@id="price_0"]').input(vals=3000, clear=True)
|
||||
@@ -263,4 +250,4 @@ class BitmartFuturesTransaction:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
BitmartFuturesTransaction(tge_id=196495).action()
|
||||
BitmartFuturesTransaction(bit_id="f2320f57e24c45529a009e1541e25961").action()
|
||||
|
||||
Reference in New Issue
Block a user