diff --git a/api/kraken.py b/api/kraken.py index bd88bf5..9023424 100644 --- a/api/kraken.py +++ b/api/kraken.py @@ -27,7 +27,7 @@ class Kraken: self.prices = pandas.concat([self.prices, pandas.DataFrame(new_row)], ignore_index=False) 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. def calculate_ema(self, short_time=5, long_time=30): diff --git a/main.py b/main.py index e4f97b0..3966ece 100644 --- a/main.py +++ b/main.py @@ -13,12 +13,17 @@ if __name__ == "__main__": currency_pair = "XXBTZUSD" k = Kraken() - print("1") + print(1) time.sleep(1) + k.get_fee(currency_pair) + print(2) + + time.sleep(1) + k.get_ohlc_prices(currency_pair) - print("3") + print(3) time.sleep(1) @@ -26,8 +31,6 @@ if __name__ == "__main__": k.get_current_price(currency_pair) 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 k.balances["vol"][currency_buy] > 10**-5: if current_state == "Buying": @@ -38,7 +41,7 @@ if __name__ == "__main__": # Sell shit # 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 - 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") k.sell_order(currency_pair, currency_buy, currency_sell, k.balances["vol"][currency_buy]) print(k.balances) @@ -52,7 +55,7 @@ if __name__ == "__main__": # Buy shit # 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 - 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") 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)