49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import time, threading
|
|
import pandas
|
|
|
|
from api.kraken import Kraken
|
|
from api.fake import Fake
|
|
|
|
glubul = ":)"
|
|
|
|
if __name__ == "__main__":
|
|
currency_buy = "XXBT"
|
|
currency_sell = "ZUSD"
|
|
currency_pair = "XXBTZUSD"
|
|
|
|
k = Kraken()
|
|
print("1")
|
|
time.sleep(1)
|
|
k.getPrices(currency_pair)
|
|
print("3")
|
|
k.calculateEMA()
|
|
print("4")
|
|
|
|
time.sleep(1)
|
|
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)
|
|
k.calculateEMA()
|
|
|
|
# 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")
|
|
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])):
|
|
print("Buying shit")
|
|
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.")
|
|
|
|
time.sleep(3)
|