示例#1
0
    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()
示例#3
0
    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 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
示例#5
0
    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 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
示例#8
0
    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
示例#9
0
    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
示例#11
0
        def markets():
            html = ""

            api = CPublicAPI()
            resp = api.getMarkets24HrStats()
            for market in resp:
                stats_30day_volume = 0
                if "stats_30day" in resp[market]:
                    if "volume" in resp[market]["stats_30day"]:
                        stats_30day_volume = resp[market]["stats_30day"]["volume"]

                stats_24hour_open = 0
                stats_24hour_high = 0
                stats_24hour_close = 0
                stats_24hour_low = 0
                stats_24hour_volume = 0
                if "stats_24hour" in resp[market]:
                    if "open" in resp[market]["stats_24hour"]:
                        stats_24hour_open = resp[market]["stats_24hour"]["open"]
                    if "high" in resp[market]["stats_24hour"]:
                        stats_24hour_high = resp[market]["stats_24hour"]["high"]
                    if "last" in resp[market]["stats_24hour"]:
                        stats_24hour_close = resp[market]["stats_24hour"]["last"]
                    if "low" in resp[market]["stats_24hour"]:
                        stats_24hour_low = resp[market]["stats_24hour"]["low"]
                    if "volume" in resp[market]["stats_24hour"]:
                        stats_24hour_volume = resp[market]["stats_24hour"]["volume"]

                if stats_24hour_close > stats_24hour_open:
                    html += f"""
                    <tr>
                        <th class="table-success" scope="row"><a class="text-dark" href="/coinbasepro/{market}">{market}</a></th>
                        <td class="table-success" style="border-left: 1px solid #000;">{stats_30day_volume}</td>
                        <td class="table-success" style="border-left: 1px solid #000;">{stats_24hour_open}</td>
                        <td class="table-success">{stats_24hour_high}</td>
                        <td class="table-success">{stats_24hour_close}</td>
                        <td class="table-success">{stats_24hour_low}</td>
                        <td class="table-success">{stats_24hour_volume}</td>
                    </tr>
                    """
                elif stats_24hour_close < stats_24hour_open:
                    html += f"""
                    <tr>
                        <th class="table-danger" scope="row"><a class="text-dark" href="/coinbasepro/{market}">{market}</a></th>
                        <td class="table-danger" style="border-left: 1px solid #000;">{stats_30day_volume}</td>
                        <td class="table-danger" style="border-left: 1px solid #000;">{stats_24hour_open}</td>
                        <td class="table-danger">{stats_24hour_high}</td>
                        <td class="table-danger">{stats_24hour_close}</td>
                        <td class="table-danger">{stats_24hour_low}</td>
                        <td class="table-danger">{stats_24hour_volume}</td>
                    </tr>
                    """
                else:
                    html += f"""
                    <tr>
                        <th scope="row"><a class="text-dark" href="/coinbasepro/{market}">{market}</a></th>
                        <td style="border-left: 1px solid #000;">{stats_30day_volume}</td>
                        <td style="border-left: 1px solid #000;">{stats_24hour_open}</td>
                        <td>{stats_24hour_high}</td>
                        <td>{stats_24hour_close}</td>
                        <td>{stats_24hour_low}</td>
                        <td>{stats_24hour_volume}</td>
                    </tr>
                    """

            return html
def test_instantiate_publicapi_without_error():
    exchange = PublicAPI()
    assert type(exchange) is PublicAPI
示例#13
0
from models.PyCryptoBot import PyCryptoBot
from models.exchange.binance import PublicAPI as BPublicAPI
from models.exchange.coinbase_pro import PublicAPI as CBPublicAPI

# Coinbase Pro time
api = CBPublicAPI()
ts = api.getTime()
print (ts)

app = PyCryptoBot(exchange='coinbasepro')
ts = api.getTime()
print (ts)

# Binance Live time
api = BPublicAPI()
ts = api.getTime()
print (ts)

app = PyCryptoBot(exchange='binance')
ts = api.getTime()
print (ts)