Fixed a bunch of stupid

This commit is contained in:
Logan G 2021-02-04 01:14:39 -07:00
parent 048e22024a
commit 39c7895afb
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 10 additions and 7 deletions

View file

@ -27,7 +27,7 @@ class Kraken:
self.prices = pandas.concat([self.prices, pandas.DataFrame(new_row)], ignore_index=False) self.prices = pandas.concat([self.prices, pandas.DataFrame(new_row)], ignore_index=False)
def get_fee(self, pair): def get_fee(self, pair):
self.fee = k.kraken_wrapper.get_tradable_asset_pairs(pair=currency_pair)["fees"][0][0][1] self.fee = self.kraken_wrapper.get_tradable_asset_pairs(pair=pair)["fees"][0][0][1]
# Calculates the exponential moving average by grabbing data from Kraken on the conversion rate every interval minutes. # Calculates the exponential moving average by grabbing data from Kraken on the conversion rate every interval minutes.
def calculate_ema(self, short_time=5, long_time=30): def calculate_ema(self, short_time=5, long_time=30):

15
main.py
View file

@ -13,12 +13,17 @@ if __name__ == "__main__":
currency_pair = "XXBTZUSD" currency_pair = "XXBTZUSD"
k = Kraken() k = Kraken()
print("1") print(1)
time.sleep(1)
k.get_fee(currency_pair)
print(2)
time.sleep(1) time.sleep(1)
k.get_ohlc_prices(currency_pair) k.get_ohlc_prices(currency_pair)
print("3") print(3)
time.sleep(1) time.sleep(1)
@ -26,8 +31,6 @@ if __name__ == "__main__":
k.get_current_price(currency_pair) k.get_current_price(currency_pair)
k.calculate_ema() k.calculate_ema()
k.get_fee()
# If we have crypto, check for sell behaviour, if we have fiat, check for buy behavior, otherwise, get really confused # 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: if k.balances["vol"][currency_buy] > 10**-5:
if current_state == "Buying": if current_state == "Buying":
@ -38,7 +41,7 @@ if __name__ == "__main__":
# Sell shit # Sell shit
# If the short term EMA (accounting for the fee) is less than the long term EMA, # If the short term EMA (accounting for the fee) is less than the long term EMA,
# and there is more than a 0.1% difference between short and long term EMA (accounting for the fee), sell # and there is more than a 0.1% difference between short and long term EMA (accounting for the fee), sell
if k.short_ema.tail(1)[0][0] * (1-self.fee/100) < k.long_ema.tail(1)[0][0] and k.long_ema.tail(1)[0][0]/(k.short_ema.tail(1)[0][0] * (1-self.fee/100)) - 1 > 0.001: if k.short_ema.tail(1)[0][0] * (1-k.fee/100) < k.long_ema.tail(1)[0][0] and k.long_ema.tail(1)[0][0]/(k.short_ema.tail(1)[0][0] * (1-k.fee/100)) - 1 > 0.001:
print("Selling shit") print("Selling shit")
k.sell_order(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_buy]) k.sell_order(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_buy])
print(k.balances) print(k.balances)
@ -52,7 +55,7 @@ if __name__ == "__main__":
# Buy shit # Buy shit
# If the previous state is known, and the short term EMA (accounting for the fee) is greater than the long term EMA, # If the previous state is known, and the short term EMA (accounting for the fee) is greater than the long term EMA,
# and there is more than a 0.1% difference between short and long term EMA (accounting for the fee), buy # and there is more than a 0.1% difference between short and long term EMA (accounting for the fee), buy
if previous_state != "Unknown" and k.short_ema.tail(1)[0][0] * (self.fee/100+1) > k.long_ema.tail(1)[0][0] and (k.short_ema.tail(1)[0][0] * (self.fee/100+1))/k.long_ema.tail(1)[0][0] - 1 > 0.001: if previous_state != "Unknown" and k.short_ema.tail(1)[0][0] * (k.fee/100+1) > k.long_ema.tail(1)[0][0] and (k.short_ema.tail(1)[0][0] * (k.fee/100+1))/k.long_ema.tail(1)[0][0] - 1 > 0.001:
print("Buying shit") print("Buying shit")
k.buy_order(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_sell] * 0.95 * (1/k.prices.tail(1)[0][0])) k.buy_order(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_sell] * 0.95 * (1/k.prices.tail(1)[0][0]))
print(k.balances) print(k.balances)