crypto: RSI short term

This commit is contained in:
JP
2018-02-14 23:19:03 +01:00
parent bd22485982
commit f5441c2ed9
+28 -14
View File
@@ -77,7 +77,7 @@ class Cryptocoin(object):
#dermines the expected growth of coin #dermines the expected growth of coin
def analyseCoin(self, coinId): def analyseCoin(self, coinId):
N_DATAPOINTS = 12 N_DATAPOINTS = 10
TIME_BETWEEN_DATAPOINTS = 86400 * 7 #one week TIME_BETWEEN_DATAPOINTS = 86400 * 7 #one week
#Get the price history: #Get the price history:
@@ -105,10 +105,19 @@ class Cryptocoin(object):
return growPercentage, stability, history return growPercentage, stability, history
#TODO: #TODO:
# - iets met stabiliteit?
# - https://en.wikipedia.org/wiki/Head_and_shoulders_(chart_pattern) # - https://en.wikipedia.org/wiki/Head_and_shoulders_(chart_pattern)
# - neural networks??? # - neural networks???
#get the last 14 dayprices of a coin. (can be used by RSI)
def getRecentCoinHistory(self, coinId):
N_DATAPOINTS = 14
TIME_BETWEEN_DATAPOINTS = 86400 #one day
history = []
for j in range(0, N_DATAPOINTS-1):
history.append(self.getCoinPrice(coinId, "USD", int(time.time()) - (N_DATAPOINTS-j)*TIME_BETWEEN_DATAPOINTS))
history.append(self.getCoinPrice(coinId, "USD")) #now
return history
#will return some random advice about a semi-random crypto coin #will return some random advice about a semi-random crypto coin
def getRandomCoinAdvice(self): def getRandomCoinAdvice(self):
@@ -233,31 +242,36 @@ class Cryptocoin(object):
coinId = coinId.upper() coinId = coinId.upper()
growPercentage, coinStability, coinHistory = self.analyseCoin(coinId) growPercentage, coinStability, dummy = self.analyseCoin(coinId)
if (growPercentage == 0 and coinStability == 1.0): #aanname. anders moet je weer een extra call doen.
yield from ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
return
time.sleep(0.1) #don't overload the API
coinHistory = self.getRecentCoinHistory(coinId)
coinRsi = self.rsi(coinHistory) coinRsi = self.rsi(coinHistory)
#TODO, get more recent data to feed the RSI
message = "" message = ""
if (growPercentage < -0.04): if (growPercentage < -0.04):
if (coinRsi > 70): if (coinRsi > 65):
message = "Sell! Sell! Sell! Aan " + coinId + " heb je niks meer." message = "Sell! Sell! Sell! Aan " + coinId + " heb je niks meer."
elif (coinStability < 0.3): elif (coinStability < 0.3):
message = coinId + " takelt op lange termijn af en is instabiel. Net als je moeder." message = coinId + " takelt op lange termijn af en is instabiel. Net als je moeder."
elif (coinRsi < 30): elif (coinRsi < 35):
message = "Op de lange termijn is " + coinId + " waardeloos, maar wacht nog even met verkopen." message = "Op de lange termijn is " + coinId + " waardeloos, maar wacht nog even met verkopen."
else: else:
message = "Als je " + coinId + " hebt, verkopen die handel. Daar heb je op de lange termijn niks aan." message = coinId + " is geen goede lange termijn investering."
elif (growPercentage < 0): elif (growPercentage < 0):
message = coinId + " gaat geen winnaar worden. " message = coinId + " gaat geen winnaar worden. "
if (coinRsi > 70): if (coinRsi > 65):
message += "Ditchen." message += "Ditchen."
elif (coinRsi < 30): elif (coinRsi < 30):
message += "Maar hou hem nog even vast." message += "Maar hou hem nog even vast."
elif (growPercentage < 0.025): elif (growPercentage < 0.025):
if (coinStability > 0.6): if (coinStability > 0.6):
message = coinId + " lijkt redelijk stabiel. " message = coinId + " lijkt redelijk stabiel. "
if (coinRsi < 30): if (coinRsi < 35):
message += "Bovendien een goed moment om te kopen." message += "Bovendien een goed moment om te kopen."
elif (coinRsi > 70): elif (coinRsi > 70):
message = "Ik zou " + coinId + " verkopen." message = "Ik zou " + coinId + " verkopen."
@@ -266,7 +280,7 @@ class Cryptocoin(object):
elif (growPercentage < 0.08): elif (growPercentage < 0.08):
if (coinStability > 0.45): if (coinStability > 0.45):
message = coinId + " is een stabiele groeier. " message = coinId + " is een stabiele groeier. "
if (coinRsi < 30): if (coinRsi < 35):
message += "Nu kopen!" message += "Nu kopen!"
elif (coinStability < 0.2): elif (coinStability < 0.2):
message = coinId + " groeit lekker, maar is instabiel." message = coinId + " groeit lekker, maar is instabiel."
@@ -275,11 +289,11 @@ class Cryptocoin(object):
if (coinRsi > 70): if (coinRsi > 70):
message += "Hij lijkt overbought, dus je kan nu verkopen." message += "Hij lijkt overbought, dus je kan nu verkopen."
else: else:
if (coinRsi < 30 and coinStability > 0.4): if (coinRsi < 35 and coinStability > 0.4):
message = "TO THE MOON! Nu " + coinId + " kopen!!" message = "TO THE MOON! Nu " + coinId + " kopen!!"
elif (coinStability > 0.7): elif (coinStability > 0.7):
message = coinId + " is op de lange termijn erg sterk en stabiel!" message = coinId + " is op de lange termijn erg sterk en stabiel!"
elif (coinRsi < 30): elif (coinRsi < 35):
message = "Ik raad sterk aan om " + coinId + " te kopen." message = "Ik raad sterk aan om " + coinId + " te kopen."
elif (coinRsi < 70): elif (coinRsi < 70):
message = coinId + " groeit wel erg hard. Wellicht overbought?" message = coinId + " groeit wel erg hard. Wellicht overbought?"