def currency_update(): while True: currency_response = requests.request("GET", currency_url).json()['result'] for item in currency_response: coin_pair = item['MarketName'] day_high = item['High'] day_low = item['Low'] volume = item['Volume'] last_price = item['Last'] base_volume = item['BaseVolume'] bid_price = item['Bid'] ask_price = item['Ask'] open_buy = item['OpenBuyOrders'] open_sell = item['OpenSellOrders'] prev_day = item['PrevDay'] currency = Currency.select().where(Currency.coin_pair == coin_pair) if not currency: Currency.create(coin_pair=coin_pair, day_high=day_high, day_low=day_low, volume=volume, last_price=last_price, base_volume=base_volume, bid_price=bid_price, ask_price=ask_price, open_buy=open_buy, open_sell=open_sell, prev_day=prev_day).save() currency = Currency.select().where( Currency.coin_pair == coin_pair).get() market_update(currency) elif currency: Currency.update(day_high=day_high, day_low=day_low, volume=volume, last_price=last_price, base_volume=base_volume, bid_price=bid_price, ask_price=ask_price, open_buy=open_buy, open_sell=open_sell, prev_day=prev_day).where( Currency.coin_pair == coin_pair).execute() print("Paused for 900 seconds") time.sleep(900)