401 Client Error

Hi, I tried submitting a trade today via the API to my paper account and I received this error:

401 Client Error: Unauthorized for url: https://paper-api.alpaca.markets/v2/orders

I have been designated a PDT in my paper account (and rightly so) but I have 99k in equity there so I shouldn’t be limited. I have the config for the day trading set to “Block on entry” but I think that shouldn’t apply, it just applies to when the rule is checked (if my understanding is correct).

I also regenned my API keys just in case that was the issue.

Edit: I should have included my code, here is what I’m doing that’s getting blocked:

        market_order_data = MarketOrderRequest(
                                symbol='SPY',
                                notional=100,
                                side=OrderSide.BUY,
                                time_in_force=TimeInForce.DAY
                            )

And I tried:

        market_order_data = MarketOrderRequest(
                                symbol='SPY',
                                qty=1,
                                side=OrderSide.BUY,
                                time_in_force=TimeInForce.DAY
                            )

But then I tried in the account GUI and it worked fine so I know it isn’t a block…

@redcoatwright The 401 error you are seeing is most often an authentication issue (ie wrong keys or the wrong base URL). The PDT protections and other restrictions respond with a different error. By the fact that you can perform the order using the UI is a clue that it probably is a API key issue and not an order issue (ie the order works in the UI but doesn’t when using the API).

If you are still getting an error, ensure your API key and secret key is correct.

@Dan_Whitnable_Alpaca hmm but I can still use the quote API to get quotes and I’m using the alpaca-py trading client object so I’m not specifying the URL at all.

If the API keys didn’t work then I assume I wouldn’t be able to get a price quote for a security?

Well it started working :man_shrugging: so let’s nobody speak on this…