0

I changed pd.ewm into pd.DataFrame.ewm just like others says (The original was pd.ewm(ups.span=RSI_N)[-1] ) . But it follows me an another problem. What did I did wrong ? Does anybody know what is happening?

I've edited into full error message

from binance.client import Client
import numpy as np
import pandas as pd
import smtplib

API_KEY = 'jHH6LNaSsdenA6xdJLRN9LVngY9KgrZ4dTzdk8685D6oquaVovY1PSuHgeQRCal5'
API_SECRET = 'DzJjJFkjppeSPQYBZg66Y2taIDr25ENfkI0G0SrxsqePYtdJX9cnxqdAHF0I8ocjS'
user = '[email protected]'
passwd = 'asdfaasdf!!'

client = Client(API_KEY, API_SECRET)

# against ETH
SYMBOLS = ('ADA', 'ADX', 'BAT', 'BCC', 'DASH', 'EOS', 'IOTA',

        'LTC', 'NEO', 'OMG', 'STORJ', 'XLM', 'NANO', 'XRP', 'XVG', 'ZEC')
RSI_N = 14
RSI_THRESHOLD = 8
RUN_INTERVAL_MINS = 30

def send_email(rsi_values):
    if len(rsi_values) > 0:
        message = '\n'.join('{0:>8} {1:.2f}'.format(symbol, rsi) for (symbol, rsi) in rsi_values)
        email_text = 'From: {0}\nTo: {1}\nSubject: Stock Recommendations\n\n{2}'.format(user, user, message)

        try:
            server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
            server.ehlo()
            server.login(user, passwd)
            server.sendmail(user, user, email_text)
            server.close()
        except:
            pass

while True:
    rsi_values = []
    for SYMBOL in SYMBOLS:
        klines = client.get_historical_klines(SYMBOL + 'ETH', Client.KLINE_INTERVAL_30MINUTE, '{} hours ago UTC'.format((RSI_N + 3) // 2))
        closings = np.asarray(klines, dtype=np.float)[-RSI_N - 1:, 4]
        diffs = np.diff(closings)
        ups = diffs.clip(min=0)
        downs = diffs.clip(max=0)
        ups_avg = pd.DataFrame.ewm(ups, span=RSI_N).mean()
        downs_avg = -pd.DataFrame.ewm(downs, span=RSI_N).mean()
        rs = ups_avg / downs_avg
        rsi = 100 - 100 / (1 + rs)
        rsi_values.append((SYMBOL, rsi))

    print('\n'.join('{0:>8} {1:.2f}'.format(symbol, rsi) for (symbol, rsi) in rsi_values))
    rsi_values = list(filter(lambda x: x[1] < RSI_THRESHOLD, rsi_values))
    send_email(rsi_values)

error:

      Traceback (most recent call last):
  File "C:\Users\심현규\PycharmProjects\FINALPROJECT\autowork.py", line 43, in <module>
    ups_avg = pd.DataFrame.ewm(ups, span=RSI_N).mean()
  File "C:\Users\심현규\PycharmProjects\FINALPROJECT\venv\lib\site-packages\pandas\core\generic.py", line 11282, i
n ewm
    axis = self._get_axis_number(axis)
AttributeError: 'numpy.ndarray' object has no attribute '_get_axis_number'
4
  • Please show full error message. Commented Apr 22, 2021 at 6:38
  • 1
    Sorry. I've edited it. Commented Apr 22, 2021 at 6:41
  • 1
    I hope those are not real secrets and api keys. If they are, you should immediately revoke those keys Commented Apr 22, 2021 at 6:43
  • I uploaded it cause I hope others to test it.. I edited it Commented Apr 22, 2021 at 6:44

1 Answer 1

1

You are never actually converting ups to a DataFrame. The DataFrame.ewm() method should be applied to an instance of pandas dataframe or a pandas Series (as per Mustafa's comment).

So this should hopefully fix things:

while True:
    rsi_values = []
    for SYMBOL in SYMBOLS:
        klines = client.get_historical_klines(SYMBOL + 'ETH', Client.KLINE_INTERVAL_30MINUTE, '{} hours ago UTC'.format((RSI_N + 3) // 2))
        closings = np.asarray(klines, dtype=np.float)[-RSI_N - 1:, 4]
        diffs = np.diff(closings)
        ups = diffs.clip(min=0)
        ups = pd.DataFrame(ups)   # Convert to a dataframe    
        downs = diffs.clip(max=0)
        ups_avg = ups.ewm(span=RSI_N).mean()   # Now perform ewm on the dataframe

Hope this helps. There might be similar issues with other variables too.

Sign up to request clarification or add additional context in comments.

14 Comments

++ but pd.DataFrame.ewm also accepts pd.Series
@MustafaAydın, no, there's a separate method - pd.Series.ewm() for series.
Yes but ewm of both resolve to NDFrame.ewm, the parent of them.
Oh yes, I've amended the answer as per your comment.
I have another issue after changing the code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.