401 Unauthorized

Hi, I have tried to login to websocket multiple times without success. Tried both live and demo endpoints, and it seems as soon as I open the connection, the server kicks me out This is the response I always get:

a[{"s":401,"i":1,"d":"\"Access is denied\""}]
Received closing frame Some(
    CloseFrame {
        code: Normal,
        reason: "Bye",
    },
)

I know my auth token is good because I had a 200 http response when I got it. The websocket doesn’t even wait for me to send the auth message, it just immediately sends that after the initial “o”.
Here’s the url I used:
wss://md.tradovateapi.com/v1/websocket
Any ideas on what I could be doing wrong?

Are you positive you aren’t sending anything at all? For example, are you sending malformed heartbeats? Meaning, anything other than []?

The server will still be expecting an authorize command and will reject something it interprets as a request.

In my experience, after some time (~20 seconds) it should drop your connection with “Bye” if you send no heartbeats at all.

@Juan_Marquez, make sure you send the auth message as a response to the ‘o’ open frame.

You can follow this guide.

make sure you send your response in this format:

mySocket.send(`authorize\n1\n\${myAccessToken}`)

Remember, the newlines are important.

Hope this helps!

@Alexander @Brady thank you guys still no success. I am not using the provided js library, I am writing my client in rust, which I have done for nearly all crypto exchanges that also use WebSockets and REST.
Here’s my app log to show you guys the messages I am sending and receiving.

2021-12-09T11:04:23.226454-08:00-sending auth token from https://live.tradovateapi.com/v1/auth/accesstokenrequest
2021-12-09T11:04:23.228236-08:00-RequestBuilder { method: POST, url: Url { scheme: “https”, cannot_be_a_base: false, username: “”, password: None, host: Some(Domain(“live.tradovateapi.com”)), port: None, path: “/v1/auth/accesstokenrequest”, query: None, fragment: None }, headers: {“content-type”: “application/json”, “accept”: “application/json”} }
2021-12-09T11:04:23.405773-08:00-Auth Request Status 200 OK
2021-12-09T11:04:23.406893-08:00-connecting to wss://md.tradovateapi.com/v1/websocket
2021-12-09T11:04:23.659681-08:00-Websocket connection status: 101
2021-12-09T11:04:23.659836-08:00-Opening Socket Connection…
2021-12-09T11:04:23.661295-08:00-sent
authorize
1
TY2fZaaEFex4utB[I deleted rest of token for this post]
2021-12-09T11:04:23.743888-08:00-a[{“s”:401,“i”:1,“d”:"“Access is denied”"}]
2021-12-09T11:04:23.744003-08:00-Received closing frame Some(
CloseFrame {
code: Normal,
reason: “Bye”,
},
)
Could this have something to do with 2FA? I received the unknown login email and went through the steps to authorize it, but it still didn’t work

Guys I got. My error was that I had only one \n before my token, and it needed two. :grinning:

1 Like

@Alexander Hi Alex, can you point me to where I may find the tick stream data on the API?
Thank you

Hi @Juan_Marquez,

Probably your best bet for getting tick stream data is to use a Market Data WebSocket and make a request to getChart with the UnderlyingType set to 'Tick'.

You seem like you understand the basics of connecting a WebSocket, so you may want to look at the first and second parts of the Chart Data portion of the Tradovate WebSocket tutorials. Making a request to for a tick chart should fulfill your needs, but it’s a good idea to review both those sections for clarity’s sake.

Edit: Don’t forget to use the market data URL when hooking up the WebSocket - wss://md.tradovateapi.com/v1/websocket

Thank you @Alexander , yes so far working only with market data endpoint. Appreciate your help