alpacahq / alpaca-trade-api-csharp

C# SDK for Alpaca Trade API https://docs.alpaca.markets/
Apache License 2.0
243 stars 76 forks source link

[QUESTION]: Sample code provided returns "Unauthorides Request" when trying to use Functions (eg GetClockAsync) #436

Closed DomDom3333 closed 2 years ago

DomDom3333 commented 2 years ago

Is there an existing issue for this?

What is your question?

Hi. Not sure if this qualifies as a bug or not since i can't find other people having this issue. When i copy the Sample code from the front page of this repo and provide it with ID and Secret, i get the following error when trying to call client.GetClockAsync():

Alpaca.Markets.RestClientErrorException: request is not authorized
   at Alpaca.Markets.HttpResponseMethodExtensions.DeserializeAsync[TApi,TJson](HttpResponseMessage response)
   at Alpaca.Markets.HttpResponseMethodExtensions.DeserializeAsync[TApi,TJson](HttpResponseMessage response)
   at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpMessageInvoker httpClient, HttpRequestMessage request, CancellationToken cancellationToken)
   at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpMessageInvoker httpClient, HttpMethod method, Uri endpointUri, CancellationToken cancellationToken)
   at AlpacaExample.Program.Main() in /home/dominik/Documents/GitHub/TradeBot/Program.cs:line 20
   at AlpacaExample.Program.<Main>()

I've tried the Envirometns.Paper as well as the Live version and both provide me with that error. I've also tried a few other functions to see if it was just the clock but all other Get functions i have tried result in the same error.

I've tried this on 2 different computers both running Ubuntu based Linux and using Jetbrains Rider as the IDE.

Thanks for any and all help on this.

Merry Christmas Dominik

Anything else?

No response

DomDom3333 commented 2 years ago

Ok. Apparently im stupid. I used the OAuthApps Id and secret and not the API ones. I am now curious what the OAuth Apps are for then but hey. At least it seems to be working now.

OlegRa commented 2 years ago

@DomDom3333 The OAuth is useful in case if you make some apps available for 3rd parties. Or if you don't want to share your secret id and key via code. See more information in Alpaca documentation. In .NET SDK you just replace the SecretKey class with the OAuthKey class and all other code will be the same.

tdhatcher commented 2 years ago

@DomDom3333 @OlegRa I've shared my unpleasant experience as well. #507

https://github.com/alpacahq/alpaca-trade-api-csharp/issues/507