1
$\begingroup$

I am trying to connect to a web socket feed of the Gdax. The documentation is here, https://docs.gdax.com/#websocket-feed. There is no account needed and the information is public.

socket = SocketConnect["wss://ws-feed.gdax.com"]

Gives error

During evaluation of In[2]:= SocketConnect::addrspec: The host specification wss://ws-feed.gdax.com is wrong because it has an invalid service specification

Out[2]= $Failed

I am unclear on what is wrong?

$\endgroup$
  • $\begingroup$ I think it is pretty clear what is wrong, the error message is quite clear: Mathematica does not understand the service specification wss, which seems to be a not very common one. The solution is to not specify a service specification but give a specific port to connect to as your own answer shows. An alternative seems to be socket = SocketConnect["ws-feed.gdax.com:443"] which also opens a socket without errors (I have not tried to really use it, though)... $\endgroup$ – Albert Retey Feb 6 '18 at 23:17
2
$\begingroup$

Sorry for the poorly formatted answer, it has been updated.

Since I am very new to web sockets, I didn't even understand the error. After some sleuthing, https://en.wikipedia.org/wiki/WebSocket, web sockets usually run on port 80 or 443.

I tried,

In[1]:= socket = SocketConnect["wss://ws-feed.gdax.com:80"]

During evaluation of In[1]:= SocketConnect::addrspec: The host specification wss://ws-feed.gdax.com:80 is wrong because the port number conflicts with the scheme specification

Out[1]= $Failed

Then after finding web sockets run on port 443 tried that.

In[2]:= socket = SocketConnect["wss://ws-feed.gdax.com:443"]

During evaluation of In[2]:= SocketConnect::addrspec: The host specification wss://ws-feed.gdax.com:443 is wrong because the port number conflicts with the scheme specification

Out[2]= $Failed

Still no success.

This works,

address = HostLookup["wss://ws-feed.gdax.com"]

socket = SocketConnect[{address[[1]], 443}]

OR

address = HostLookup["wss://ws-feed.gdax.com"]

socket = SocketConnect[{address[[2]], 443}]

OR

thanks to the comment,

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

This works as well to non secure

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

After successful connection, for this API, a subscribe command is needed. I am having trouble getting a response. Will post another question.

$\endgroup$
  • $\begingroup$ actually I think that wss (typically port 443, just as https) is the secure version of ws (port 80, just as http). When you just connect directly to the port you might need to handle the encryption in one way or another. It might be quite a lot of low level coding to get this running when Mathematica is not aware of the protocol. Is there a reason not to use the REST API that GDAX provides instead of web-sockets? I think that would be much easier to use from Mathematica... $\endgroup$ – Albert Retey Feb 7 '18 at 14:15
  • $\begingroup$ @AlbertRetey I am currently using the REST API but want to get very fresh data from the web socket. $\endgroup$ – Ray Troy Feb 7 '18 at 18:22
  • $\begingroup$ OK, then good luck :-). Just a recommendation: if you know some of the languages for which there are libraries available, you might want to look into what these are doing and try to translate to Mathematica... $\endgroup$ – Albert Retey Feb 7 '18 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.