DEV Community

Cover image for Get BAT price with Python
codesharedot
codesharedot

Posted on

1 1

Get BAT price with Python

BAT (Basic Attention Token) is a decentralized ad exchange platform built on the Ethereum platform.

The token aims to correctly price user attention within the platform. Advertisers pay BAT to website publishers for the attention of users.

The BAT ecosystem includes Brave, an open-source, privacy-centered browser designed to block trackers and malware. It leverages blockchain technology to anonymously and track user attention securely and rewards publishers accordingly.

Earning BAT

At this point in time, you can only collect BAT, but there doesn't seem to be a way to withdraw it to other crypto-currency. But you could collect BATs and wait for withdraw support in the future.

Edit: You can now collect BAT tokens, withdraw BAT

Exchange

BAT can be exchanged for other crypto-currencies or you can exchange to another btc and then to fiat currency.

You can get the current price of BAT with Python:

#!/usr/bin/python3
import requests
import json
from forex_python.converter import CurrencyRates
import os

c = CurrencyRates()
rate = c.get_rate('USD', 'EUR') 
print(rate)

basic_attention_token_api_url = 'https://api.coinmarketcap.com/v1/ticker/basic-attention-token/'
response = requests.get(basic_attention_token_api_url)
response_json = response.json()
print(response_json)

for coin in response.json():
    price = coin.get("price_usd", "U$S Price not provided")
    coin_price = float(("{0:.2f}").format(float(price)))
    print("$ " + str(coin_price))
    coin_price_eur = float(("{0:.2f}").format(float(price)*rate))   
    print("E " + str(coin_price_eur))

ref: https://github.com/codesharedot/basic-attention-token-price/

Read more:

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay