-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitso_functions.py
112 lines (97 loc) · 3.26 KB
/
bitso_functions.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
'''
Funciones para bitso
https://github.com/barucAlmaguer/bitso-py/blob/master/examples/place_order_test.py
'''
def btc_update(api):
ob = api.order_book('btc_mxn')
return ob
def xrp_update(api):
ob = api.order_book('xrp_mxn')
return ob
def min_ask_price(ob):
return min([ask.price for ask in ob.asks])
def max_bid_price(ob):
return max([ask.price for ask in ob.bids])
def bitso_status(api):
status = api.account_status()
print("Daily limit= {}".format(status.daily_limit))
print("Daily remaining= {}".format(status.daily_remaining))
def place_order_btc(api, side, amount, price):
print("Colocando orden...")
order = api.place_order(book='btc_mxn', side=side, order_type='limit', major=amount, price=price)
print("Orden colocada")
print('Tipo:' + side)
print('Monto:' + amount)
print('Precio:' + price)
return order
def place_order_xrp(api, side, amount, price):
print("Colocando orden...")
order = api.place_order(book='xrp_mxn', side=side, order_type='limit', major=amount, price=price)
print("Orden colocada")
print('Tipo:' + side)
print('Monto:' + amount)
print('Precio:' + price)
return order
def view_orders(api):
result = 0
oo = api.open_orders('btc_mxn')
if len(oo) > 0:
for o in oo:
print("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")
print("Order #: {}".format(o.oid))
print("\tSide= {}".format(o.side))
print("\tAmount= BTC${}".format(o.original_amount))
print("\tPrice= MXN${}".format(o.price))
print("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")
result = 1
else:
print("No hay ordenes activas")
return result
def view_orders_xrp(api):
result = 0
oo = api.open_orders('xrp_mxn')
if len(oo) > 0:
for o in oo:
print("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")
print("Order #: {}".format(o.oid))
print("\tSide= {}".format(o.side))
print("\tAmount= XRP ${}".format(o.original_amount))
print("\tPrice= MXN ${}".format(o.price))
print("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")
result = 1
else:
print("No hay ordenes activas")
return result
def cancel_order(api, oid):
return api.cancel_order(oid)
def cancel_all_orders(api):
oo = api.open_orders('btc_mxn')
if len(oo) > 0:
for o in oo:
success = cancel_order(api, o.oid)
if success:
print("Order #{} cancelled".format(o.oid))
else:
print("Error cancelling order #{}".format(o.oid))
else:
print('No orders to cancel')
def cancel_all_orders_xrp(api):
oo = api.open_orders('xrp_mxn')
if len(oo) > 0:
for o in oo:
success = cancel_order(api, o.oid)
if success:
print("Order #{} cancelled".format(o.oid))
else:
print("Error cancelling order #{}".format(o.oid))
else:
print('No orders to cancel')
def get_mxn_balance(api):
balances = api.balances()
return balances.mxn.available
def get_btc_balance(api):
balances = api.balances()
return balances.btc.available
def get_xrp_balance(api):
balances = api.balances()
return balances.xrp.available