예제 #1
0
    def _updater(self):
        '''
        This section is incharge of updating and getting data for indicators.

        -> Do periodic timed events
            The updater will update data based on a set interval.
            
        -> Calculate and Re-calculate the Indicators.
            re-calculate the indicators used with new candle data.
    
        -> Do checks on the API account.
            Do checks on teh account depending on the current order state.
            
        '''
        current_unix_time = time.time()

        ## Periodic timer (1 min)
        if self.last_inter_update + 60 <= current_unix_time:
            self.last_inter_update = current_unix_time

        ## Re-calculate Indicators
        if 'MACD' in self.indicators:
            MACD = self.indicators['MACD'][:]

        ## [INDICATOR] ----->
        try:
            self.indicators['MACD'] = TI.get_MACD(self.candles['close'],
                                                  signal=14)
        except:
            self.indicators['MACD'] = MACD[:]

        ## Main Updater
        if self.runtime['state'] == 'FORCE_STANDBY':
            # If force standy then force the trader to reset.
            self._setup_buy()
            self.runtime['state'] = 'STANDBY'

        if self.run_type == 'REAL':
            # Check the current order/trade.
            manager = self._balance_manager()

            if manager:
                if manager['code'] != None:
                    side = 'BUY' if self.trade_information['orderType'][
                        'S'] == None else 'SELL'
                    self._code_manager(manager['code'], side)

        # Setup a time stamp of the last time the trader was updated.
        current_localtime = time.localtime()
        self.runtime['time'] = '{0}:{1}:{2}'.format(current_localtime[3],
                                                    current_localtime[4],
                                                    current_localtime[5])

        if self.runtime['state'] == 'SETUP':
            self.runtime['state'] = 'RUN'
예제 #2
0
    def _updater(self):
        '''
        This section is incharge of updating and getting data for indicators.
        -> Do timing for periodic events.
        -> Calculate and Re-calculate the Indicators.
        -> Do checks on the apis account and other periodic checks.
        '''
        symbol = self.runtime['symbol']
        tInfo = self.TradesInformation
        cMarket = self.currentMarket

        ## <----------------------------------| BOT TIMING MANAGEMENT |-----------------------------------> ##
        unixTime = time.time()

        ## Used to run peridotical updates (every 1 min).
        if self.lastUpdateTime['iu'] + 60 <= unixTime:
            self.lastUpdateTime['iu'] = unixTime

        ## <----------------------------------| INITIALIZE INDICATORS |-----------------------------------> ##
        candles = self.candles

        if 'MACD' in self.normalIndicators:
            MACD = self.normalIndicators['MACD'][:]

        ## [INDICATOR] ----->
        try:
            self.normalIndicators['MACD'] = TI.get_MACD(candles['close'],
                                                        signal=14)
        except:
            self.normalIndicators['MACD'] = MACD[:]

        ## <----------------------------------| RUNTIME CHECKS |-----------------------------------> ##
        if self.runtime['state'] == 'FORCE_STANDBY':
            ## If force standy then force the trader to reset.
            self._setup_buy()
            self.runtime['state'] = 'STANDBY'

        if self.botRunType == 'real':
            ## Check the current order/trade.
            manager = self._balance_manager()

            if manager:
                side = 'BUY' if tInfo['orderType']['S'] == None else 'SELL'

                self._code_manager(manager['code'], side)

        ## Setup a time stamp of the last time the trader was updated.
        currenyTime = time.localtime()
        self.runtime['time'] = '{0}:{1}:{2}'.format(currenyTime[3],
                                                    currenyTime[4],
                                                    currenyTime[5])

        if self.runtime['state'] == 'SETUP':
            self.runtime['state'] = 'RUN'
예제 #3
0
	def get_sorted_candles(self, market, interval, limit):
		"""
		This is used to get the candles for a specific market and the interval.
		"""
		sortedCandles = None

		candles = self.get_candles(market, interval, limit=limit)
		try:
			sortedCandles = TI.sort_candle(candles, "binance")
		except Exception as e:
			print_out(e, "getting candles")

		return(sortedCandles)
예제 #4
0
    def get_sorted_candles(self, market, interval, limit):
        """
		This is used to get the candles for a specific market and the interval.
		"""
        sortedCandles = None

        candles = self.get_candles(market, interval, limit=limit)
        try:
            sortedCandles = TI.sort_candle(candles, "binance")
        except Exception as e:
            print_out(e, "getting candles")

        return (sortedCandles)
