-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_prices.py
49 lines (40 loc) · 1.24 KB
/
get_prices.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
import requests as r
import json
from datetime import datetime, date, timedelta
hora = datetime.now()
hora = datetime.strftime(hora,'%d-%m-%Y %H:%M:%S')
try:
belo = r.get('https://criptoya.com/api/belo/btc/ars/0.1').json()
lemon = r.get('https://criptoya.com/api/lemoncash/btc/ars/0.1').json()
except Exception as e:
print(e)
def get_ask():
ask_medium=(belo['ask'] + lemon['ask']) / 2
return round(ask_medium, 2)
def get_buy():
buy_medium = (belo['bid'] + lemon['bid']) / 2
return round(buy_medium, 2)
def get_btc():
medium = round((get_ask() + get_buy()) / 2)
return medium
def get_dolarbtc():
btc = r.get("https://blockchain.info/ticker").json()
price_btc = float(btc["USD"]["15m"])
list = []
list.append(round(get_ask()/price_btc,2))
list.append(round(get_buy()/price_btc,2))
list.append(round(get_btc()/price_btc,2))
return list
def create_dict():
dict = {}
list = get_dolarbtc()
dict.update({'compra':list[0]})
dict.update({'venta':list[1]})
dict.update({'promedio':list[2]})
dict.update({'bitcoin':get_btc()})
dict.update({'time':hora})
return dict
data = json.dumps(create_dict())
## write to a json file
with open('data.json', 'w') as f:
f.write(data)