CryptoBot/main.py

49 lines
1.7 KiB
Python
Raw Normal View History

2021-01-31 16:17:25 -05:00
import time, threading
import pandas
2021-01-31 03:15:56 -05:00
from api.kraken import Kraken
from api.fake import Fake
2021-01-31 16:17:25 -05:00
glubul = ":)"
2021-01-31 03:15:56 -05:00
2021-01-31 03:18:06 -05:00
if __name__ == "__main__":
2021-02-01 22:34:35 -05:00
currency_buy = "XXBT"
2021-01-31 16:17:25 -05:00
currency_sell = "ZUSD"
2021-02-01 22:34:35 -05:00
currency_pair = "XXBTZUSD"
2021-01-31 16:17:25 -05:00
2021-01-31 03:18:06 -05:00
k = Kraken()
2021-01-31 16:17:25 -05:00
print("1")
time.sleep(1)
k.getPrices(currency_pair)
print("3")
2021-02-02 17:51:46 -05:00
time.sleep(1)
2021-01-31 16:17:25 -05:00
while True:
2021-02-01 22:34:35 -05:00
#print("Main loop")
2021-02-01 00:19:16 -05:00
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)
2021-02-01 23:23:32 -05:00
k.calculateEMA()
2021-02-01 00:19:16 -05:00
2021-01-31 16:17:25 -05:00
# 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])):
print("Selling shit")
2021-02-01 00:19:16 -05:00
k.sellOrder(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_buy])
2021-01-31 16:17:25 -05:00
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])):
print("Buying shit")
2021-02-01 00:19:16 -05:00
k.buyOrder(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_sell] * (1/k.prices.tail(1)[0]))
2021-01-31 16:17:25 -05:00
print(k.balances)
else:
raise Exception("There is no currency in this account.")
time.sleep(3)