I am trying to connect to a web socket feed of Gdax. The documentation is here, https://docs.gdax.com/#websocket-feed. There is no account needed and the information is public. I have successfully connected see this post, SocketConnect not connecting to web socket address

After connection, a subscription message needs to be sent. My json looks exactly like the documentation but not successful.

socket = SocketConnect["ws-feed.gdax.com:80"];

json = ExportString[<|"type" -> "subcribe", 
"product_ids" -> {"ETH-USD", "ETH-EUR"}, 
"channels" -> {"level2", 
  "heartbeat", <|"name" -> "ticker", 
   "product_ids" -> {"ETH-BTC", "ETH-USD"}|>}|>, "JSON"];

WriteString[socket, json]

result = ReadString[socket]

Yields an error message.

HTTP/1.1 400 Bad Request

Date: Wed, 07 Feb 2018 18:14:59 GMT

Content-Type: text/html

Content-Length: 177

Connection: close

Server: cloudflare-nginx



<head><title>400 Bad Request</title></head>

<body bgcolor=\"white\">

<center><h1>400 Bad Request</h1></center>




I also tried this as a HTTPRequest and returns same error message. I have also tried the request as a PUT to no avail.

request = HTTPRequest[<|"Body" -> json, Method -> "GET"|>];

WriteString[socket, request]

result = ReadString[socket]
  • 1
    $\begingroup$ To establish a websocket connection, you must complement the opening handshake first. This is not the same thing with socket and not implemented as built-in function, so you'll have to write it yourself (generally by following the spec). FYI there are utilities like websocketd exist. Combining with process functions, they might be a big time saver. $\endgroup$
    – Silvia
    Commented Feb 20, 2018 at 6:59
  • $\begingroup$ @Silvia thank you for the help. I would have just assumed, like every other web socket package out there, it handles the handshake in the background. I will put in a feature request. $\endgroup$
    – Ray Troy
    Commented Feb 20, 2018 at 14:23
  • $\begingroup$ You're welcome! I think the socket ability in current version of Mathematica is intended for a more general, low level purpose. Websocket on the other hand is a higher level application. It would be very nice if you come back with further information from the feature request! :D $\endgroup$
    – Silvia
    Commented Feb 21, 2018 at 4:56
  • $\begingroup$ Did you find anything new? I also have some issues with SocketConnect (see 166571). $\endgroup$
    – anderstood
    Commented Feb 26, 2018 at 22:24
  • $\begingroup$ No. I have emailed Wolfram and they "...forwarded an issue report to our developers with the information you provided. " So I wouldn't expect anything soon. $\endgroup$
    – Ray Troy
    Commented Feb 28, 2018 at 19:46


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.