More updates
This commit is contained in:
parent
83530fe52e
commit
0a9730d958
3 changed files with 39 additions and 20 deletions
|
@ -8,6 +8,8 @@ class Kraken:
|
|||
self.krakenAPI = krakenex.API()
|
||||
self.krakenAPI.load_key("kraken.key")
|
||||
self.krakenWrapper = KrakenAPI(self.krakenAPI)
|
||||
self.getBalances()
|
||||
|
||||
|
||||
# Updates the current wallet prices from the internet
|
||||
def getBalances(self):
|
||||
|
@ -27,17 +29,17 @@ class Kraken:
|
|||
def calculateEMA(self, shortTime=round(time.time())-(7*24*3600), longTime=round(time.time())-(30*24*3600), interval=60):
|
||||
#self.prices = self.krakenWrapper.get_ohlc_data("XXBTZUSD", interval=interval, since=longTime)[0].close.iloc[::-1]
|
||||
|
||||
self.longEMA = self.prices.ewm(span=1*24).mean()
|
||||
self.shortEMA = self.prices.ewm(span=6).mean()
|
||||
self.longEMA = self.prices.ewm(span=12).mean()
|
||||
self.shortEMA = self.prices.ewm(span=3).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)
|
||||
def buyOrder(self, currency_pair, currency_buy, currency_sell, amount, _type="market"):
|
||||
self.krakenWrapper.add_standard_order(currency_pair, "sell", _type, volume=amount, 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)
|
||||
def sellOrder(self, currency_pair, currency_buy, currency_sell, amount, _type="market"):
|
||||
self.krakenWrapper.add_standard_order(currency_pair, "buy", _type, volume=amount, validate=True)
|
||||
self.balances["vol"][currency_buy] -= amount
|
||||
self.balances["vol"][currency_sell] += amount * self.prices.tail(1)[0]
|
||||
|
||||
|
|
16
main.py
16
main.py
|
@ -1,5 +1,4 @@
|
|||
import time, threading
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas
|
||||
|
||||
from api.kraken import Kraken
|
||||
|
@ -8,14 +7,12 @@ from api.fake import Fake
|
|||
glubul = ":)"
|
||||
|
||||
if __name__ == "__main__":
|
||||
currency_buy = "XXDG"
|
||||
currency_buy = "XXBT"
|
||||
currency_sell = "ZUSD"
|
||||
currency_pair = "XDGUSD"
|
||||
currency_pair = "XXBTZUSD"
|
||||
|
||||
k = Kraken()
|
||||
print("1")
|
||||
k.getBalances()
|
||||
print("2")
|
||||
time.sleep(1)
|
||||
k.getPrices(currency_pair)
|
||||
print("3")
|
||||
|
@ -24,7 +21,7 @@ if __name__ == "__main__":
|
|||
|
||||
time.sleep(1)
|
||||
while True:
|
||||
print("Main loop")
|
||||
#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")])
|
||||
|
||||
|
@ -49,10 +46,3 @@ if __name__ == "__main__":
|
|||
raise Exception("There is no currency in this account.")
|
||||
|
||||
time.sleep(3)
|
||||
'''
|
||||
|
||||
plt.plot(k.shortEMA)
|
||||
plt.plot(k.longEMA)
|
||||
plt.plot(k.prices)
|
||||
plt.show()
|
||||
'''
|
||||
|
|
27
plot.py
Normal file
27
plot.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import time, threading
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas
|
||||
|
||||
from api.kraken import Kraken
|
||||
from api.fake import Fake
|
||||
|
||||
if __name__ == "__main__":
|
||||
currency_buy = "XXBT"
|
||||
currency_sell = "ZUSD"
|
||||
currency_pair = "XXBTZUSD"
|
||||
|
||||
k = Kraken()
|
||||
print("1")
|
||||
k.getBalances()
|
||||
print("2")
|
||||
time.sleep(1)
|
||||
k.getPrices(currency_pair)
|
||||
print("3")
|
||||
k.calculateEMA()
|
||||
print("4")
|
||||
|
||||
plt.plot(k.shortEMA)
|
||||
plt.plot(k.longEMA)
|
||||
plt.plot(k.prices)
|
||||
plt.show()
|
||||
|
Loading…
Reference in a new issue