File: websocket_client.lua

package info (click to toggle)
lua-http 0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,100 kB
  • sloc: makefile: 60; sh: 16
file content (21 lines) | stat: -rwxr-xr-x 537 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env lua
--[[
Example of websocket client usage

  - Connects to the gdax market data feed.
	Documentation of feed: https://docs.gdax.com/#websocket-feed
  - Sends a subscribe message
  - Prints off 5 messages
  - Close the socket and clean up.
]]

local websocket = require "http.websocket"

local ws = websocket.new_from_uri("wss://ws-feed.gdax.com")
assert(ws:connect())
assert(ws:send([[{"type": "subscribe", "product_id": "BTC-USD"}]]))
for _=1, 5 do
	local data = assert(ws:receive())
	print(data)
end
assert(ws:close())