def market_update(currency): market_response = requests.request("GET", market_url).json()['result'] # Create a new variable to instantiate the api. isFound = False # crypto-currency is set to not being in the database. for item in market_response: if item["MarketName"] == currency.coin_pair: # if the isFound = True coin_ticker = item['MarketCurrency'] coin_base = item['BaseCurrency'] coin_name = item['MarketCurrencyLong'] coin_pair = item['MarketName'] coin_active = item['IsActive'] coin_created = item['Created'] coin_logo = item['LogoUrl'] Market.create(coin_ticker=coin_ticker, coin_base=coin_base, coin_name=coin_name, coin_pair=coin_pair, coin_active=coin_active, coin_created=coin_created, coin_logo=coin_logo, currency_id=currency.id).save() break if not isFound: Market.create(currency_id=currency.id).save()