Connecting to websocket issue

I have been able to connect to many similar websockets using this same set up.

here is the domain wss://api.hitbtc.com/api/2/ws

For some reason this one will not connect. I have gotten the domain to respond in wscat, so I’m sure it’s a valid request. 

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ffffff; background-color: #2b66c9}span.s1 {font-variant-ligatures: no-common-ligatures}

Here is what I’ve tried:

  1. Simple connect 

r::($“:ws://api.hitbtc.com”)“GET /api/2/ws HTTP/1.1\r\nHost: api.hitbtc.com\r\n\r\n”;show r`

result: 

'.z.ws undefined [0] show r

  1. Using this library: https://github.com/jonathonmcmurray/ws.q

\l ws.q.hbc.upd:{.hbc.x,:enlist x} .hbc.h:.ws.open["ws://api.hitbtc.com/api/2/ws";.hbc.upd] `

result: 

q).hbc.h0Ni

showing there is no connection where there should be… and here, 

q).ws.wh| hostname callback-| ----------------------- | api.hitbtc.com .hbc.upd

it shows nothing in the h column, which means there is no connection.

Any help would be greatly appreciated! Thanks in advance. 

For wss, you’ll need SSL. Plain ws will not work.

I’d recommend a recent white paper that explains the whole process of wrestling with websockets in q quite well: https://code.kx.com/q/wp/websockets/

So there was a bug in my ws.q library – I didn’t realise that kdb+ already adds a number of WebSocket-related headers to requests to ws:// or wss:// URLs; my library added some of these headers as well, which caused problems on some hosts (I guess any I’d tried before just ignored duplicated headers)<o:p></o:p>

<o:p> </o:p>

I have updated the library so that it now works with the hitbtc example:<o:p></o:p>

<o:p> </o:p>

q).hbc.upd:{show .j.k x};<o:p></o:p>

q).hbc.h:.ws.open[“wss://api.hitbtc.com/api/2/ws”;`.hbc.upd]<o:p></o:p>

q).hbc.h .j.j methodparamsid!(getCurrency;(1#currency)!1#ETH;123)<o:p></o:p>

q)jsonrpc| “2.0”<o:p></o:p>

result | idfullNamecryptopayinEnabledpayinPaymentIdpayinConfirmationspayoutEnabledpayoutIsPaymentIdtransferEnableddelisted`payoutFee!(“ETH”;“Ethereum”;1b;1b;0b;2f;1b;0b;1b;0b;“0.00958”)<o:p></o:p>

id     | 123f<o:p></o:p>

<o:p> </o:p>

GitHub issue:https://github.com/jonathonmcmurray/ws.q/issues/1<o:p></o:p>

<o:p> </o:p>

From: personal-kdbplus@googlegroups.com <personal-kdbplus@googlegroups.com> On Behalf Of Jake
Sent: 23 May 2018 18:48
To: Kdb+ Personal Developers <personal-kdbplus@googlegroups.com>
Subject: [personal kdb+] Connecting to websocket issue<o:p></o:p>

<o:p> </o:p>

I have been able to connect to many similar websockets using this same set up.<o:p></o:p>

<o:p> </o:p>

here is the domain wss://api.hitbtc.com/api/2/ws<o:p></o:p>

<o:p> </o:p>

For some reason this one will not connect. I have gotten the domain to respond in wscat, so I’m sure it’s a valid request. <o:p></o:p>

<o:p> </o:p>

Here is what I’ve tried:<o:p></o:p>

<o:p> </o:p>

  1. Simple connect <o:p></o:p>

<o:p> </o:p>

r::(`$“:ws://api.hitbtc.com”)“GET /api/2/ws HTTP/1.1\r\nHost: api.hitbtc.com\r\n\r\n”;
show r<o:p></o:p>

<o:p> </o:p>

result: <o:p></o:p>

<o:p> </o:p>

'.z.ws undefined
  [0]  show r<o:p></o:p>

<o:p> </o:p>

  1. Using this library: https://github.com/jonathonmcmurray/ws.q<o:p></o:p>

<o:p> </o:p>

\l ws.q
.hbc.upd:{.hbc.x,:enlist x}
.hbc.h:.ws.open[“ws://api.hitbtc.com/api/2/ws”;`.hbc.upd] <o:p></o:p>

<o:p> </o:p>

result: <o:p></o:p>

<o:p> </o:p>

q).hbc.h
0Ni<o:p></o:p>

<o:p> </o:p>

showing there is no connection where there should be… and here, <o:p></o:p>

<o:p> </o:p>

q).ws.w

h hostname       callback
  api.hitbtc.com .hbc.upd<o:p></o:p>

<o:p> </o:p>

it shows nothing in the h column, which means there is no connection.<o:p></o:p>

<o:p> </o:p>

Any help would be greatly appreciated! Thanks in advance. <o:p></o:p>


Submitted via Google Groups