예제 #1
0
 def __update_standard_deviation(self, all_candles):
     if len(all_candles) < 20:
         return
     last_20_candles = Candle.select_last_candles(all_candles, self.pair,
                                                  20)
     last_20_closing_prices = Candle.select_closing_prices(last_20_candles)
     from numpy import std
     self.standard_deviation.append(std(last_20_closing_prices))
예제 #2
0
 def __update_SMA_EMA(self, all_candles, period, previous_EMA):
     if len(all_candles) > period:
         last_candles = Candle.select_last_candles(all_candles, self.pair,
                                                   period)
         SMA = self.SMA.SMA(Candle.select_closing_prices(last_candles))
         EMA = self.EMA.EMA(Candle.select_closing_prices(last_candles),
                            previous_EMA)
         return SMA, EMA
예제 #3
0
 def __update_SMA_EMA_first_time(self, all_candles, period):
     if len(all_candles) < period:
         raise AverageComputationTooEarly
     if len(all_candles) == period:
         last_candles = Candle.select_last_candles(all_candles, self.pair,
                                                   period)
         SMA = self.SMA.SMA(Candle.select_closing_prices(last_candles))
         return SMA, SMA
예제 #4
0
 def __debug_plot_charts(self, all_candles):
     all_USDT_ETH_candles = Candle.select_last_candles(
         all_candles, "USDT_ETH", -1)
     closing_prices = Candle.select_closing_prices(all_USDT_ETH_candles)
     dates = Candle.select_dates(all_USDT_ETH_candles)
     self.__drawer.draw(closing_prices, dates,
                        self.__USDT_ETH_indicators.EMA.EMA_12,
                        self.__USDT_ETH_indicators.EMA.EMA_26,
                        self.__USDT_ETH_indicators.MACD.MACD,
                        self.__USDT_ETH_indicators.MACD.MACD_signal,
                        self.__USDT_ETH_indicators.stochastic.stochastic_D,
                        self.__USDT_ETH_indicators.RSI.RSI,
                        self.__USDT_ETH_indicators.ADX.ADX)
예제 #5
0
 def feed(self, all_candles):
     last_14_candles = Candle.select_last_candles(all_candles, self.pair,
                                                  14)
     self.__feed_SMA_arrays_and_EMA_arrays(all_candles, len(all_candles),
                                           last_14_candles[-1].close)
     self.MACD.feed(len(all_candles), self.EMA)
     self.__update_standard_deviation(all_candles)
     if len(all_candles) >= 14:
         self.ADX.feed(last_14_candles[-2:])
         self.RSI.feed(all_candles, last_14_candles)
         self.stochastic.feed(last_14_candles)
         self.__update_oversold_overbought_indicators()
     if len(self.standard_deviation) >= 1 and len(self.SMA.SMA_20) >= 1:
         self.BB.feed(self.SMA.SMA_20[-1], self.standard_deviation[-1],
                      last_14_candles[-1].close)
     if len(all_candles) >= 100:
         self.__define_trend(last_14_candles[-1].close)
예제 #6
0
 def __do_action_on_USDT_ETH(self, all_candles, current_stockpile,
                             bot_settings, option):
     #if (self.__buy_authorization(self.__USDT_ETH_indicators) and current_stockpile.USDT > 3):
     if (self.__buy_authorization(self.__USDT_ETH_indicators)
             or self.__buy_permission_USDT_ETH is True
         ) and current_stockpile.USDT > 3:
         if self.__buy_permission_USDT_ETH is False:
             self.__buy_permission_USDT_ETH = True
             return 0
         else:
             self.__buy_permission_USDT_ETH = False
         price_one_eth = Candle.select_last_candles(all_candles, "USDT_ETH",
                                                    1)[0].close
         amount_i_want_to_buy = current_stockpile.USDT / price_one_eth
         if option:
             return 0
         if DEBUG_TEXT_MODE:
             msg = "buy USDT_ETH " + str(amount_i_want_to_buy)
             self.__debug_print_which_indicator_triggered(
                 all_candles, current_stockpile, self.__USDT_ETH_indicators,
                 msg)
         return "buy USDT_ETH " + str(amount_i_want_to_buy)
     #elif self.__sell_authorization(self.__USDT_ETH_indicators):
     elif self.__sell_authorization(
             self.__USDT_ETH_indicators
     ) or self.__sell_permission_USDT_ETH is True:
         if self.__sell_permission_USDT_ETH is False:
             self.__sell_permission_USDT_ETH = True
             return 0
         else:
             self.__sell_permission_USDT_ETH = False
         amount_i_want_to_sell = current_stockpile.ETH
         if amount_i_want_to_sell < 0.000001 or option:
             return 0
         if DEBUG_TEXT_MODE:
             msg = "sell USDT_ETH " + str(amount_i_want_to_sell)
             self.__debug_print_which_indicator_triggered(
                 all_candles, current_stockpile, self.__USDT_ETH_indicators,
                 msg)
         return "sell USDT_ETH " + str(amount_i_want_to_sell)
     return 0
