CryptoBot/main.py
2021-01-31 14:17:25 -07:00

67 lines
2.5 KiB
Python

import time, threading
import matplotlib.pyplot as plt
import pandas
from api.kraken import Kraken
from api.fake import Fake
glubul = ":)"
if __name__ == "__main__":
currency_buy = "XXDG"
currency_sell = "ZUSD"
currency_pair = "XDGUSD"
k = Kraken()
print("1")
k.updateBalances()
print("2")
time.sleep(1)
k.getPrices(currency_pair)
print("3")
k.calculateEMA()
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:
# 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
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
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)
'''
plt.plot(k.shortEMA)
plt.plot(k.longEMA)
plt.plot(k.prices)
plt.show()