31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from pykrakenapi import KrakenAPI
|
|
import pandas
|
|
import krakenex
|
|
import time
|
|
|
|
class Kraken:
|
|
def __init__(self):
|
|
self.krakenAPI = krakenex.API()
|
|
self.krakenAPI.load_key("kraken.key")
|
|
self.krakenWrapper = KrakenAPI(self.krakenAPI)
|
|
|
|
# Updates the current wallet prices from the internet
|
|
def updateBalances(self):
|
|
__newBalances = self.krakenWrapper.get_account_balance()
|
|
print(self.balances.loc["XXBT","vol"]-__newBalances.loc["XXBT","vol"])
|
|
print(self.balances.loc["ZUSD","vol"]-__newBalances.loc["ZUSD","vol"])
|
|
|
|
self.balances = __newBalances
|
|
|
|
# Calculates
|
|
def calculateEMA(self, shortTime=round(time.time())-(7*24*3600), longTime=round(time.time())-(30*24*3600), interval=60):
|
|
self.prices = self.krakenWrapper.get_ohlc_data("XXBTZUSD", interval=interval, since=longTime)[0].close.iloc[::-1]
|
|
#self.longEMA = self.prices.ewm(span=longTime/60/interval/2).mean()
|
|
#self.shortEMA = self.prices.truncate(before=time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(shortTime))).ewm(span=(shortTime-longTime)/60/interval/2).mean()
|
|
|
|
self.longEMA = self.prices.ewm(span=7*24).mean()
|
|
self.shortEMA = self.prices.ewm(span=30*24).mean()
|
|
|
|
|
|
|
|
|