35 lines
877 B
Python
35 lines
877 B
Python
#!/usr/bin/env python
|
|
|
|
import sys, os
|
|
|
|
from coinbase.wallet.client import Client
|
|
|
|
from dotenv import load_dotenv
|
|
from pathlib import Path # python3 only
|
|
env_path = Path('.') / 'configuration/coinbase.env'
|
|
load_dotenv(dotenv_path=env_path)
|
|
|
|
class keys():
|
|
|
|
def __init__(self):
|
|
self.api_key = os.getenv('API_KEY')
|
|
self.api_secret = os.getenv("API_SECRET")
|
|
|
|
def coinbasePublicTicker(type):
|
|
|
|
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, 3)
|
|
return price
|
|
except KeyError as e:
|
|
print("Coinbase Spot Price Error: %s" % str(e))
|
|
sys.stdout.flush()
|
|
price = 0
|
|
return price |