alpacahq / Alpaca-API

The Alpaca API is a developer interface for trading operations and market data reception through the Alpaca platform.
https://alpaca.markets/
141 stars 13 forks source link

Last Quote 404 Error Using Requests.Get On Weekend? #125

Closed windowshopr closed 4 years ago

windowshopr commented 4 years ago

Hey,

Just wondering why I'm getting a 404 response when trying to request the "last quote" for AAPL. Is it not accessible on the weekend, or is there something wrong with my syntax? I'm using paper trading. My code looks like this:

base_url = "https://paper-api.alpaca.markets"

quotes_url = "{}/v1/last_quote/stocks/".format(base_url) # ticker defined later

api_key = "API_GOES_HERE"
secret_key = "SECRET_KEY_GOES_HERE"

headers = {"APCA-API-KEY-ID": api_key, "APCA-API-SECRET-KEY": secret_key}

def get_latest_bid_ask_prices(ticker):

    r = requests.get(quotes_url + str(ticker), headers=headers)
    results = json.loads(r.content)

    print(results['askprice'])
    print(results['bidprice'])

    return

get_latest_bid_ask_prices("AAPL")

404 means the ticker is unavailable? Thanks!

windowshopr commented 4 years ago

Nevermind, I was using the wrong baseurl. Baseurl should have read:

quotes_base_url = "https://data.alpaca.markets/v1"