-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCoinbase Pro Order Example 1.py
52 lines (44 loc) · 1.59 KB
/
Coinbase Pro Order Example 1.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
import cbpro
import base64
import json
from time import sleep
key = ''
secret = ''
passphrase = ''
encoded = json.dumps(secret).encode()
b64secret = base64.b64encode(encoded)
auth_client = cbpro.AuthenticatedClient(key=key, b64secret=secret, passphrase=passphrase)
c = cbpro.PublicClient()
while True:
try:
ticker = c.get_product_ticker(product_id='BTC-USD')
except Exception as e:
print(f'Error obtaining ticker data: {e}')
if float(ticker['price']) >= 38500.00:
try:
limit = c.get_product_ticker(product_id='ETH-USD')
except Exception as e:
print(f'Error obtaining ticker data: {e}')
try:
order=auth_client.place_limit_order(product_id='ETH-USDT',
side='buy',
price=float(limit['price'])+2,
size='0.007')
except Exception as e:
print(f'Error placing order: {e}')
sleep(2)
try:
check = order['id']
check_order = auth_client.get_order(order_id=check)
except Exception as e:
print(f'Unable to check order. It might be rejected. {e}')
if check_order['status'] == 'done':
print('Order placed successfully')
print(check_order)
break
else:
print('Order was not matched')
break
else:
print(f'The requirement is not reached. The ticker price is at {ticker["price"]}')
sleep(10)