forked from lswlc33/autoFunBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
贝壳-倒狗.py
140 lines (116 loc) · 4.02 KB
/
贝壳-倒狗.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import time
from lib.贝壳 import 贝壳信息, 贝壳市场, 贝壳交易
import threading
shells_info = {
"myshells": None,
"myrocks": None,
"tradeId1": None,
"quantity1": None,
"price1": None,
"tradeId2": None,
"quantity2": None,
"price2": None,
"is_sold": True,
"sold_quantity": 0,
}
def update_wallet_info():
"""钱包"""
global shells_info
try:
index = 贝壳信息()
shells_info["myshells"] = round(float(index["shells"]))
shells_info["myrocks"] = round(float(index["rocks"]), 2)
except Exception as e:
pass
wallet_info_timer = threading.Timer(1, update_wallet_info)
wallet_info_timer.start()
def update_market_info():
"""更新市场信息"""
global shells_info
data1 = 贝壳市场(0)[0]
data2 = 贝壳市场(1)[0]
if shells_info["tradeId1"] != int(data1["tradeId"]) or shells_info[
"tradeId2"
] != int(data2["tradeId"]):
shells_info["price1"] = float(data1["price"])
shells_info["price2"] = float(data2["price"])
shells_info["quantity1"] = int(data1["quantity"])
shells_info["quantity2"] = int(data2["quantity"])
print(
shells_info["myrocks"],
shells_info["myshells"],
shells_info["price1"],
shells_info["price2"],
shells_info["quantity1"],
shells_info["quantity2"],
)
shells_info["tradeId1"] = int(data1["tradeId"])
shells_info["tradeId2"] = int(data2["tradeId"])
def buy_shell(id, quantity):
"""购买"""
r = 贝壳交易(0, id, quantity)
if r.get("errorCode"):
print(f"购买失败: {r.get('message')}")
return False
else:
print("购买成功")
return True
def sell_shell(id, quantity):
"""出售"""
r = 贝壳交易(1, id, quantity)
if r.get("errorCode"):
print(f"出售失败: {r.get('message')}")
return False
else:
print("出售成功")
return True
def check_market_loop():
global shells_info
if not shells_info["is_sold"]:
# 当前贝壳不足
if shells_info["myshells"] < 500.0:
shells_info["is_sold"] = True
else:
print("补救流程")
if shells_info["sold_quantity"] > shells_info["quantity1"]:
# 预防卖完不剩了
if shells_info["sold_quantity"] - shells_info["quantity1"] < 501:
shells_info["is_sold"] = True
if sell_shell(shells_info["tradeId1"], shells_info["quantity1"]):
shells_info["sold_quantity"] = (
shells_info["sold_quantity"] - shells_info["quantity1"]
)
else:
shells_info["is_sold"] = sell_shell(
shells_info["tradeId1"], shells_info["sold_quantity"]
)
elif shells_info["myshells"] >= 600.00:
print("闲置流程")
quantity = min(200, shells_info["myshells"] - 501)
sell_shell(shells_info["tradeId1"], quantity - 10)
elif shells_info["price1"] >= 0.01:
print("高价流程")
quantity = min(shells_info["quantity1"], shells_info["myshells"] - 501)
sell_shell(shells_info["tradeId1"], quantity)
elif shells_info["price2"] < 0.001:
print("低价流程")
buy_shell(shells_info["tradeId2"], shells_info["quantity2"])
elif shells_info["price1"] > shells_info["price2"]:
print("交换流程")
quantity = min(1000, shells_info["quantity1"], shells_info["quantity2"])
if buy_shell(shells_info["tradeId2"], quantity):
shells_info["is_sold"] = sell_shell(shells_info["tradeId1"], quantity)
shells_info["sold_quantity"] = quantity
time.sleep(1)
print("\033c\033[?25l", end="")
update_wallet_info()
while True:
try:
update_market_info()
time.sleep(0.5)
check_market_loop()
except KeyError:
pass
except Exception as e:
print(f"Error: {e}")
time.sleep(1)