alpacahq / alpaca-trade-api-go

Go client for Alpaca's trade API
Apache License 2.0
325 stars 93 forks source link

Marketdata DefaultClient authentication does not seem to work #276

Open LeventeLantos opened 7 months ago

LeventeLantos commented 7 months ago

marketdata DefaultClient authentication does not seem to work, I have this piece code: `func printCurrentPrice(symbol string) { lastQuote, err := marketdata.GetLatestQuote(symbol, marketdata.GetLatestQuoteRequest{ Feed: marketdata.SIP, Currency: "USD", }) if err != nil { fmt.Printf("Failed to get last quote for %s: %s\n", symbol, err) return }

fmt.Printf("The last quoted price for %s is $%.2f\n", symbol, lastQuote.AskPrice)

}`

This will simple return: `$ go run main.go Failed to get last quote for AAPL:

403 Forbidden

403 Forbidden


nginx

(HTTP 403) `

gnvk commented 7 months ago

Have you set the environment variables as described here?

princefishthrower commented 5 months ago

@LeventeLantos - did you ever figure this out? I'm running into the same issue, even when APCA_API_KEY_ID and APCA_API_SECRET_KEY exist in my env.

princefishthrower commented 5 months ago

Figured this out, the marketdata package has an identical NewClient function and ClientOpts just as in the alpaca package:

client := marketdata.NewClient(marketdata.ClientOpts{
    APIKey:    os.Getenv("APCA_API_KEY_ID"),
    APISecret: os.Getenv("APCA_API_SECRET_KEY"),
})

client.GetBars(...)
// etc.