How do you find the current price of a stock?(Python)

How do you find the current price of a stock? I have been trying to find an answer on the docs, but it isn’t very user friendly. I want to find the current price, not the open or close price.

Its going to be hard to answer because you need to be more specific and the documentation is terrible. There is no ‘current’ price in stock trading. So that maybe some of the problem.
There is the current BID and ASK and there is the Last Trade. Anyone of those might be what you want for current.

This page in the docs may help. This is a query for Latest quote that might be what you want.

1 Like

Let’s say it is 10 am est, and I want to check the current price of the stock. Is there a way to do that? Or do I have to use last quote?

I think you are you wanting Last Trade - that is the last price the stock traded at. It is not the ‘Current’ price. If you were to execute a market trade you are going to get the last quote - ASK price - which could be significantly different. Hope that helps.

2 Likes

@Brian_Rowe and @ineedhelp
Might seem like a basic question but is the “current” price (that number we see when we google a ticker symbol) just an average price that’s between the bid price and ask price? I’m still learning a ton about the API and the document you shared doesn’t explain the outputs well. I had to google the difference between quotes and trades and I think this is what the original question could be answered with:

#In python if you were looking for the latest info on the Robinhood stock
api.get_last_quote(‘HOOD’)

#The output looks like this:
Quote({ ‘askexchange’: 15,
‘askprice’: 51.22,
‘asksize’: 1,
‘bidexchange’: 15,
‘bidprice’: 50.25,
‘bidsize’: 1,
‘timestamp’: 1628708348916325270})

I appreciate any help or insight you can give me!

3 Likes

Please don’t ask a question on my question.

… i thought i was helping you

1 Like

usually the price you see in a ticker is the Last traded price.

1 Like

Hello, I think you could use a tutorial on youtube by parttimelarry on using websockets to stream real time data. It worked for me, so maybe it’ll satisfy your needs also. Let me know if that was what you were looking for

1 Like

Can you share more on that? I am trying to use real time data to retrieve latest trade price, and I am struggling with it.

1 Like

Seems like there is no way to get current stock price when the market is closed

Hello,

You can use FMP data API, and they have excel add-on as well very easy to use and track stock prices

This should help guide you:But you need to research or know the difference between bid/ask quotes, close prices, and trade prices. They all seem the same but they’re not exactly the same thing.

live_api = tradeapi.REST(LIVE_API_KEY, LIVE_SECRET_KEY, LIVE_BASE_URL, api_version='v2')


def get_alpaca_bid_ask(symbol, global_variables=True):
    global no_quote_available_symbols

    try:
        # Get the bid and ask prices for the symbol
        quote = live_api.get_latest_quote(symbol.replace('-', '.'))
        bid_price = quote.bp
        ask_price = quote.ap

    except Exception as e:
        no_quote_available_symbols.append(symbol)
        if 'no quote found for' in str(e):
            logging.warning(f"{symbol}: get_alpaca_bid_ask: Error for symbol: {e}")
        else:
            logging.warning(f"{symbol}: get_alpaca_bid_ask: Error retrieving bid/ask prices: {e}")
        return [None, None]

    if bid_price == 0 or ask_price == 0:
        no_quote_available_symbols.append(symbol)
        logging.warning(f"{symbol}: get_alpaca_bid_ask: Bid or ask price is zero")
        return [None, None]

    logging.debug(f'{symbol}: get_alpaca_bid_ask: bid: {bid_price} ask: {ask_price}')

    if global_variables:
        update_global_variables(symbol, ask_price, bid_price)

    return [bid_price, ask_price]

or this

def fetch_historical_data(symbol, start_date, end_date, timeframe='1Min'):
    data = []

    # print(f'input data: {symbol}, {start_date}, {end_date}, {timeframe}')

    for bar in live_api.get_bars(symbol, start=start_date, end=end_date, limit=10000, timeframe=timeframe):
        data.append({
            'c': bar.c,
            'h': bar.h,
            'l': bar.l,
            'n': bar.n,
            'o': bar.o,
            't': bar.t,
            'v': bar.v,
            'vw': bar.vw
        })

    historical_data = pd.DataFrame(data)

    # print('historical data')
    # print(historical_data.tail(20))

    historical_data['t'] = pd.to_datetime(historical_data['t'])
    historical_data.set_index('t', inplace=True)

    # print(historical_data.head(20))
    # print(historical_data.tail(20))

    return historical_data