R_Milligan3

Crypto_Price

Mar 11th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/usr/bin/python3.8
  2. from tokens import cmc_token
  3. import requests
  4. import json
  5. from tokens import tel_token
  6. import discord
  7. from discord.ext import commands
  8.  
  9. def write_json(data,filename='response.json'):
  10. with open(filename,'w')as f:
  11. json.dump(data,f,indent=4,ensure_ascii=False)
  12.  
  13.  
  14. def get_cmc_data(crypto):
  15. url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
  16. headers={'X-CMC_PRO_API_KEY':cmc_token}
  17. params={'symbol':crypto,'convert':'GBP'} # the crypto symbol is BTC so it converts BTC to GBP
  18. r = requests.get(url,headers=headers,params=params).json()
  19. price = r ['data'][crypto]['quote']['GBP'['price']
  20. return price # getting error here (invalid syntax)
  21.  
  22. def main():
  23. print(get_cmc_data('BTC'))
  24.  
  25. if __name__=="__main__":
  26. main()
  27.  
Add Comment
Please, Sign In to add comment