38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
#!/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][9]) + float(response[0][10]))/3
|
|
price = round(price, 3)
|
|
return price
|
|
except KeyError as e:
|
|
logger.error("Bitfinex Spot Price Error: {}".format(e))
|
|
price = 0
|
|
return price
|
|
|
|
def bitfinexHighLowVol(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)
|
|
|
|
high = round(float(response[0][9]), 3)
|
|
low = round(float(response[0][10]), 3)
|
|
vol = round(float((response[0][8]))/24, 3)
|
|
|
|
ask = round(float(response[0][1]), 3)
|
|
bid = round(float(response[0][3]), 3)
|
|
|
|
return high, low, vol, ask, bid
|
|
except KeyError as e:
|
|
logger.error("Bitfinex High Low Volume Error: {}".format(e))
|
|
return 0, 0, 0 |