Runtime emulation dispatch for Bourse unified methods.
Uses extracted emulated method metadata to decide when a method should be derived at runtime instead of issuing HTTP or WebSocket requests.
The metadata index is cached in :persistent_term for the life of the VM.
In a long-running dev session, recompile/0 reloads modules but does not
invalidate that cache — after editing a venue's emulated_methods slice,
call Bourse.Emulation.reload!/0 or the stale index keeps answering.
Summary
Functions
Dispatches emulated method calls.
Returns true if a method is emulated for the exchange and scope.
Returns emulated metadata for a method (or nil if not emulated).
Derives unified currencies from fetchMarkets output (emulation strategy).
Returns the set of emulated methods with runtime handlers implemented.
Maps an extractor JS method name to its snake_case atom.
Reloads emulation index (bypasses cache).
Types
@type dispatch_result() :: :passthrough | {:ok, term()} | {:error, Bourse.Error.t()}
@type entry() :: map()
@type scope() :: :rest | :ws
Functions
@spec dispatch(Bourse.Exchange.t(), atom(), scope(), map()) :: dispatch_result()
Dispatches emulated method calls.
Returns :passthrough when the method is not emulated for this exchange,
{:ok, result} when emulation succeeds, or {:error, reason} on failure.
@spec emulated?(Bourse.Exchange.t(), atom(), scope()) :: boolean()
Returns true if a method is emulated for the exchange and scope.
@spec entry(Bourse.Exchange.t(), atom(), scope()) :: entry() | nil
Returns emulated metadata for a method (or nil if not emulated).
@spec handle_fetch_currencies(Bourse.Exchange.t(), module(), map(), keyword()) :: dispatch_result()
Derives unified currencies from fetchMarkets output (emulation strategy).
Returns the set of emulated methods with runtime handlers implemented.
Maps an extractor JS method name to its snake_case atom.
Resolves via Unified.method_atom_for_js_name/1 (method_defs) plus a small
explicit map for WS names not yet in method_defs. Unknown names return nil
rather than minting atoms.
@spec reload!() :: map()
Reloads emulation index (bypasses cache).