-1

I implement secondary indicators through Python, Binance API. However, even though I keep changing the type, it is recognized as "NoneType" and cannot be output to Excel.

def macd(symbol, timeinterval, limit, short, long, signal):
    df = Can.get_fu_coin(symbol, timeinterval, limit)
    # df = klines
    marketprice = "https://fapi.binance.com/fapi/v1/ticker/24hr?symbol="+symbol
    res = requests.get(marketprice)
    data=res.json()
    price=float(data['lastPrice'])
    
    df['open']=df['open'].astype(float)
    df2=df['open'].to_numpy()
    df3=pd.DataFrame(df2, columns=['open'])

    exp1=df3['open'].ewm(span=short, adjust=False).mean()
    exp2=df3['open'].ewm(span=long, adjust=False).mean()
    macd=exp1-exp2
    exp3=macd.ewm(span=signal, adjust=False).mean()        

    e1 = exp1.astype(float)
    e1 = e1.to_numpy()
    e1 = pd.DataFrame(e1, columns = ['exp1'])
    
    e2 = exp2.astype(float)
    e2 = e2.to_numpy()
    e2 = pd.DataFrame(e2, columns = ['exp2'])
    
    e3 = exp3.astype(float)
    e3 = e3.to_numpy()
    e3 = pd.DataFrame(e3, columns = ['exp3'])

    e4 = macd.astype(float)
    e4 = e4.to_numpy()
    e4 = pd.DataFrame(e4, columns = ['macd'])
    
    data = pd.concat([e1, e2, e3, e4], axis=1)
    data1 = data.apply(pd.to_numeric)
    print(data1)

ethusdt_macd = macd('BTCUSDT', '1m', '1500', 12, 26, 9)
ethusdt_macd.to_excel("dd.xlsx")
stuck
  • 1,477
  • 2
  • 14
  • 30
R song
  • 35
  • 5
  • `macd` has no `return`, yet you are assigning this non-existent return value to the variable `ethusdt_macd`. It isn't clear what you expect to happen. Perhaps you think `macd=exp1-exp2` functions as a return? In VBA something like that actually makes sense, but Python isn't VBA. – John Coleman Mar 28 '22 at 15:56
  • add `return data1` right after `print(data1)` – gremur Mar 28 '22 at 16:01
  • I missed the most basic thing. Thank you. – R song Mar 28 '22 at 16:10

1 Answers1

1

In your function, you are returning nothing. So it makes your ethusdt_macd NoneType because it is basically nothing.

So, when you call to_excel method, it cannot find it because ethusdt_macd is None.

You need to return the data1 (or whatever variable you need) in your function.

stuck
  • 1,477
  • 2
  • 14
  • 30