Error reading last price for WAVES/BTC

I’m using the pyWaves library to connect to the waves blockchain and read prices.

when I use the following commands in the main script it works perfectly:

WAVES_BTC = pw.AssetPair(pw.WAVES, pw.BTC)
last_trade_price = WAVES_BTC.last()
log(" Last Trade Price : %s" % last_trade_price)

but if I try to use it in a defined function, like this:

def get_last_price():
WAVES_BTC = pw.AssetPair(pw.WAVES, pw.BTC)
last_trade_price = WAVES_BTC.last()
log(" Last Trade Price : %s" % last_trade_price)
return last_trade_price

and I call the function anywhere in the main script with this:

last_price = get_last_price()
log(" Last Trade Price : %s" % last_price)

it gives this error:

return str(self.ticker()[‘24h_close’])
KeyError: ‘24h_close’

And what is your question?