예제 #5
0
	def update(self, forceUpdate):
		"""
		This section is incharge of updating and getting data for indicators.
		"""
		intervalUpdate = False
		localTime 	= time.localtime()
		unixTime	= time.time()
		market 		= self.traderInfo["market"]
		call 		= self.call
		fcandles 	= self.fCandles


		"""##############					 ##############
		##############	 Timing For Bot Func 	############## 	
		"""##############					 ##############
		if self.timeInt[-1] == "m":
			currentTime = localTime[4]
		elif self.timeInt[-1] == "h":
			currentTime = localTime[3]

		## This sets up and for interval updates
		if (currentTime != self.lastUpdateTime["U"] and (currentTime % int(self.timeInt[0:-1]) == 0)) or (forceUpdate):
			self.lastUpdateTime["U"] = currentTime
			intervalUpdate = True

		## THis will update candles every 10s or on candle close.
		if (self.lastUpdateTime["candle"]+20) <= unixTime or intervalUpdate:
			self.lastUpdateTime["candle"] = unixTime
			fcandles = call.get_sorted_candles(market, self.timeInt, 400)
			self.traderInfo["CMI"]["lastPrice"] = fcandles["close"][0]

		## This is used for very simple error correction.
		if self.traderInfo["status"] == "STANDBY_ERROR":
			self.traderInfo["status"] = "RUNNING"

		try:
			## This section is for adding indicators [PLACEINDS]
			
			self.traderInfo["Ind"]["MACD"] = TI.get_MACD(fcandles["close"], 12, 26, 9, 4)

			## --------------------------------------->
		except Exception as e:
			print("Error with Indicators!")
			print(e)
			self.traderInfo["status"] = "STANDBY_ERROR"


		self.fCandles = fcandles
예제 #6
0
    def _updater(self):
        '''
        This section is incharge of updating and getting data for indicators.
        -> Timing
        -> Indicators
        -> Checks
        '''
        tInfo = self.TradesInformation
        cMarket = self.currentMarket

        ## <----------------------------------| BOT TIMING MANAGEMENT |-----------------------------------> ##
        unixTime = time.time()
        update = False

        ## Used to run peridotical updates (every 1 min).
        if self.lastUpdateTime['iu'] + 60 <= unixTime:
            self.lastUpdateTime['iu'] = unixTime
            update = True
        ## <----------------------------------------------------------------------------------------------> ##

        ## <----------------------------------| INITIALIZE INDICATORS |-----------------------------------> ##
        candles = self.candles
        normalClose = candles['close']
        normalOpen = candles['open']

        ## [INDICATOR] ----->
        self.normalIndicators['MA9'] = TI.get_SMA(normalClose, maPeriod=9)
        self.normalIndicators['MA21'] = TI.get_SMA(normalClose, maPeriod=21)
        self.normalIndicators['BB'] = TI.get_BOLL(normalClose,
                                                  ma_type=21,
                                                  stDev=2)
        self.normalIndicators['RSI'] = TI.get_RSI(normalClose, rsiType=14)
        self.normalIndicators['MACD'] = TI.get_MACD(normalOpen, signal=14)
        self.normalIndicators['Ichimoku'] = TI.get_Ichimoku(candles,
                                                            tS_type=9,
                                                            kS_type=26,
                                                            sSB_type=52,
                                                            dataType='normal')
        ## <----------------------------------------------------------------------------------------------> ##

        ## <----------------------------------| RUNTIME CHECKS |-----------------------------------> ##
        if self.botRunType == 'real':
            ## Used to check what the trader is able to do and what not.
            manager = self._balance_manager()
            logging.info(manager)
            side = 'BUY' if tInfo['orderType']['S'] == None else 'SELL'

            ## Manage the code given by balance manager.
            self._code_manager(manager['code'], side)

            ## Update the balance for active trades.
            balance = self.RESTapi.get_balance()
            self.TradesInformation['currencyLeft'] = tInfo['MAC'] - (
                balance['free'] * cMarket['lastPrice'])

        if update:
            if tInfo['orderType']['S'] == 'limit':
                self.TradesInformation['updateOrder'] = True

        ## Setup a time stamp of the last time the trader was updated.
        currenyTime = time.localtime()
        self.runtime['time'] = '{0}:{1}:{2}'.format(currenyTime[3],
                                                    currenyTime[4],
                                                    currenyTime[5])

        if self.runtime['state'] == 'Setup':
            self.runtime['state'] = 'Running'