29 lines
717 B
Python
29 lines
717 B
Python
#!/usr/bin/env python
|
|
|
|
import sys, os
|
|
|
|
from coinbase.wallet.client import Client
|
|
|
|
class keys():
|
|
|
|
def __init__(self):
|
|
self.api_key = os.getenv('COINBASE_KEY')
|
|
self.api_secret = os.getenv("COINBASE_SECRET")
|
|
|
|
def coinbasePublicTicker(type, logger):
|
|
|
|
api_key = keys().api_key
|
|
api_secret = keys().api_secret
|
|
|
|
type = type.upper().replace('_', '-')
|
|
|
|
try:
|
|
client = Client(api_key, api_secret)
|
|
repsonse = client.get_spot_price(currency_pair = type)
|
|
price = (float(repsonse['amount']))
|
|
price = round(price, 2)
|
|
return price
|
|
except KeyError as e:
|
|
logger.error("Coinbase Spot Price Error: {}".format(e))
|
|
price = 0
|
|
return price |