Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to hitBTC ws API #1

Closed
jonathonmcmurray opened this issue May 23, 2018 · 2 comments
Closed

Can't connect to hitBTC ws API #1

jonathonmcmurray opened this issue May 23, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@jonathonmcmurray
Copy link
Owner

jonathonmcmurray commented May 23, 2018

Connection fails, with a 400 Bad Request response:

q)\l ws.q
q).ws.VERBOSE:1b                                                //enable ws.q verbose mode
q).hbc.upd:{.hbc.x,:enlist x}                                   //define upd func for hbc
q).hbc.h:.ws.open["wss://api.hitbtc.com/api/2/ws";`.hbc.upd]    //send request
-- REQUEST --
:wss://api.hitbtc.com GET /api/2/ws HTTP/1.1
Host: api.hitbtc.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Origin: api.hitbtc.com


-- RESPONSE --
HTTP/1.1 400 Bad Request
Server: nginx
Date: Wed, 23 May 2018 23:02:53 GMT
Content-Type: text/html
Content-Length: 11
Connection: keep-alive



Reported by @QuickSwitch

@jonathonmcmurray jonathonmcmurray added the bug Something isn't working label May 23, 2018
@jonathonmcmurray jonathonmcmurray self-assigned this May 23, 2018
@jonathonmcmurray
Copy link
Owner Author

Issue was that when opening a WebSocket connection, kdb+ already adds all the necessary headers (Sec-WebSocket-Key, Sec-WebSocket-Version, Sec-WebSocket-Extensions, Upgrade, Connection) so my code was duplicating (some of) these, which led to "bad requests".

In other words, the solution is simply to simplify ws.q much further. With this change:

q).hbc.upd:{show .j.k x}
q).hbc.h:.ws.open["wss://api.hitbtc.com/api/2/ws";`.hbc.upd]
q).hbc.h
-3i
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

Small disadvantage is that the verbose mode I added is less effective, as it won't show the kdb+ added headers on the request.

Will push a commit now that fixes this

@jonathonmcmurray
Copy link
Owner Author

fixed in fd655f1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant