How to test several objects simultaneously in python

My goal is to to know if one of my users submitted an existing Stock Symbol in my webapp's form. So, I have a string with several words. I want to identify an active finance symbol (EURUSD=X, AAPL, ...). Because the string will count no more than 10 words, I decided to test all word independently through a yfinance request. If the stock symbol exists, Yahoo API will send me data, otherwise there is an error message 'Unknown Stock symbol'.

Therefore, I need a function that:

  1. Split all string's variable into words. Done.
  2. Test all words, one by one in the API (My code is not working)
  3. Identify the API call that receives data (might be done with a length condition as the unknown symbols all have length < 40.
import yfinance as yf
#CMD lookup
room = str("23/01/2023 24/02/2021 hello   test sj sjojzoo    jhihi EURUSD=X")
x = room.split()

def Symbol(symbol):
    aapl = yf.Ticker(symbol)
    ainfo = aapl.history(period='1y')
    if len(ainfo) >= 40:
        print('yes it is a symbol')
        print('no it is not')


Back to Top