More updates

This commit is contained in:
Logan G 2021-02-01 20:34:35 -07:00
parent 83530fe52e
commit 0a9730d958
Signed by: logan
GPG key ID: E328528C921E7A7A
3 changed files with 39 additions and 20 deletions

View file

@ -8,6 +8,8 @@ class Kraken:
self.krakenAPI = krakenex.API() self.krakenAPI = krakenex.API()
self.krakenAPI.load_key("kraken.key") self.krakenAPI.load_key("kraken.key")
self.krakenWrapper = KrakenAPI(self.krakenAPI) self.krakenWrapper = KrakenAPI(self.krakenAPI)
self.getBalances()
# Updates the current wallet prices from the internet # Updates the current wallet prices from the internet
def getBalances(self): def getBalances(self):
@ -27,17 +29,17 @@ class Kraken:
def calculateEMA(self, shortTime=round(time.time())-(7*24*3600), longTime=round(time.time())-(30*24*3600), interval=60): 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.prices = self.krakenWrapper.get_ohlc_data("XXBTZUSD", interval=interval, since=longTime)[0].close.iloc[::-1]
self.longEMA = self.prices.ewm(span=1*24).mean() self.longEMA = self.prices.ewm(span=12).mean()
self.shortEMA = self.prices.ewm(span=6).mean() self.shortEMA = self.prices.ewm(span=3).mean()
def buyOrder(self, pair, currency_buy, currency_sell, amount, type="market"): def buyOrder(self, currency_pair, currency_buy, currency_sell, amount, _type="market"):
#self.krakenWrapper.add_standard_order(currency_pair, "sell", type, volume=k.balances["vol"][currency_buy], validate=True) self.krakenWrapper.add_standard_order(currency_pair, "sell", _type, volume=amount, validate=True)
self.balances["vol"][currency_buy] += amount self.balances["vol"][currency_buy] += amount
self.balances["vol"][currency_sell] -= amount * self.prices.tail(1)[0] self.balances["vol"][currency_sell] -= amount * self.prices.tail(1)[0]
def sellOrder(self, pair, currency_buy, currency_sell, amount, type="market"): def sellOrder(self, currency_pair, currency_buy, currency_sell, amount, _type="market"):
#self.krakenWrapper.add_standard_order(currency_pair, "buy", type, volume=k.balances["vol"][currency_sell], validate=True) self.krakenWrapper.add_standard_order(currency_pair, "buy", _type, volume=amount, validate=True)
self.balances["vol"][currency_buy] -= amount self.balances["vol"][currency_buy] -= amount
self.balances["vol"][currency_sell] += amount * self.prices.tail(1)[0] self.balances["vol"][currency_sell] += amount * self.prices.tail(1)[0]

18
main.py
View file

@ -1,5 +1,4 @@
import time, threading import time, threading
import matplotlib.pyplot as plt
import pandas import pandas
from api.kraken import Kraken from api.kraken import Kraken
@ -8,23 +7,21 @@ from api.fake import Fake
glubul = ":)" glubul = ":)"
if __name__ == "__main__": if __name__ == "__main__":
currency_buy = "XXDG" currency_buy = "XXBT"
currency_sell = "ZUSD" currency_sell = "ZUSD"
currency_pair = "XDGUSD" currency_pair = "XXBTZUSD"
k = Kraken() k = Kraken()
print("1") print("1")
k.getBalances()
print("2")
time.sleep(1) time.sleep(1)
k.getPrices(currency_pair) k.getPrices(currency_pair)
print("3") print("3")
k.calculateEMA() k.calculateEMA()
print("4") print("4")
time.sleep(1) time.sleep(1)
while True: while True:
print("Main loop") #print("Main loop")
current_price = float(k.krakenWrapper.get_ticker_information(currency_pair)["c"][0][0]) current_price = float(k.krakenWrapper.get_ticker_information(currency_pair)["c"][0][0])
new_row = pandas.DataFrame([[current_price]], index=[pandas.to_datetime(time.time(), unit = "s")]) new_row = pandas.DataFrame([[current_price]], index=[pandas.to_datetime(time.time(), unit = "s")])
@ -49,10 +46,3 @@ if __name__ == "__main__":
raise Exception("There is no currency in this account.") raise Exception("There is no currency in this account.")
time.sleep(3) time.sleep(3)
'''
plt.plot(k.shortEMA)
plt.plot(k.longEMA)
plt.plot(k.prices)
plt.show()
'''

27
plot.py Normal file
View file

@ -0,0 +1,27 @@
import time, threading
import matplotlib.pyplot as plt
import pandas
from api.kraken import Kraken
from api.fake import Fake
if __name__ == "__main__":
currency_buy = "XXBT"
currency_sell = "ZUSD"
currency_pair = "XXBTZUSD"
k = Kraken()
print("1")
k.getBalances()
print("2")
time.sleep(1)
k.getPrices(currency_pair)
print("3")
k.calculateEMA()
print("4")
plt.plot(k.shortEMA)
plt.plot(k.longEMA)
plt.plot(k.prices)
plt.show()