Get data from the Ethereum API list

In this article, we will study how to access the data from the API responses list and extract important information.

Overview of the task

The task includes the creation of the Python script, which provides the list of API response objects as a starter. Each object has two pores of the value of the keys: “symbols” and “lastprice”. Our goal is to print only the values ​​of Price, assuming that these are the prices we dominate.

necessary conditions

Before continuing, make sure you have:

Implementation of the scenario

`Python

Import the required libraries

Import surveys

Define the list of API response objects

Price_list = [

{'Symbol': 'Ethbtc', 'Lastprice': '0.03574700'},

ethbtc

{'symbol': 'btcusdt', 'lastprice': '57621.0800000000'}

btcusdt

]]

Use the questions library to send a GET request to the end of the API

Def Get_api_response (data, result):

"" Send the request for a request to the rear point of the API and return the response data. "" ""

Answer = survey.get (event, for days = data)

Return the answer.json ()

Pull the Lastprice values ​​from each API response object

For the article Price_list:

Print (f "Last {element ['symbol']} Price: {element ['Lastprice']})

Use an understanding list to extract and print only the values ​​of the last prior

Last_prices = [Item ['Lastprice'] for the element price_list if 'btcusdt' element ['symbol']]]]]

Printing (latest prices: ")

For a "Last_price" price:

Print (price)

'

How it works

Expansion sample

'

Last price:

57621.08000000

0.03574700

Last price:

57621.08000000

` ‘

This scenario is an easy way to obtain data from the Ethereum API list and to withdraw specific values, which makes them useful for a variety of programs such as data analysis or web rating.

Stop Loss Payment

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Abrir bate-papo
Olá 👋
Podemos ajudá-lo?