Пример #1
0
        df_markets["volume"] = df_markets["volume"].astype(float).round(
            0).astype(int)
        df_markets.sort_values(by=["market"], ascending=True, inplace=True)
        df_markets.set_index("market", inplace=True)

        print("Processing, please wait...")

        ROW = 1
        for market, data in df_markets.T.iteritems():
            print(
                f"[{ROW}/{len(df_markets)}] {market} {round((ROW/len(df_markets))*100, 2)}%"
            )
            try:
                if int(data["volume"]) > 0:
                    ta = TechnicalAnalysis(
                        api.getHistoricalData(market, GRANULARITY, None))
                    ta.addEMA(12)
                    ta.addEMA(26)
                    ta.addATR(72)
                    df_1h = ta.getDataFrame()
                    df_1h["ema12ltema26"] = df_1h.ema12 < df_1h.ema26
                    df_1h_last = df_1h.tail(1)

                    # volatility over the last 72 hours
                    df_markets.at[market,
                                  "atr72"] = float(df_1h_last[["atr72"
                                                               ]].values[0][0])
                    df_markets["atr72_pcnt"] = (df_markets["atr72"] /
                                                df_markets["price"] *
                                                100).round(2)
                    df_markets.at[market, "buy_next"] = df_1h_last[
Пример #2
0
    def technical_analysis(exchange: str, market: str, g1, g2, g3) -> str:
        if exchange == 'binance':
            if not isBinanceMarketValid(market):
                return f"""
                {header()}
                <h4>Invalid Market!</h4>

                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                <a class="text-dark" href='/{exchange}'><button class="btn btn-primary me-md-2" type="button">Go Back</button></a>
                </div>
                {footer()}
                """
        elif exchange == 'coinbasepro':
            if not isCoinbaseMarketValid(market):
                return f"""
                {header()}
                <h4>Invalid Market!</h4>

                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                <a class="text-dark" href='/{exchange}'><button class="btn btn-primary me-md-2" type="button">Go Back</button></a>
                </div>
                {footer()}
                """
        else:
            return "Invalid Exchange!"

        if exchange == 'binance':
            api = BPublicAPI()
        if exchange == 'coinbasepro':
            api = CPublicAPI()
        ticker = api.getTicker(market)

        ta = TechnicalAnalysis(api.getHistoricalData(market, g1, None))
        ta.addAll()
        df_15m = ta.getDataFrame()
        df_15m_last = df_15m.tail(1)

        ta = TechnicalAnalysis(api.getHistoricalData(market, g2, None))
        ta.addAll()
        df_1h = ta.getDataFrame()
        df_1h_last = df_1h.tail(1)

        ta = TechnicalAnalysis(api.getHistoricalData(market, g3, None))
        ta.addAll()
        df_6h = ta.getDataFrame()
        df_6h_last = df_6h.tail(1)

        if exchange == 'binance':
            exchange_name = 'Binance'
        elif exchange == 'coinbasepro':
            exchange_name = 'Coinbase Pro'

        rsi14_15m_class = 'table-normal'
        rsi14_15m_desc = 'Uneventful'
        if df_15m_last['rsi14'].values[0] > 70:
            rsi14_15m_class = 'table-danger'
            rsi14_15m_desc = 'Overbought (Sell)'
        elif df_15m_last['rsi14'].values[0] < 30:
            rsi14_15m_class = 'table-success'
            rsi14_15m_desc = 'Oversold (Buy)'

        rsi14_1h_class = 'table-normal'
        rsi14_1h_desc = 'Uneventful'
        if df_1h_last['rsi14'].values[0] > 70:
            rsi14_1h_class = 'table-danger'
            rsi14_1h_desc = 'Overbought (Sell)'
        elif df_1h_last['rsi14'].values[0] < 30:
            rsi14_1h_class = 'table-success'
            rsi14_1h_desc = 'Oversold (Buy)'

        rsi14_6h_class = 'table-normal'
        rsi14_6h_desc = 'Uneventful'
        if df_6h_last['rsi14'].values[0] > 70:
            rsi14_6h_class = 'table-danger'
            rsi14_6h_desc = 'Overbought (Sell)'
        elif df_6h_last['rsi14'].values[0] < 30:
            rsi14_6h_class = 'table-success'
            rsi14_6h_desc = 'Oversold (Buy)'

        stochrsi14_15m_class = 'table-normal'
        stochrsi14_15m_desc = 'Uneventful'
        if df_6h_last['stochrsi14'].values[0] > 0.8:
            stochrsi14_6h_class = 'table-danger'
            stochrsi14_6h_desc = 'Overbought (Sell)'
        elif df_6h_last['stochrsi14'].values[0] < 0.2:
            stochrsi14_6h_class = 'table-success'
            stochrsi14_6h_desc = 'Oversold (Buy)'

        stochrsi14_1h_class = 'table-normal'
        stochrsi14_1h_desc = 'Uneventful'
        if df_1h_last['stochrsi14'].values[0] > 0.8:
            stochrsi14_1h_class = 'table-danger'
            stochrsi14_1h_desc = 'Overbought (Sell)'
        elif df_1h_last['stochrsi14'].values[0] < 0.2:
            stochrsi14_1h_class = 'table-success'
            stochrsi14_1h_desc = 'Oversold (Buy)'

        stochrsi14_6h_class = 'table-normal'
        stochrsi14_6h_desc = 'Uneventful'
        if df_6h_last['stochrsi14'].values[0] > 0.8:
            stochrsi14_6h_class = 'table-danger'
            stochrsi14_6h_desc = 'Overbought (Sell)'
        elif df_6h_last['stochrsi14'].values[0] < 0.2:
            stochrsi14_6h_class = 'table-success'
            stochrsi14_6h_desc = 'Oversold (Buy)'

        williamsr14_15m_class = 'table-normal'
        williamsr14_15m_desc = 'Uneventful'
        if df_15m_last['williamsr14'].values[0] > -20:
            williamsr14_15m_class = 'table-danger'
            williamsr14_15m_desc = 'Overbought (Sell)'
        elif df_15m_last['williamsr14'].values[0] < -80:
            williamsr14_15m_class = 'table-success'
            williamsr14_15m_desc = 'Oversold (Buy)'

        williamsr14_1h_class = 'table-normal'
        williamsr14_1h_desc = 'Uneventful'
        if df_1h_last['williamsr14'].values[0] > -20:
            williamsr14_1h_class = 'table-danger'
            williamsr14_1h_desc = 'Overbought (Sell)'
        elif df_1h_last['williamsr14'].values[0] < -80:
            williamsr14_1h_class = 'table-success'
            williamsr14_1h_desc = 'Oversold (Buy)'

        williamsr14_6h_class = 'table-normal'
        williamsr14_6h_desc = 'Uneventful'
        if df_6h_last['williamsr14'].values[0] > -20:
            williamsr14_6h_class = 'table-danger'
            williamsr14_6h_desc = 'Overbought (Sell)'
        elif df_6h_last['williamsr14'].values[0] < -80:
            williamsr14_6h_class = 'table-success'
            williamsr14_6h_desc = 'Oversold (Buy)'

        adx14_15m_class = 'table-normal'
        adx14_15m_desc = 'Normal Trend'
        if df_15m_last['adx14'].values[0] > 25 and df_15m_last['ema12'].values[0] >= df_15m_last['ema26'].values[0]:
            adx14_15m_class = 'table-success'
            adx14_15m_desc = 'Strong Trend Up'
        elif df_15m_last['adx14'].values[0] > 25 and df_15m_last['ema12'].values[0] < df_15m_last['ema26'].values[0]:
            adx14_15m_class = 'table-danger'
            adx14_15m_desc = 'Strong Trend Down'
        elif df_15m_last['adx14'].values[0] < 20 and df_15m_last['ema12'].values[0] >= df_15m_last['ema26'].values[0]:
            adx14_15m_class = 'table-success'
            adx14_15m_desc = 'Weak Trend Up'
        elif df_15m_last['adx14'].values[0] < 20 and df_15m_last['ema12'].values[0] < df_15m_last['ema26'].values[0]:
            adx14_15m_class = 'table-danger'
            adx14_15m_desc = 'Weak Trend Up'

        adx14_1h_class = 'table-normal'
        adx14_1h_desc = 'Normal Trend'
        if df_1h_last['adx14'].values[0] > 25 and df_1h_last['ema12'].values[0] >= df_1h_last['ema26'].values[0]:
            adx14_1h_class = 'table-success'
            adx14_1h_desc = 'Strong Trend Up'
        elif df_1h_last['adx14'].values[0] > 25 and df_1h_last['ema12'].values[0] < df_1h_last['ema26'].values[0]:
            adx14_1h_class = 'table-danger'
            adx14_1h_desc = 'Strong Trend Down'
        elif df_1h_last['adx14'].values[0] < 20 and df_1h_last['ema12'].values[0] >= df_1h_last['ema26'].values[0]:
            adx14_1h_class = 'table-success'
            adx14_1h_desc = 'Weak Trend Up'
        elif df_1h_last['adx14'].values[0] < 20 and df_1h_last['ema12'].values[0] < df_1h_last['ema26'].values[0]:
            adx14_1h_class = 'table-danger'
            adx14_1h_desc = 'Weak Trend Up'

        adx14_6h_class = 'table-normal'
        adx14_6h_desc = 'Normal Trend'
        if df_6h_last['adx14'].values[0] > 25 and df_6h_last['ema12'].values[0] >= df_6h_last['ema26'].values[0]:
            adx14_6h_class = 'table-success'
            adx14_6h_desc = 'Strong Trend Up'
        elif df_6h_last['adx14'].values[0] > 25 and df_6h_last['ema12'].values[0] < df_6h_last['ema26'].values[0]:
            adx14_6h_class = 'table-danger'
            adx14_6h_desc = 'Strong Trend Down'
        elif df_6h_last['adx14'].values[0] < 20 and df_6h_last['ema12'].values[0] >= df_6h_last['ema26'].values[0]:
            adx14_6h_class = 'table-success'
            adx14_6h_desc = 'Weak Trend Up'
        elif df_6h_last['adx14'].values[0] < 20 and df_6h_last['ema12'].values[0] < df_6h_last['ema26'].values[0]:
            adx14_6h_class = 'table-danger'
            adx14_6h_desc = 'Weak Trend Up'

        def arima_predictions(even_rows: bool = True):
            results_ARIMA = ta.seasonalARIMAModel()
            start_date = df_1h.last_valid_index()
            end_date = start_date + datetime.timedelta(days=3)
            arima_pred = results_ARIMA.predict(
                start=str(start_date), end=str(end_date), dynamic=True
            )

            if even_rows:
                arima_pred_rows = arima_pred.iloc[::2]
            else:
                arima_pred_rows = arima_pred.iloc[1::2]

            html = ""
            for index, pred in arima_pred_rows.iteritems():
                html += f"""
                <tbody>
                    <tr class={'table-success' if pred >= ticker[1] else 'table-danger'}>
                        <td>{index}</td>
                        <td>{pred}</td>
                    </tr>
                </tbody>
                """

            return html

        return f"""