-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
88 lines (71 loc) · 2.65 KB
/
test.py
File metadata and controls
88 lines (71 loc) · 2.65 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
import requests
import time
from config import auth
# MercadoTest
market_id = 'btc-clp'
# Obtener mis ordenes
urlOrders = f'https://www.buda.com/api/v2/markets/{market_id}/orders'
responseOrders = requests.get(urlOrders, auth=auth, params={
'state': 'pending',
'per': 20,
'page': 1,
})
print(responseOrders.json())
# Obtener precio de punta en el libro
urlBook = f'https://www.buda.com/api/v2/markets/{market_id}/order_book'
responseBook = requests.get(urlBook)
responseBook_json = responseBook.json()
bids = responseBook_json['order_book']['bids']
# El primer elemento en la lista de bids es la punta
primera_punta = bids[0]
precio = primera_punta[0]
cantidad = primera_punta[1]
print("Precio:", precio)
print("Cantidad:", cantidad)
limit = responseOrders.json()['orders'][0]['limit'][0]
# Calcular el porcentaje de diferencia entre "limit" y "precio"
price_dif = ((float(limit) - float(precio)) / float(precio)) * 100
# nuevo precio
new_price = float(precio) * (1 - 2.17)
# check precio
if price_dif < -10:
order_id = responseOrders.json()['orders'][0]['id']
url_cancel = f'https://www.buda.com/api/v2/orders/{order_id}'
response_cancel = requests.put(url_cancel, auth=auth, json={
'state': 'canceling',
})
print(response_cancel.json())
new_price = float(precio) * (1 - 0.094)
url_balance = f'https://www.buda.com/api/v2/balances'
response_balance = requests.get(url_balance, auth=auth)
print(response_balance.json())
#new_amount = float(response_balance.json()['balances']['amount'][0])
new_amount = 0.0
# Iterate over the "balances" array to find the desired object
time.sleep(1)
desired_currency = 'CLP'
for balance in response_balance.json()['balances']:
if balance['id'] == desired_currency:
balanceCLP = float(balance['available_amount'][0])
new_amount = (balanceCLP - 1) / new_price
print("Balance CLP:", balanceCLP)
print("Nuevo monto:", new_amount)
break
time.sleep(1)
url_newOrder = f'https://www.buda.com/api/v2/markets/{market_id}/orders'
response_newOrder = requests.post(url_newOrder, auth=auth, json={
'type': 'Bid',
'price_type': 'limit',
'limit': new_price,
'amount': new_amount,
})
print("Esta es la nueva orden", response_newOrder.json())
####### TEST#########
# Imprimir el resultado
print(new_price)
print(
f"El valor de 'limit' es {price_dif:.2f}% diferente del precio de punta.")
if float(limit) > float(precio):
print("El valor de 'limit' es mayor que el precio de punta.")
else:
print("El valor de 'limit' es menor o igual que el precio de punta.")