Authentication Issue: API Key/Secret Key not working for both websocket (streams) and rest api (bars)

I followed the tutorial videos from ‘Part Time Larry’ to a tee, setting up python scripts to connect to websocket and rest api’s (for paper trading)

part 1 (websocket client) https://www.youtube.com/watch?v=Mv6c_9FqNx4&t=1308s

there’s a part 2 that covers the rest api for ‘v1/bars’, and 3 as well that covers the bta-lib for python.

The websocket tutorial in part 1 worked for me perfectly until it didn’t (auth issue)
The rest api tutorial in part 2 connecting to the bars url didn’t work for me initially, but then miraculously started working out of the blue with no code changes, and at the same time, the websocket streams promptly stopped working out of the blue which had previously been working.

I think there is some problems with the auth tokens not working consistently across these api’s.

I’m for sure I’m not doing anything wrong in my code, and that there is some sort of infrastructure issue, and I don’t know who to contact to get this resolved. Not sure if this is widespread, or if this is just me. My email is kent.fletcher@gmail.com

1 Like

Coding error on my part. My bad. I’m now able to connect to streams websockets.

Kent,
I’m seeing a similar issue. GetBarsAsync was working perfectly until it didn’t. I’ve been working on this for several days. Any insights are greatly appreciated.
John

I’m having a similar issue as well, I’ve been trying to diagnose all weekend. I’m using the paper trading API version 3.8.3 and a call to “.GetBarSetAsync()” returns this:
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
—> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
—> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.
— End of inner exception stack trace —
at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
— End of stack trace from previous location where exception was thrown —
at System.Net.Security.SslStream.ThrowIfExceptional()
at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
at System.Net.Security.SslStream.<>c.b__65_1(IAsyncResult iar)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
— End of stack trace from previous location where exception was thrown —
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
— End of inner exception stack trace —
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Alpaca.Markets.HttpClientExtensions.sendThrottledAsync(HttpClient httpClient, HttpRequestMessage request, CancellationToken cancellationToken, IThrottler throttler) at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpRequestMessage request, CancellationToken cancellationToken, IThrottler throttler) at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpMethod method, Uri endpointUri, CancellationToken cancellationToken, IThrottler throttler) at Alpaca.Markets.HttpClientExtensions.GetAsync[TKeyApi,TValueApi,TKeyJson,TValueJson](HttpClient httpClient, UriBuilder uriBuilder, IEqualityComparer1 comparer, CancellationToken cancellationToken)

My program has been running for several months and had no issues until recently. If anyone knows what this is, assistance would also be greatly appreciated.

Thanks,
Steve

Best I can tell, any /v1/ call is throwing these errors. /v2/ calls are working fine. My guess is the underlying /v1/ code needs to be rewritten to accommodate new security requirements. Alpaca support is underwhelming. While I love the Alpaca concept and ease of programming, the implementation leaves much to be desired. For what it’s worth, an internet search surfaced the following code modifications (which did not work for me) -

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
ServicePointManager.CheckCertificateRevocationList = false;

Be sure to place this code ahead of API call.

I also tried SDK 3.9 rc3 Beta available at NuGet. Did not help.