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