DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Get BAT price with Python
codesharedot
codesharedot

Posted on

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:

Top comments (0)

πŸ‘€ Just want to lurk?

That's fine, you can still create an account and turn on features like 🌚 dark mode.