#!/usr/bin/env python import requests, json, sys def bitfinexPublicTicker(type, logger): try: uri = "https://api.bitfinex.com/v2/tickers?symbols=" + "t"+type.upper().replace('_', '') response = requests.request("GET", uri) response = json.loads(response.text) price = (float(response[0][7])+ float(response[0][1]) + float(response[0][3]))/3 price = round(price, 2) return price except KeyError as e: logger.error("Bitfinex Spot Price Error: {}".format(e)) price = 0 return price def bitfinexVolAskBid(type, logger): try: uri = "https://api.bitfinex.com/v2/tickers?symbols=" + "t"+type.upper().replace('_', '') response = requests.request("GET", uri) response = json.loads(response.text) vol = round(float((response[0][2])+response[0][4])/2, 2) ask = round(float(response[0][1]), 2) # Hourly High bid = round(float(response[0][3]), 2) # Hourly Low return vol, ask, bid except KeyError as e: logger.error("Bitfinex High Low Volume Error: {}".format(e)) return 0, 0, 0