Crypto Exchange API and Real-time pricing

Viewed 812

I am hoping to write a python code that gives me the real-time pricing of a cryptocurrency using the exchange's API, in this case the exchange is Bitmax (but it can be any other). I have no idea where to start as I'm still quite new to python and coding in general...

2 Answers

The CoinMarketCap API is used here, the real time price is generated every time you run the code. This code generated 100 cryptos and their details some altcoins were not generated by the API.

## Code to display tokens and their price using CoinMarketCap API
# Note: Some altcoins are not displayed by this API.

from coinmarketcapapi import CoinMarketCapAPI

# Register on https://coinmarketcap.com/ to get your API
API_KEY = "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEE" # Enter you API here
coin_market_cap = CoinMarketCapAPI(API_KEY)

raw_data = coin_market_cap.cryptocurrency_listings_latest()

all_data = raw_data.data[:]

print("S/N\tID\tCryptocurrency\t\tSymbol\tPrice(USD)\tDate Added\tCirculating 
          Supply\tTotal Supply")
print('------------------------------------------------------------------------')

for index in range(len(all_data)):
     coin_id = all_data[index]['id']
     coin_name = all_data[index]['name']
     coin_symbol = all_data[index]['symbol']
     coin_date_added = all_data[index]['date_added'][:10]
     coin_supply = all_data[index]['total_supply']
     quote = (((all_data[index])['quote'])['USD'])['price']
     coin_circ_supply = all_data[index]['circulating_supply']
     coin_max_supply = all_data[index]['max_supply']
     serial = index+1
     
     print("{0:3} {1:7} \t{2:16} \t {3:5} \t {4:8.2f} \t{5:12} \t{6:12.1f} \t\t{7:}"
          .format(serial, coin_id, coin_name, coin_symbol, quote, coin_date_added, 
                  coin_circ_supply, coin_max_supply))
Related