예제 #1
0
 def test_get_avg(self):
     coin = 'BTC'
     curr = 'USD'
     avg = cryptocompare.get_avg(coin, curr, exchange='Kraken')
     self.assertEqual(avg['LASTMARKET'], 'Kraken')
     self.assertEqual(avg['FROMSYMBOL'], coin)
     self.assertEqual(avg['TOSYMBOL'], curr)
import cryptocompare

##
eth = cryptocompare.get_price('ETH', curr='USD', full=True)
pprint(eth)

##
eth_daily = cryptocompare.get_historical_price_day('ETH',
                                                   curr='USD',
                                                   limit=180)
pprint(eth_daily)

##
with open('../../public/dummy_data/eth_daily.json', 'w') as f:
    json.dump(eth_daily, f)

##
exc = cryptocompare.get_exchanges()

##
for exc_name in exc.keys():
    print(exc_name)
    avg = cryptocompare.get_avg('BTC', curr='USD', exchange=exc_name)
    break

##
avg = cryptocompare.get_avg('BTC', curr='USDT', exchange='Binance')

##
pairs = cryptocompare.get_pairs(exchange='Binance')
예제 #3
0
 def test_get_avg_given_exchange(self):
     res = cryptocompare.get_avg(coins[0], exchange='Kraken')
     self.assertTrue(len(res) > 0)
     self.assertTrue(float(res['PRICE']) > 0)
예제 #4
0
def crypto(update, context):
    new_message.new_message(update)

    with open('config.yaml', 'r') as f:
        config = yaml.full_load(f)
        apikey = config['CRYPTO']['API_KEY']

    if enable_check.enable_check(__name__):
        return

    def changepct(time):
        if len(context.args) >= 2:
            currency1 = context.args[1]
        else:
            currency1 = "BTC"
        if len(context.args) == 3:
            currency2 = context.args[2]
        else:
            currency2 = "USD"
        url = f"https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?CMC_PRO_API_KEY={apikey}&symbol={currency1.upper()}&convert={currency2.upper()}"
        r = requests.get(url)
        msg = r.json()['data'][currency1.upper()]['quote'][
            currency2.upper()][f'percent_change_{time[:-1]}']
        if msg > 0.01 or msg < -0.01:
            msg = round(msg, 2)
            if msg > 0.0:
                msg = f"+{msg}"
        return msg

    # crypto % change for past 24h, 7d, 30d
    if len(context.args) >= 1 and context.args[0] in ['24h%', '7d%', '30d%']:
        msg = changepct(context.args[0])
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=f'{msg}%')

    # /crypto 24h btc
    elif len(context.args) >= 1 and context.args[0] == "24h":
        if len(context.args) >= 2:
            currency1 = context.args[1]
        else:
            currency1 = "BTC"
        if len(context.args) == 3:
            currency2 = context.args[2]
        else:
            currency2 = "USD"
        try:
            symbol = currency.symbol(currency2, native=False)
        except:
            symbol = ""
        avg = cryptocompare.get_avg(currency1, currency=currency2)
        msg = avg['CHANGE24HOUR']
        if msg > 0.01 or msg < -0.01:
            msg = round(msg, 2)
            if msg > 0.0:
                msg = f"+{msg}"
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=f"{msg}{symbol}")

    # /crypto btc eur
    elif len(context.args) >= 1:
        currency1 = context.args[0].upper()

        if len(context.args) == 2:
            currency2 = context.args[1].upper()
        else:
            currency2 = "USD"
        try:
            symbol = currency.symbol(currency2, native=False)
        except:
            symbol = ''
        price = cryptocompare.get_price(currency1,
                                        currency=currency2,
                                        full=False)

        if price:
            context.bot.send_message(
                chat_id=update.message.chat_id,
                text=f"{symbol}{price[currency1][currency2]}")
        else:
            context.bot.send_message(chat_id=update.message.chat_id,
                                     text=f"Sorry, can\'t find {currency1}")
        return

    elif not context.args or len(context.args) > 3:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 parse_mode='markdown',
                                 text='Usage: `/crypto <btc,eth,xmr,etc>`')
        return
예제 #5
0
print(cryptocompare.get_price(coins, curr='USD'))
print(cryptocompare.get_price(coins, curr=['EUR','USD','GBP']))

print('==================== HIST PRICE ==================')
print(cryptocompare.get_historical_price(coins[0]))
print(cryptocompare.get_historical_price(coins[0], curr='USD'))
print(cryptocompare.get_historical_price(coins[1], curr=['EUR','USD','GBP']))
print(cryptocompare.get_historical_price(coins[1], 'USD', datetime.datetime.now()))
print(cryptocompare.get_historical_price(coins[2], ['EUR','USD','GBP'], time.time(), exchange='Kraken'))

