FixAlchemy.SessionConfig (FIXAlchemy v0.2.1)

View Source

One FIX session of a connection: its name, its SenderCompID, the roles it serves, and the shared settings it overrides.

A connection's config is shared settings plus a list of sessions. A session's name identifies it within its connection and is the second element of every registry key it owns; its SenderCompID is its own, because two sessions to the same venue are told apart by exactly that and no venue accepts two carrying the same one; its roles say what it is for, and are what callers resolve against. Everything else it inherits from the shared settings until it names an override.

Sessions are declared under the :sessions key of a connection config, as maps or keyword lists:

[
  host: "fix.example.com",
  port: 5001,
  target_comp_id: "VENUE",
  sessions: [
    %{name: "order", roles: [:trading], sender_comp_id: "ACME_ORD"},
    %{
      name: "quote",
      roles: [:market_data],
      sender_comp_id: "ACME_MD",
      overrides: %{port: 5002}
    }
  ]
]

Overrides may also be written flat alongside name, roles and sender_comp_id. Keys and role names may be atoms or strings, so a config read back from storage needs no conversion before it is used.

A config carrying no :sessions declares its sessions through the flat host/port/sender_comp_id and host_md/port_md/sender_comp_id_md groups instead; from_connection_config/1 reads those as the two sessions :trading and :md.

Rules

  • A session is configured only when it carries its own sender comp id and its resolved host and port are both present; one that is not is dropped.
  • Any connection setting may be overridden. An override naming a setting nothing recognises is dropped; one holding the same value as the shared setting is kept, since a session that states a value owns it.
  • Names are unique within a connection. A blank name becomes "session<n>" for its position, and a repeated name gains a -<n> suffix.
  • Roles outside known_roles/0 are dropped. A session declaring none serves :trading.
  • When no session declares :market_data, the first session declaring :trading serves it too, so market data rides the trading session.

Summary

Functions

Coerce value to the type connection setting key is carried as.

The sessions a connection config declares, in declaration order.

The roles a session may declare.

The session serving role, falling back to one serving :trading.

Whether session serves role.

base_opts with the session's overrides, comp id, name and roles applied.

The session as connection-form parameters, with string keys.

Types

name()

@type name() :: atom() | binary()

role()

@type role() :: :trading | :market_data | :drop_copy | :ops | :back_office

t()

@type t() :: %FixAlchemy.SessionConfig{
  name: name(),
  overrides: keyword(),
  roles: [role()],
  sender_comp_id: binary()
}

Functions

cast(key, value)

@spec cast(atom(), term()) :: term()

Coerce value to the type connection setting key is carried as.

Strings are trimmed; a setting the engine holds as an integer or a boolean is parsed from its string form.

from_connection_config(config)

@spec from_connection_config(keyword() | map()) :: [t()]

The sessions a connection config declares, in declaration order.

Accepts the config as a keyword list or as a map with atom or string keys. Sessions that are not fully configured are dropped, so an empty list means the config names no usable session.

known_roles()

@spec known_roles() :: [role()]

The roles a session may declare.

resolve(sessions, role)

@spec resolve([t()], role()) :: {:ok, t()} | :error

The session serving role, falling back to one serving :trading.

Returns :error when neither exists.

serves?(session_config, role)

@spec serves?(t(), role()) :: boolean()

Whether session serves role.

session_opts(session, base_opts)

@spec session_opts(
  t(),
  keyword()
) :: keyword()

base_opts with the session's overrides, comp id, name and roles applied.

to_params(session)

@spec to_params(t()) :: %{required(binary()) => term()}

The session as connection-form parameters, with string keys.

Overrides are nested under "overrides", so a form renders exactly the settings the session states and leaves the rest inherited.