예제 #7
0
    def __debug_print_which_indicator_triggered(self, all_candles, stockpile,
                                                indicators, msg):
        if indicators.BB.buy_indicator:
            print("BB_buy indicator triggered", file=sys.stderr)
        if indicators.BB.sell_indicator:
            print("BB_ sell _indicator_ triggered", file=sys.stderr)
        if indicators.BB.BB_indicator:
            print("BB indicator triggered", file=sys.stderr)
        if indicators.stochastic.buy_indicator:
            print("stochastic buy indicator triggered", file=sys.stderr)
        if indicators.stochastic.sell_indicator:
            print("stochastic sell indicator triggered", file=sys.stderr)
        if indicators.MACD.buy_indicator:
            print("MACD buy indicator triggered", file=sys.stderr)
        if indicators.MACD.sell_indicator:
            print("MACD sell indicator triggered", file=sys.stderr)
        if indicators.trend == Trend.UPWARD:
            print("TREND UPWARD ", file=sys.stderr)
        if indicators.trend == Trend.DOWNWARD:
            print("TREND DOWNWARD ", file=sys.stderr)
        if indicators.RSI.buy_indicator:
            print("RSI buy indicator triggered", file=sys.stderr)
        if indicators.RSI.sell_indicator:
            print("RSI sell indicator triggered", file=sys.stderr)
        if indicators.ADX.buy_indicator:
            print("ADX buy indicator triggered", file=sys.stderr)
        if indicators.ADX.sell_indicator:
            print("ADX sell indicator triggered", file=sys.stderr)
        if indicators.overbought:
            print("Overbought triggered", file=sys.stderr)
        if indicators.oversold:
            print("Oversold triggered", file=sys.stderr)
        if indicators.possible_overbought:
            print("possible Overbought triggered", file=sys.stderr)
        if indicators.possible_oversold:
            print("possible Oversold triggered", file=sys.stderr)
        print("MSG = ", msg, file=sys.stderr)
        print("sto_D  = ",
              indicators.stochastic.stochastic_D[-20:],
              file=sys.stderr)
        print("RSI  = ", indicators.RSI.RSI[-20:], file=sys.stderr)
        print("ADX strength : ", indicators.ADX.ADX[-1], file=sys.stderr)
        print("DI+ strength : ",
              indicators.ADX.DI_positive[-1],
              file=sys.stderr)
        print("DI- strength : ",
              indicators.ADX.DI_negative[-1],
              file=sys.stderr)
        print("current USDT =",
              stockpile.USDT,
              " current ETH = ",
              stockpile.ETH,
              "current BTC = ",
              stockpile.BTC,
              file=sys.stderr)

        last_close = Candle.select_last_candles(all_candles, "BTC_ETH",
                                                1)[-1].close
        print("diff SMA_160 - close : ",
              indicators.SMA.SMA_160_diff,
              file=sys.stderr)
        print("diff EMA_80 - close : ",
              last_close - indicators.EMA.EMA_80[-1],
              file=sys.stderr)
        print("diff SMA_50 - close : ",
              last_close - indicators.SMA.SMA_50[-1],
              file=sys.stderr)
        print("", file=sys.stderr)