print('================== HIST PRICE MINUTE ===============')
print(cryptocompare.get_historical_price_minute(coins[0], curr='USD'))
print(cryptocompare.get_historical_price_minute(coins[0], curr='USD', limit=100))

print('================== HIST PRICE HOUR ===============')
print(cryptocompare.get_historical_price_hour(coins[0]))
print(cryptocompare.get_historical_price_hour(coins[0], curr='USD'))
print(cryptocompare.get_historical_price_hour(coins[1], curr=['EUR','USD','GBP']))

print('================== HIST PRICE DAY ================')
print(cryptocompare.get_historical_price_day(coins[0]))
print(cryptocompare.get_historical_price_day(coins[0], curr='USD'))
print(cryptocompare.get_historical_price_day(coins[1], curr=['EUR','USD','GBP']))

print('======================== AVG =====================')
print(cryptocompare.get_avg(coins[0], exchange='Coinbase'))
print(cryptocompare.get_avg(coins[0], curr='USD', exchange='Coinbase'))

print('====================== EXCHANGES =================')
print(cryptocompare.get_exchanges())
예제 #6
0
 def test_get_avg(self):
     res = cryptocompare.get_avg(coins[1])
     self.assertTrue(len(res) > 0)
     self.assertTrue(float(res['PRICE']) > 0)
예제 #7
0
def get_latest_crypto_price(n):
    valuetext = cryptocompare.get_avg('BTC', curr='USD', exchange='Kraken')
    return float(valuetext['PRICE'])
예제 #8
0
 def get_average(self, crypto, exchange):
     avg = cryptocompare.get_avg(crypto, curr='EUR', exchange=exchange)
     return avg
예제 #9
0
 def test_get_avg(self):
     print "-- testing get_avg() --"
     cryptocompare.get_avg(coins[0], markets='Coinbase')
     cryptocompare.get_avg(coins[0], curr='USD', markets='Coinbase')
예제 #10
0
print(cryptocompare.get_coin_list())
print(cryptocompare.get_coin_list(True))

print('===================== PRICE ======================')
print(cryptocompare.get_price(coins[0]))
print(cryptocompare.get_price(coins[1], curr='USD'))
print(cryptocompare.get_price(coins[2], curr=['EUR', 'USD', 'GBP']))
print(cryptocompare.get_price(coins[2], full=True))
print(cryptocompare.get_price(coins[0], curr='USD', full=True))
print(cryptocompare.get_price(coins[1], curr=['EUR', 'USD', 'GBP'], full=True))

print('==================================================')
print(cryptocompare.get_price(coins))
print(cryptocompare.get_price(coins, curr='USD'))
print(cryptocompare.get_price(coins, curr=['EUR', 'USD', 'GBP']))

print('==================== HIST PRICE ==================')
print(cryptocompare.get_historical_price(coins[0]))
print(cryptocompare.get_historical_price(coins[0], curr='USD'))
print(cryptocompare.get_historical_price(coins[1], curr=['EUR', 'USD', 'GBP']))
print(
    cryptocompare.get_historical_price(coins[1], 'USD',
                                       datetime.datetime.now()))
print(
    cryptocompare.get_historical_price(coins[2], ['EUR', 'USD', 'GBP'],
                                       time.time()))

print('======================== AVG =====================')
print(cryptocompare.get_avg(coins[2]))
print(cryptocompare.get_avg(coins[2], curr='USD'))
예제 #11
0
print(cryptocompare.get_historical_price(coins[0]))
print(cryptocompare.get_historical_price(coins[0], curr='USD'))
print(cryptocompare.get_historical_price(coins[1], curr=['EUR', 'USD', 'GBP']))
print(
    cryptocompare.get_historical_price(coins[1], 'USD',
                                       datetime.datetime.now()))
print(
    cryptocompare.get_historical_price(coins[2], ['EUR', 'USD', 'GBP'],
                                       time.time()))

print('================== HIST PRICE HOUR ===============')
print(cryptocompare.get_historical_price_hour(coins[0]))
print(cryptocompare.get_historical_price_hour(coins[0], curr='USD'))
print(
    cryptocompare.get_historical_price_hour(coins[1],
                                            curr=['EUR', 'USD', 'GBP']))

print('================== HIST PRICE DAY ================')
print(cryptocompare.get_historical_price_day(coins[0]))
print(cryptocompare.get_historical_price_day(coins[0], curr='USD'))
print(
    cryptocompare.get_historical_price_day(coins[1],
                                           curr=['EUR', 'USD', 'GBP']))

print('======================== AVG =====================')
print(cryptocompare.get_avg(coins[0], markets='Coinbase'))
print(cryptocompare.get_avg(coins[0], curr='USD', markets='Coinbase'))

print('====================== EXCHANGES =================')
print(cryptocompare.get_exchanges())