-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_binance.py
107 lines (73 loc) · 2.41 KB
/
api_binance.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
#This example uses Python 2.7 and the python-request library.
from os import close
import os
from requests import Request, Session
import json
import requests
import pprint
from tkinter import Button, Label, Tk,PhotoImage
from PIL import Image
from dotenv import load_dotenv
import os
import sys
load_dotenv()
#enviroment variables
from requests.sessions import session
url = os.getenv("url")
def priceBTC(url):
API_KEY=os.getenv("API_KEY")
parameters = {
'slug':'bitcoin',
'convert':'USD'
}
headers={
'Accepts':'application/json',
'X-CMC_PRO_API_KEY':f'{API_KEY}'
}
session=Session()
session.headers.update(headers)
response=session.get(url,params=parameters)
#pprint.pprint(json.loads(response.text)['data']['1']['quote']['USD']['price'])
BTC_price=str(json.loads(response.text)['data']['1']['quote']['USD']['price'])
return BTC_price
def priceETH(url):
API_KEY=os.getenv("API_KEY")
parameters = {
'slug':'ethereum',
'convert':'USD'
}
headers={
'Accepts':'application/json',
'X-CMC_PRO_API_KEY':f'{API_KEY}'
}
session=Session()
session.headers.update(headers)
response=session.get(url,params=parameters)
#pprint.pprint(json.loads(response.text)['data']['1027']['quote']['USD']['price'])
ETH_price=str(json.loads(response.text)['data']['1027']['quote']['USD']['price'])
return ETH_price
def reset():
os.execl(sys.executable, sys.executable, * sys.argv)
ETH_price=priceETH(url)
BTC_price=priceBTC(url)
class main:
root=Tk()
root.iconbitmap('Cjdowner-Cryptocurrency-Flat-Bitcoin-BTC.ico')
root.title("Lector de precio de crypto")
root.geometry("500x700")
root.resizable(0,0)
root.configure(bg='white')
imageneth = PhotoImage(file="giphy.gif")
imagenbtc = PhotoImage(file="btc2.gif")
precioeth=Label(root,text=f"El precio de ETH es " + "$" + ETH_price)
precioeth.config(fg="black",bg="cyan",font=("Verdana",12))
precioeth.pack()
Label(root, image=imageneth, bd=1).pack(side="top")
preciobtc=Label(root,text="El precio de BITCOIN BTC es "+ "$" + BTC_price )
preciobtc.config(fg="black",bg="gold",font=("Verdana",12))
preciobtc.pack()
Label(root, image=imagenbtc, bd=1).pack(side="top")
Button(text="EXIT",command=quit).pack()
Button(text="RESET",command=reset).pack()
root.mainloop()
w=main()