FixAlchemy.Session behaviour (FIXAlchemy v0.2.4)

View Source

Base for a per-session handshake subscriber.

use FixAlchemy.Session gives a GenServer that subscribes to the session's client for the message types it cares about and dispatches each to handle_fix/4. The defaults implement a plain FIX session: it subscribes to logon (A) and marks the session ready the moment logon is accepted.

A broker adapter overrides the callbacks with @impl FixAlchemy.Session to add its own login flow — credentials, account discovery, entitlements — while reusing everything else:

defmodule MyBroker.Session do
  use FixAlchemy.Session

  @impl FixAlchemy.Session
  def message_types, do: ["A", "BF", "BA"]

  @impl FixAlchemy.Session
  def handle_fix("A", _raw, meta, state) do
    FixAlchemy.Client.send_custom_message(meta.client, {"BE", credentials(state)})
    state
  end

  def handle_fix(type, raw, meta, state), do: super(type, raw, meta, state)
end

Summary

Callbacks

Handle a dispatched message, returning the new state.

Build the session's state from its start options.

Message types this session subscribes to (default ["A"]).

Functions

Ask the venue for its instruments with a SecurityListRequest (35=x).

Subscribe pid to types on the session's client for {connection_id, session_name}.

Callbacks

handle_fix(type, raw, meta, state)

@callback handle_fix(type :: binary(), raw :: binary(), meta :: map(), state :: term()) ::
  term()

Handle a dispatched message, returning the new state.

init_session(opts)

@callback init_session(opts :: keyword()) :: term()

Build the session's state from its start options.

message_types()

@callback message_types() :: [binary()]

Message types this session subscribes to (default ["A"]).

Functions

request_security_list(client, arg2)

@spec request_security_list(GenServer.server(), map()) :: :ok

Ask the venue for its instruments with a SecurityListRequest (35=x).

Sends nothing when the session was started with request_security_list: false. The reply (35=y) is collected by FixAlchemy.MarketData; a venue that does not serve security lists answers with a reject, which the engine records against the message type and does not repeat.

subscribe_types(connection_id, session_name, pid, types)

@spec subscribe_types(binary(), FixAlchemy.SessionConfig.name(), pid(), [binary()]) ::
  :ok

Subscribe pid to types on the session's client for {connection_id, session_name}.