Example #1
0
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)
Example #2
0
    def start(self):
        print('----SCRAPER STARTED----')
        api = NomicsApi()
        currencies = api.currencies()

        for currency in currencies:
            message = "{} ({}): ${} on {}".format(currency['name'],
                                                  currency['currency'],
                                                  currency['price'],
                                                  currency['price_timestamp'])
            print(message)

            Currency.create(
                currency=currency['currency'],
                name=currency['name'],
                price=currency['price'],
                date=currency['price_timestamp'],
                price_1h_change=currency['1h']['price_change'],
                price_1h_change_pct=currency['1h']['price_change_pct'],
                price_1d_change=currency['1d']['price_change'],
                price_1d_change_pct=currency['1d']['price_change_pct'],
                price_30d_change=currency['30d']['price_change'],
                price_30d_change_pct=currency['30d']['price_change_pct'])