Hello,
Sorry I'm new to websockets.
I want to convert the following Python code to Julia
from websocket import create_connection
import orjson
ws = create_connection("wss://ws.kraken.com/")
message = {"event":"subscribe", "subscription":{"name":"trade"}, "pair":["XBT/USDT","XBT/USD"]}
ws.send(orjson.dumps(message))
while True:
message = ws.recv()
message = orjson.loads(message)
print(message)
if isinstance(message, list):
print(message[2], message[3])
I did using doc
using WebSockets
import JSON
const url = "wss://ws.kraken.com/"
WebSockets.open(url) do ws_client
# msg = "{\"event\":\"subscribe\", \"subscription\":{\"name\":\"trade\"}, \"pair\":[\"XBT/USD\",\"XRP/USD\"]}"
msg = Dict(
"event" => "subscribe",
"subscription" => Dict("name" => "trade"),
"pair" => ["XBT/USDT", "XBT/USD"]
)
msg = JSON.json(msg)
writeguarded(ws_client, msg)
while (true)
data, success = readguarded(ws_client)
if success
println(stderr, ws_client, " received:", String(data))
end
end
end;
but I don't like Julia do statements.
Moreover I would prefer to have separate create_connection, send and recv call like in the Python example but in the Julia example open takes handle function as parameter which is a mix of all this.
How can I achieve that? (ie having a Julia code nearer than the Python code)
Kind regards
Hello,
Sorry I'm new to websockets.
I want to convert the following Python code to Julia
I did using doc
but I don't like Julia
dostatements.Moreover I would prefer to have separate
create_connection,sendandrecvcall like in the Python example but in the Julia exampleopentakes handle function as parameter which is a mix of all this.How can I achieve that? (ie having a Julia code nearer than the Python code)
Kind regards