-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGreenLineBitrue.py
109 lines (97 loc) · 4.09 KB
/
GreenLineBitrue.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
from __future__ import print_function
import gate_api
from bitrue.client import Client
from bitrue.enums import *
import requests
import time
import hashlib
import hmac
configuration = gate_api.Configuration(
host="https://api.gateio.ws/api/v4",
key="*****",
secret="*****")
def gen_sign(method, url, query_string=None, payload_string=None):
key = '******'
secret = '******'
t = time.time()
m = hashlib.sha512()
m.update((payload_string or "").encode('utf-8'))
hashed_payload = m.hexdigest()
s = '%s\n%s\n%s\n%s\n%s' % (method, url, query_string or "", hashed_payload, t)
sign = hmac.new(secret.encode('utf-8'), s.encode('utf-8'), hashlib.sha512).hexdigest()
return {'KEY': key, 'Timestamp': str(t), 'SIGN': sign}
while True:
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url1 = '/spot/order_book'
query_param = 'currency_pair=CSPR_USDT'
r = requests.request('GET', host + prefix + url1 + "?" + query_param, headers=headers)
url2 = '/wallet/total_balance'
query_param = ''
sign_headers = gen_sign('GET', prefix + url2, query_param)
headers.update(sign_headers)
q1= round(float(((requests.request('GET', host + prefix + url2, headers=headers)).json()['total'])['amount']), 5)
g11 = float(r.json()['asks'][0][0])
g12 = float(r.json()['asks'][1][0])
g21 = float(r.json()['asks'][0][1])
g22 = float(r.json()['asks'][1][1])
gt2=(g21 + g22)
gsa = round(float((g11*g21)+(g12*g22))/gt2, 5)
g31 = float(r.json()['bids'][0][0])
g32 = float(r.json()['bids'][1][0])
g41 = float(r.json()['bids'][0][1])
g42 = float(r.json()['bids'][1][1])
gt4 = float(g41 + g42)
gba = round(float((g31 * g41) + (g32 * g42)) / gt4, 5)
api_instance = gate_api.WalletApi(gate_api.ApiClient(configuration))
v3 = round(float(api_instance.get_total_balance(currency='USD').total.amount), 5)
v8 = ((q1-v3) / g11) - 1
api_key = '*****'
api_secret = '*****'
client = Client(api_key, api_secret)
bms = round(float(float(client.get_order_book(symbol='CSPRUSDT', limit=1)['asks'][0][0])) - 0.00001, 5)
bmb = round(float(float(client.get_order_book(symbol='CSPRUSDT', limit=1)['bids'][0][0])) + 0.00001, 5)
fcb = int(float(client.get_asset_balance(asset='CSPR')['free']))
lcb = int(float(client.get_asset_balance(asset='CSPR')['locked']))
tsm = int(fcb + lcb + v8)
fub = int(float(client.get_asset_balance(asset='USDT')['free']))
lub = int(float(client.get_asset_balance(asset='USDT')['locked']))
tub = int(fub + lub + v3)
if lub > 15:
sId3 = str(client.get_open_orders(symbol='CSPRUSDT')[0]['orderId'])
sop3 = round(float(client.get_open_orders(symbol='CSPRUSDT')[0]['price']), 5)
fub3 = float(client.get_asset_balance(asset='cspr')['free'])
lub3 = float(client.get_asset_balance(asset='cspr')['locked'])
tub3 = fub3 + lub3 + v3
pp2 = round(float(client.get_order_book(symbol='CSPRUSDT', limit=1)['bids'][0][0]), 5)
if g31 > sop3*1.008 or pp2 > sop3:
result = client.cancel_order(
symbol='CSPRUSDT',
orderId=sId3)
else:
continue
time.sleep(1)
if gba >= bmb * 1.008 and fub > 40 and lub < 1:
bmb = round(float(float(client.get_order_book(symbol='CSPRUSDT', limit=1)['bids'][0][0])) + 0.00001, 5)
v9 = int(v8)
client.create_order(
symbol='CSPRUSDT',
side=SIDE_BUY,
type=ORDER_TYPE_LIMIT,
timeInForce=TIME_IN_FORCE_GTC,
quantity=v9,
price=bmb)
mab = str(tsm - 5720)
mab1 = int(tsm - 5720)
fiat = str(g31)
api_instance3 = gate_api.SpotApi(gate_api.ApiClient(configuration))
if tsm > 5720 and mab1 > 75:
gob = gate_api.Order(currency_pair='cspr_usdt',
side='sell',
amount=mab,
price=fiat, )
api_response = api_instance3.create_order(gob)
if (fub + lub) < 10:
break
time.sleep(1)