-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdax_authentiClient.py
More file actions
152 lines (101 loc) · 4.25 KB
/
gdax_authentiClient.py
File metadata and controls
152 lines (101 loc) · 4.25 KB
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
141
142
143
144
145
146
147
148
149
150
151
import gdax
import json
import smtplib
import infoPerso
import time
import matplotlib.pyplot as plt
def getPosition():
# get the last position for each product
publicClient = gdax.PublicClient()
#products = publicClient.get_products()
products = [{'currency':'EUR', 'id': 'EUR'}, {'currency':'LTC', 'id': 'LTC-EUR'}, {'currency':'ETH', 'id':'ETH-EUR'}, {'currency':'BTC', 'id':'BTC-EUR'}]
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
total = 0
acounts = auth_client.get_accounts()
with open('C:/Temp/data.txt', 'a') as outfile:
json.dump(acounts, outfile)
labels = None
sizes = []
for ac in acounts:
balance = float(ac['balance'])
if( ac['currency'] == 'EUR'):
value = balance;
print(ac['currency'], balance, value)
total += value
labels.append('EUR')
sizes.append(value)
else:
for product in products:
if( ac['currency'] == product['currency']):
ticker = publicClient.get_product_ticker(product['id'])
value = float(balance)*float(ticker['bid'])
print(ac['currency'], ticker['bid'], balance, value)
total += value
labels.append(ac['currency'])
sizes.append(value)
print( 'my total is:', total)
ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
def mailAlert( msg ):
myInfo = infoPerso.infoPerso()
server = smtplib.SMTP(myInfo.smpt_server, 587)
server.starttls()
server.login(myInfo.smpt_login, myInfo.smpt_pass)
server.sendmail(myInfo.smpt_from, myInfo.smpt_to, msg)
server.quit()
def getMyOrders():
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
orders = auth_client.get_orders()
if( len(orders)==0):
mailAlert()
print( orders)
def buyCoins( price='100.00', #EUR
size='0.001', #BTC
product_id='BTC-EUR'):
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
keys = {'size': size, 'product_id':product_id, 'price': price}
order = auth_client.buy(**keys)
return order
def buyAtBestPrice( size='0.01',
product_id='LTC-EUR'):
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
publicClient = gdax.PublicClient()
ticker = publicClient.get_product_ticker(product_id)
price = float(ticker['price'])- 0.5
keys = {'size': size, 'product_id':product_id, 'price': price}
order = auth_client.buy(**keys)
print(order)
count = 0
while (count < 60):
time.sleep(1)
auth_client.cancel_order(order['id'])
ticker = publicClient.get_product_ticker(product_id)
price = float(ticker['price']) - 0.5;
keys = {'size': size, 'product_id':product_id, 'price': price}
order = auth_client.buy(**keys)
print(order)
count = count + 1
return order
def sellCoins( price='20000.00', #EUR
size='0.001', #BTC
product_id='BTC-EUR'):
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
keys = {'size': size, 'product_id':product_id, 'price': price}
order = auth_client.sell(**keys)
return order
def cancelOrder( order_id ):
myInfo = infoPerso.infoPerso()
auth_client = gdax.AuthenticatedClient( myInfo.gdax_key, myInfo.gdax_b64secret, myInfo.gdax_passphrase)
if order_id :
orders = auth_client.cancel_order(order_id)
print( orders)
else:
print( 'no order to cancel')