Today (and yesterday) was spent almost entirely on figuring out how to manage the input side of things, as different APIs provide different information that is organized in different ways.
This is what I ended up with:
def token_symbol_request():
"""Requests user input for the symbol of a token."""
token_name = input("What token would you like to check the price of today? As an example, you can enter 'CUB'.")
pancakeswap_request = requests.get('https://api.pancakeswap.finance/api/v1/price')
pancakeswap_prices = pancakeswap_request.json()
coingecko_id_request = requests.get(('https://api.coingecko.com/api/v3/coins/list?include_platform=true'))
coingecko_id = coingecko_id_request.json()
try:
print("Checking PancakeSwap...")
pancakeswap_prices['prices'][token_name.upper()]
price_check_BSC()
except KeyError:
print("Checking CoinGecko...")
try:
for crypto_dicts in coingecko_id:
if crypto_dicts['symbol'] == token_name.lower():
price_check_id()
except KeyError:
print("Are you sure that's the correct symbol?")
The gist of what's going on here:
This is pretty good so far: now I can call one function, token_symbol_request(), and then that'll route to the correct API to pull the price information from. I realized that it's probably not worth calling the API every single time I would like to check where the coin is listed, so I plan to save a copy of the list locally. Ideally, I can call a function whenever it's needed and save an updated copy to include any new listings.
I would like my next step to be thinking about the actual portfolio itself. Specifically: how the portfolio will be organized, stored (I'll have to figure out how to write to a file!), and modified. Before doing that though, I have to change the functions that check prices to have them pull the user input from token_symbol_request(). Currently, the correct API is called, but then it requests the user to input the token again, which seems a little silly.
I'm pretty happy with the progress so far. This project has been a good learning experience, and I expect that to continue (and probably get more difficult) as time goes on.
Which language is that?
It's Python, super user friendly for a beginner.
For me programming is never friendly. Even when I copy code from tutorials in Internet and do everything the same, they often does not work.
Sorry for the late response!
Yeah, things not working is pretty standard I think, but it's the best way to learn. I had to essentially redo everything with the Pancakeswap change to V2.
I've tried tutorials and they really don't work well for me. It's just not how programming works.
It's similar to writing down the steps to completing a math problem, but then not trying to solve the problem itself. You can read an entire book on Calculus, but until you sit there and pound away equations for hours, you will more than likely understand just as much as you did before starting the book.
Making things, taking the time to read about errors, and being persistent is key. Because of my job being very busy, I had to step away from this for about a week, and I had to reteach myself some things that I had already managed to forget.
Congratulations @phul! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
Your next target is to reach 800 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Support the HiveBuzz project. Vote for our proposal!