CryptoBot/kraken.py
2021-01-30 18:11:16 -07:00

35 lines
962 B
Python

from tenacity import retry, wait_exponential
import krakenex, threading
class Kraken:
def __init__(self):
self.krakenAPI = krakenex.API()
self.krakenAPI.load_key("kraken.key")
self.callCounter = 0
self.callCooldown = 2
self.callMaximum = 15
threading.Timer(self.callCooldown, self.decrementCallCounter).start()
def decrementCallCounter(self):
#print(self.callCounter)
if self.callCounter > 0:
self.callCounter -= 1
threading.Timer(self.callCooldown, self.decrementCallCounter).start()
@retry(wait=wait_exponential(multiplier=1, min=1, max=10))
def getBalances(self):
# Garbage way of handling this, but better than 15 minutes of :(
if self.callCounter >= self.callMaximum:
time.sleep(self.callCooldown)
self.balances = self.krakenAPI.query_private("Balance")
self.callCounter += 1