In this chapter, we will create a button which will call a function to retrieve the top 50 exchanges and the trading volume for a cryptocurrency/currency pair. The API needs the selected cryptocurrency and the selected currency symbol to make the call.

BTC vs EURO for various exchanges

First we will create the exchange button.

# get top 50 exchanges by volume for currency/cryptocurrency pairs
action_coin_top_exchange = tk.Button(selectorFrame, text="Top Exchange", command=top_exchange, state=DISABLED)  # button used to get the top currency/cryptocurrency pair data
action_coin_top_exchange.pack(side=LEFT)

Then we create the function.

def top_exchange():  # Get a number of top 50 exchanges by their volumes

    sell_buy = ''
    try:
        currency_symbol = based.get()  # get the currency symbol
        crypto_symbol = crypto.get() # get the cryptocurrency symbol
        url = "https://min-api.cryptocompare.com/data/top/exchanges"
        data = {'tsym': currency_symbol, 'fsym': crypto_symbol, 'limit': 50}
        r = requests.get(url, params=data)
        exchange_rate_s = json.loads(json.dumps(r.json()))

    except:
        print("An exception occurred")

    for value in exchange_rate_s['Data']:  # populate exchange rate string
        for key, value1 in value.items():
            sell_buy += str(key) + " : " + str(value1) + "\n"

        sell_buy += "\n"


    text_widget.delete('1.0', END)  # clear all those previous text first
    s.set(sell_buy)
    text_widget.insert(INSERT, s.get())  # populate the text widget with new exchange rate data

If you miss out the first few posts regarding this project, you can read them all on this website under the python category.

Please follow and like us:
error0

Leave a Reply

Your email address will not be published. Required fields are marked *