Bourse.WS.Subscription.MethodSubscription (bourse v0.7.0)

Copy Markdown View Source

Hyperliquid-style subscribe frame.

%{"method" => "subscribe", "subscription" => %{"type" => "allMids"}}

Accepts two caller conventions per channel list (same dual-shape contract as MethodParams / EventSubscribe):

  1. Plain strings — each string becomes the nested subscription's "type". Hyperliquid accepts one subscription object per frame; when multiple strings are supplied the first is used (matches prior single-type behavior).

    MethodSubscription.subscribe(["allMids"], %{})
    # => %{"method" => "subscribe", "subscription" => %{"type" => "allMids"}}
  2. Single pre-shaped map — used as the subscription object directly (e.g. %{"type" => "l2Book", "coin" => "BTC"}). Passing a map into the string branch previously double-wrapped to %{"type" => %{"type" => "allMids"}} and the venue rejected the frame.

    MethodSubscription.subscribe([%{"type" => "allMids"}], %{})
    # => %{"method" => "subscribe", "subscription" => %{"type" => "allMids"}}

Multiple maps per call return {:error, :multiple_maps_not_supported}; lists that mix maps and strings return {:error, :mixed_channel_types}.

Config keys: :op_field (default "method"), :args_field (default "subscription").