cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to websocket issue

Jake1
New Contributor
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. 

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


2. 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.h
0Ni

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

q).ws.w
h
| 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. 
2 REPLIES 2

Flying
New Contributor III
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/

Jonathon_McMurr
New Contributor

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)

 

I have updated the library so that it now works with the hitbtc example:

 

q).hbc.upd:{show .j.k x};

q).hbc.h:.ws.open["wss://api.hitbtc.com/api/2/ws";`.hbc.upd]

q).hbc.h .j.j `method`params`id!(`getCurrency;(1#`currency)!1#`ETH;123)

q)jsonrpc| "2.0"

result | `id`fullName`crypto`payinEnabled`payinPaymentId`payinConfirmations`payoutEnabled`payoutIsPaymentId`transferEnabled`delisted`payoutFee!("ETH";"Ethereum";1b;1b;0b;2f;1b;0b;1b;0b;"0.00958")

id     | 123f

 

GitHub issue: https://github.com/jonathonmcmurray/ws.q/issues/1

 

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

 

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. 

 

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

 

 

\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.h
0Ni

 

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

 

q).ws.w
h
| 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. 

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.


This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of AquaQ Analytics may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.