bhftbootcamp / .github

0 stars 0 forks source link

Implement a LibWebsockets Julia wrapper #3

Open gryumov opened 6 months ago

gryumov commented 6 months ago

Implement a LibWebsockets Julia wrapper

Description

Create a convenient Julia wrapper around LibWebsockets library.

Requirements

Documentation

Tests

Suggested API

using Serde
using LibWebsockets

LibWebsockets.open(
    "wss://stream.binance.com:9443/stream?streams=adausdt@depth20@100ms/btcusdt@depth20@100ms",
    headers = [
        "sec-websocket-extensions" => "permessage-deflate"
    ],
    read_timeout = 60,
) do connection
    LibWebsockets.send(connection, "Hello Binance!")

    while isopen(connection)
        data = LibWebsockets.recv(connection)
        data |> Serde.parse_json |> println
    end
end

{
  "stream": "btcusdt@depth20@100ms",
  "data": {
    "lastUpdateId": 37084267997,
    "asks": [
      [
        "26803.16000000",
        "2.83684000"
      ],
      [
        "26803.17000000",
        "0.09562000"
      ],
      [
        "26803.19000000",
        "1.46067000"
      ],
      [
        "26803.23000000",
        "0.14172000"
      ],
      ...
    ],
    "bids": [
      [
        "26803.15000000",
        "10.51675000"
      ],
      [
        "26803.09000000",
        "0.01658000"
      ],
      [
        "26803.03000000",
        "0.01851000"
      ],
      ...
    ]
  }
}