More changes

This commit is contained in:
Logan G 2021-01-31 22:19:16 -07:00
parent d017883a15
commit 4315a641a8
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 19 additions and 20 deletions

View file

@ -10,7 +10,7 @@ class Kraken:
self.krakenWrapper = KrakenAPI(self.krakenAPI)
# Updates the current wallet prices from the internet
def updateBalances(self):
def getBalances(self):
__newBalances = self.krakenWrapper.get_account_balance()
#print(self.balances.loc["XXBT","vol"]-__newBalances.loc["XXBT","vol"])
#print(self.balances.loc["XXDG","vol"]-__newBalances.loc["XXDG","vol"])
@ -31,5 +31,13 @@ class Kraken:
self.shortEMA = self.prices.ewm(span=6).mean()
def buyOrder(self, 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.balances["vol"][currency_buy] += amount
self.balances["vol"][currency_sell] -= amount * self.prices.tail(1)[0]
def sellOrder(self, 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.balances["vol"][currency_buy] -= amount
self.balances["vol"][currency_sell] += amount * self.prices.tail(1)[0]

29
main.py
View file

@ -14,7 +14,7 @@ if __name__ == "__main__":
k = Kraken()
print("1")
k.updateBalances()
k.getBalances()
print("2")
time.sleep(1)
k.getPrices(currency_pair)
@ -23,41 +23,31 @@ if __name__ == "__main__":
print("4")
time.sleep(1)
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")])
k.prices = pandas.concat([k.prices, pandas.DataFrame(new_row)], ignore_index=False)
'''
while True:
print("Main loop")
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")])
k.prices = pandas.concat([k.prices, pandas.DataFrame(new_row)], ignore_index=False)
# If we have crypto, check for sell behaviour, if we have fiat, check for buy behavior, otherwise, get really confused
if k.balances["vol"][currency_buy] > 10**-5:
# Sell shit
# TODO: Needs to check if fresh start
# If short term change dips below long term change, sell
if(float(k.shortEMA.tail(1)[0]) < float(k.longEMA.tail(1)[0])):
#k.krakenWrapper.add_standard_order(currency_pair, "sell", "market", volume=k.balances["vol"][currency_buy], validate=True)
print("Selling shit")
k.balances["vol"][currency_sell] += k.balances["vol"][currency_buy] * k.prices.tail(1)[0]
k.balances["vol"][currency_buy] = 0
k.sellOrder(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_buy])
print(k.balances)
elif k.balances["vol"][currency_sell] > 10**-2:
# Buy shit
if(float(k.shortEMA.tail(1)[0]) > float(k.longEMA.tail(1)[0])):
#k.krakenWrapper.add_standard_order(currency_pair, "buy", "market", volume=k.balances["vol"][currency_sell], validate=True)
print("Buying shit")
k.balances["vol"][currency_buy] += k.balances["vol"][currency_sell] * (1/k.prices.tail(1)[0])
k.balances["vol"][currency_sell] = 0
k.buyOrder(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_sell] * (1/k.prices.tail(1)[0]))
print(k.balances)
else:
raise Exception("There is no currency in this account.")
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")])
k.prices = pandas.concat([k.prices, pandas.DataFrame(new_row)], ignore_index=False)
k.calculateEMA(currency_pair)
time.sleep(3)
'''
@ -65,3 +55,4 @@ plt.plot(k.shortEMA)
plt.plot(k.longEMA)
plt.plot(k.prices)
plt.show()
'''