Bourse.Emulation (bourse v0.1.0)

Copy Markdown View Source

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.

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

dispatch_result()

@type dispatch_result() :: :passthrough | {:ok, term()} | {:error, Bourse.Error.t()}

entry()

@type entry() :: map()

scope()

@type scope() :: :rest | :ws

Functions

dispatch(exchange, method, scope, context)

@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.

emulated?(exchange, method, scope)

@spec emulated?(Bourse.Exchange.t(), atom(), scope()) :: boolean()

Returns true if a method is emulated for the exchange and scope.

entry(exchange, method, scope)

@spec entry(Bourse.Exchange.t(), atom(), scope()) :: entry() | nil

Returns emulated metadata for a method (or nil if not emulated).

handle_fetch_currencies(exchange, exchange_module, params, opts)

@spec handle_fetch_currencies(Bourse.Exchange.t(), module(), map(), keyword()) ::
  dispatch_result()

Derives unified currencies from fetchMarkets output (emulation strategy).

implemented_methods()

@spec implemented_methods() :: MapSet.t(atom())

Returns the set of emulated methods with runtime handlers implemented.

method_atom(name)

@spec method_atom(String.t() | nil) :: atom() | nil

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.

reload!()

@spec reload!() :: map()

Reloads emulation index (bypasses cache).