How to get a current share price (Python)

Hi,

I recently started to use Alpaca API, and I need help with some issue:

I’m trying to get the current share of a stock.I succeeded to do it like that:

position_data = (api.get_position(symbol))
current_price = float (positiondata.current_price)

The problem with that, is that I get the prich only if I got open position

Tnd with that, the price is not acuret enough:

symbol_bars = api.get_barset(symbol, 'minute', 1).df.iloc[0]
symbol_price = symbol_bars[symbol]['close']

Someone has an idea how can I get a stock acuret price with out having open position?

1 Like

Thank you for trying! It looks to me what you want to do is [-1] instead of [0] like

api.get_barset(symbol, 'minute', 1).df.iloc[-1]

Thank you for your answer.
I tried your suggestion, but still,the price updating one time in a minute, and untill the next bar is created, the price is not acuret.

use
ss = api.polygon.snapshot(symbol)
lastprice = ss.ticker[‘lastTrade’][‘p’]