Skip to content

Commit

Permalink
get_prices: Add CryptoCompare support.
Browse files Browse the repository at this point in the history
get_prices iterates over all bounties in the DB and retrieves
ConversionRates from CryptoCompare if not yet available.

Add cryptocompare dependency to requirements.

Refs: gitcoinco#693, gitcoinco#491, gitcoinco#692
  • Loading branch information
cryptomental committed Apr 11, 2018
1 parent f38331b commit 307ef0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/economy/management/commands/get_prices.py
Expand Up @@ -22,6 +22,7 @@
from django.core.management.base import BaseCommand

import ccxt
import cryptocompare as cc
from dashboard.models import Bounty
from economy.models import ConversionRate
from websocket import create_connection
Expand Down Expand Up @@ -120,6 +121,38 @@ def polo():
b.save()


def cryptocompare():
"""Handle pulling market data from CryptoCompare.
Updates ConversionRates only if data not available."""

to_currency = 'USDT'
for b in Bounty.objects.all():
print('CryptoCompare {}'.format(b.pk))

conversion_rate = ConversionRate.objects.filter(
from_currency=b.token_name,
to_currency=to_currency,
timestamp=b.web3_created
)

if len(conversion_rate) == 0: # historical ConversionRate for the given bounty does not exist yet
try:
price = cc.get_historical_price(b.token_name, to_currency, b.web3_created)

to_amount = price[b.token_name][to_currency]
ConversionRate.objects.create(
from_amount=1,
to_amount=to_amount,
source='cryptocompare',
from_currency=b.token_name,
to_currency=to_currency,
timestamp=b.web3_created,
)
print('Cryptocompare: {}=>{}:{}'.format(b.token_name, to_currency, to_amount))
except Exception as e:
print(e)


class Command(BaseCommand):
"""Define the management command to update currency conversion rates."""

Expand All @@ -135,6 +168,12 @@ def handle(self, *args, **options):
except Exception as e:
print(e)

try:
print('cryptocompare')
cryptocompare()
except Exception as e:
print(e)

try:
print('polo')
polo()
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
@@ -1,5 +1,6 @@
bs4
ccxt
cryptocompare
cryptography==2.1.4
django==2.0.3
django-bootstrap3==8.2.3
Expand Down

0 comments on commit 307ef0e

Please sign in to comment.