I'm a newbie to Elixir/Erlang. By way of example, I'm trying to learn how to subscribe to a websocket feed.
I've copied the Websockex basic example:
defmodule WebSocketExample do
use WebSockex
def start_link(url, state) do
WebSockex.start_link(url, __MODULE__, state)
end
def handle_frame({type, msg}, state) do
IO.puts "Received Message - Type: #{inspect type} -- Message: #{inspect msg}"
{:ok, state}
end
def handle_cast({:send, {type, msg} = frame}, state) do
IO.puts "Sending #{type} frame with payload: #{msg}"
{:reply, frame, state}
end
end
and am trying to instantiate it in iex with:
WebSocketExample.start_link "wss://www.bitmex.com/realtime?subscribe=instrument,quote:XBTUSD", state
(CompileError) iex:3: undefined function state/0
however I get the error that state is undefined.
I'm not sure what state should be (surely that's empty and gets passed around a loop?). Any tips that help me understand would be much appreciated!