I use the following code to access the Binance API, pull the last 200 klines for BTC/USDT and then attempt to produce the EMA 50 as a column in a dataframe:
client = Client('PUBLIC_KEY', 'PRIVATE_KEY')
client.API_URL = 'https://testnet.binance.vision/api'
#obtain historical data for indicator calculation
klines = client.get_historical_klines('BTCUSDT', '1d', limit=200)
klines = np.array(klines)
#convert bars to df
df = pd.DataFrame(klines.reshape(-1,12),dtype=float, columns = ('Open Time',
'Open',
'High',
'Low',
'Close',
'Volume',
'Close time',
'Quote asset volume',
'Number of trades',
'Taker buy base asset volume',
'Taker buy quote asset volume',
'Ignore'))
df['Open Time'] = pd.to_datetime(df['Open Time'], unit='ms')
#run indicators
df['ema50'] = ta.ema(df['Close'], length=50)
Despite having more than enough values to calculate the EMA, I am getting all None values in the resulting dataframe column. Can anybody tell me what I’m doing wrong?