def is6hEMA1226Bull(self): try: if isinstance(self.ema1226_6h_cache, pd.DataFrame): df_data = self.ema1226_6h_cache elif self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 21600) self.ema1226_6h_cache = df_data elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData self.ema1226_6h_cache = df_data(self.market, '6h') else: return False ta = TechnicalAnalysis(df_data) if 'ema12' not in df_data: ta.addEMA(12) if 'ema26' not in df_data: ta.addEMA(26) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['bull'] = df_last['ema12'] > df_last['ema26'] return bool(df_last['bull']) except Exception: return False
def getHistoricalData(self, market, granularity, iso8601start='', iso8601end=''): if self.exchange == 'coinbasepro': api = CBPublicAPI() return api.getHistoricalData(market, granularity, iso8601start, iso8601end) elif self.exchange == 'binance': api = BPublicAPI() if iso8601start != '' and iso8601end != '': return api.getHistoricalData( market, granularity, str( datetime.strptime( iso8601start, '%Y-%m-%dT%H:%M:%S.%f').strftime('%d %b, %Y')), str( datetime.strptime( iso8601end, '%Y-%m-%dT%H:%M:%S.%f').strftime('%d %b, %Y'))) else: return api.getHistoricalData(market, granularity) else: return pd.DataFrame()
def is1hSMA50200Bull(self): try: if self.isSimulation() and isinstance(self.sma50200_1h_cache, pd.DataFrame): df_data = self.sma50200_1h_cache if self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 3600) self.sma50200_1h_cache = df_data elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '1h') self.sma50200_1h_cache = df_data else: return False ta = TechnicalAnalysis(df_data) if 'sma50' not in df_data: ta.addSMA(50) if 'sma200' not in df_data: ta.addSMA(200) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['bull'] = df_last['sma50'] > df_last['sma200'] return bool(df_last['bull']) except Exception: return False
def getHistoricalData(self, market, granularity: int, iso8601start='', iso8601end=''): if self.exchange == 'coinbasepro': api = CBPublicAPI() if iso8601start != '' and iso8601end == '': return api.getHistoricalData( market, to_coinbase_pro_granularity(granularity), iso8601start) elif iso8601start != '' and iso8601end != '': return api.getHistoricalData( market, to_coinbase_pro_granularity(granularity), iso8601start, iso8601end) else: return api.getHistoricalData( market, to_coinbase_pro_granularity(granularity)) elif self.exchange == 'binance': api = BPublicAPI() if iso8601start != '' and iso8601end != '': return api.getHistoricalData( market, to_binance_granularity(granularity), iso8601start, iso8601end) else: return api.getHistoricalData( market, to_binance_granularity(granularity)) else: return pd.DataFrame()
def getTicker(self, market): if self.exchange == 'coinbasepro': api = CBPublicAPI() return api.getTicker(market) elif self.exchange == 'binance': api = BPublicAPI() return api.getTicker(market) else: return None
def getTime(self): if self.exchange == 'coinbasepro': return CBPublicAPI().getTime() elif self.exchange == 'binance': try: return BPublicAPI().getTime() except ReadTimeoutError: return '' else: return ''
def is6hSMA50200Bull(self): try: if self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 21600) elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '6h') else: return False ta = TechnicalAnalysis(df_data) ta.addSMA(50) ta.addSMA(200) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['bull'] = df_last['sma50'] > df_last['sma200'] return bool(df_last['bull']) except Exception: return False
def is1hEMA1226Bull(self): try: if self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 3600) elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '1h') else: return False ta = TechnicalAnalysis(df_data) ta.addEMA(12) ta.addEMA(26) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['bull'] = df_last['ema12'] > df_last['ema26'] return bool(df_last['bull']) except Exception: return False
def is6hEMA1226Bull(self, iso8601end: str = ''): try: if self.isSimulation() and isinstance(self.ema1226_6h_cache, pd.DataFrame): df_data = self.ema1226_6h_cache[(self.ema1226_6h_cache['date'] <= iso8601end)] elif self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 21600) self.ema1226_6h_cache = df_data elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '6h') self.ema1226_6h_cache = df_data else: return False ta = TechnicalAnalysis(df_data) if 'ema12' not in df_data: ta.addEMA(12) if 'ema26' not in df_data: ta.addEMA(26) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['bull'] = df_last['ema12'] > df_last['ema26'] Logger.debug("---- EMA1226 6H Check----") if self.isSimulation(): Logger.debug("simdate: " + str(df_last['date'])) Logger.debug("ema12 6h: " + str(df_last['ema12'])) Logger.debug("ema26 6h: " + str(df_last['ema26'])) Logger.debug("bull 6h: " + str(df_last['ema12'] > df_last['ema26'])) return bool(df_last['bull']) except Exception: return False
def is1hSMA50200Bull(self, iso8601end: str = ''): try: if self.isSimulation() and isinstance(self.sma50200_1h_cache, pd.DataFrame): df_data = self.sma50200_1h_cache[( self.sma50200_1h_cache['date'] <= iso8601end)] elif self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 3600) self.sma50200_1h_cache = df_data elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '1h') self.sma50200_1h_cache = df_data else: return False ta = TechnicalAnalysis(df_data) if 'sma50' not in df_data: ta.addSMA(50) if 'sma200' not in df_data: ta.addSMA(200) df_last = ta.getDataFrame().copy().iloc[-1, :] Logger.debug("---- SMA50200 1H Check----") if self.isSimulation(): Logger.debug("simdate: " + str(df_last['date'])) Logger.debug("sma50 1h: " + str(df_last['sma50'])) Logger.debug("sma200 1h: " + str(df_last['sma200'])) Logger.debug("bull 1h: " + str(df_last['sma50'] > df_last['sma200'])) df_last['bull'] = df_last['sma50'] > df_last['sma200'] return bool(df_last['bull']) except Exception: return False
def isCryptoRecession(self): try: if self.exchange == 'coinbasepro': api = CBPublicAPI() df_data = api.getHistoricalData(self.market, 86400) elif self.exchange == 'binance': api = BPublicAPI() df_data = api.getHistoricalData(self.market, '1d') else: return False # if there is an API issue, default to False to avoid hard sells if len(df_data) <= 200: return False # if there is unsufficient data, default to False to avoid hard sells ta = TechnicalAnalysis(df_data) ta.addSMA(50) ta.addSMA(200) df_last = ta.getDataFrame().copy().iloc[-1, :] df_last['crypto_recession'] = df_last['sma50'] < df_last['sma200'] return bool(df_last['crypto_recession']) except Exception: return False
maker_fee_rate = float( fees["maker_fee_rate"].to_string(index=False).strip() ) taker_fee_rate = float( fees["taker_fee_rate"].to_string(index=False).strip() ) if len(orders) > 0: last_order = orders.iloc[-1:] last_buy_order = last_order[last_order.action == "buy"] last_buy_order = last_buy_order.reset_index(drop=True) if len(last_buy_order) > 0: print(last_buy_order.to_string(index=False)) api = CBPublicAPI() ticker = api.getTicker(market) current_price = ticker[1] market = last_buy_order["market"].to_string(index=False).strip() buy_type = last_buy_order["type"].to_string(index=False).strip() buy_size = round( float(last_buy_order["size"].to_string(index=False).strip()), 8 ) buy_filled = round( float(last_buy_order["filled"].to_string(index=False).strip()), 8, ) buy_fees = round( float(last_buy_order["fees"].to_string(index=False).strip()), 8 )