-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
128 lines (109 loc) · 3.91 KB
/
main.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
import os
import ccxt
import time
import json
import keep_alive
import datetime
def Rebalance(t,b,bn):
C98_info = bn.fetch_tickers('C98/BUSD')
Balance = bn.fetchBalance()
C98 = C98_info['C98/BUSD']['last'] # ราคา C98 ต่อ BUSD
C98_V = Balance['C98']['free'] # จำนวน C98 ที่มี
V_C98 = C98 * C98_V # จำนวน C98 ต่อ BUSD ที่มี $
BUSD_V = Balance['BUSD']['free']
s,h,m,d,mth = now.second,now.hour,now.minute,now.day,now.month
GMT = 7
temp = (h+GMT) // 24
h += GMT
if h > 24:
h -= 24
else:
pass
d += temp
if V_C98 > t: # V > 82 - 1
orderSell = (10/C98)+0.13
bn.create_market_sell_order('C98/BUSD',orderSell)
print(f"SELL C98 @Marketprice {orderSell}$")
print(f"ราคา C98 = {C98}")
print(f"จำนวน C98 ที่มี = {C98_V}")
print(f"C98 รวมแล้วมี {V_C98} ~$")
print(f"BUSD รวมแล้วมี {BUSD_V} ~$")
print(f"วันเวลา {h}:{m}:{s} วันที่ {d} เดือน {mth}")
print("\r")
time.sleep(2)
elif V_C98 < b: # V < 68 + 1
orderBuy = (10/C98)+0.13
bn.create_market_buy_order('C98/BUSD',orderBuy)
print(f"BUY C98 @Marketprice {orderBuy}$")
print(f"ราคา C98 = {C98}")
print(f"จำนวน C98 ที่มี = {C98_V}")
print(f"C98 รวมแล้วมี {V_C98} ~$")
print(f"BUSD รวมแล้วมี {BUSD_V} ~$")
print(f"วันเวลา {h}:{m}:{s} วันที่ {d} เดือน {mth}")
print("\r")
time.sleep(2)
file = open('config.json')
config = json.load(file)
fix = int(config['fix']) # 75
fee = int(config['rebal']) # 7
top = (fix+fee) - 1 # 82 (-1)
bottom = (fix-fee) + 1 # 68 (+1)
my_API = os.environ['API']
my_secret = os.environ['Secret']
bn = ccxt.binance({
'api_key': my_API, # API Keys
'secret': my_secret, # API Secret
'enableRateLimit': True,
})
keep_alive.keep_alive()
print("Start Rebalance")
n = 0
while True:
now = datetime.datetime.now()
Rebalance(top,bottom,bn)
time.sleep(2)
t,b = top,bottom
n+=1
if n == 30:
C98_info = bn.fetch_tickers('C98/BUSD')
Balance = bn.fetchBalance()
C98 = C98_info['C98/BUSD']['last'] # ราคา C98 ต่อ BUSD
C98_V = Balance['C98']['free'] # จำนวน C98 ที่มี
V_C98 = C98 * C98_V # จำนวน C98 ต่อ BUSD ที่มี $
BUSD_V = Balance['BUSD']['free']
s,h,m,d,mth = now.second,now.hour,now.minute,now.day,now.month
GMT = 7
temp = (h+GMT) // 24
h += GMT
if h > 24:
h -= 24
d += temp
if V_C98 > t: # V > 82 - 1
orderSell = (10/C98)+0.13
bn.create_market_sell_order('C98/BUSD',orderSell)
print(f"SELL C98 @Marketprice {orderSell}$")
print(f"ราคา C98 = {C98}")
print(f"จำนวน C98 ที่มี = {C98_V}")
print(f"C98 รวมแล้วมี {V_C98} ~$")
print(f"BUSD รวมแล้วมี {BUSD_V} ~$")
print(f"วันเวลา {h}:{m}:{s} วันที่ {d} เดือน {mth}")
print("\r")
time.sleep(2)
elif V_C98 < b: # V < 68 + 1
orderBuy = (10/C98)+0.13
bn.create_market_buy_order('C98/BUSD',orderBuy)
print(f"BUY C98 @Marketprice {orderBuy}$")
print(f"ราคา C98 = {C98}")
print(f"จำนวน C98 ที่มี = {C98_V}")
print(f"C98 รวมแล้วมี {V_C98} ~$")
print(f"BUSD รวมแล้วมี {BUSD_V} ~$")
print(f"วันเวลา {h}:{m}:{s} วันที่ {d} เดือน {mth}")
print("\r")
time.sleep(2)
else:
print("นั่งทับมือ")
print(f"ราคา C98 = {C98}")
print(f"C98 รวมแล้วมี {V_C98} ~$")
print(f"วันเวลา {h}:{m}:{s} วันที่ {d} เดือน {mth}")
print("\r")
n = 0