FixAlchemy (FIXAlchemy v0.2.4)

View Source

FIX protocol engine for Elixir.

Frames the FIX byte stream, runs the session protocol, and routes each inbound message to your code by type through a keyed pub/sub bus. A message you subscribe to is delivered raw and decoded at the point of use; a message no one subscribes to is dropped after the cheap type scan.

Quick start

{:ok, conn} = FixAlchemy.connect(
  host: "fix.example.com",
  port: 9043,
  username: "demo_user",
  sender_comp_id: "CLIENT1",
  target_comp_id: "SERVER"
)

FixAlchemy.subscribe(conn, "W", "EUR/USD")
FixAlchemy.send_message(conn, {"V", [{55, "EUR/USD"}, {263, "1"}]})

Architecture

Summary

Functions

Establish a FIX connection to a server.

Trading capabilities derived from the connection's FIX specification.

Send a custom FIX message built from {msg_type, fields}.

Subscribe the calling process to a message type on this session.

Remove every subscription held by the calling process (or subscriber).

Functions

connect(opts)

@spec connect(keyword()) :: GenServer.on_start()

Establish a FIX connection to a server.

Returns {:ok, pid} on success or {:error, reason} on failure.

Options

  • :host - Server hostname (required)
  • :port - Server port (required)
  • :username - FIX username (required)
  • :sender_comp_id - Sender component ID (required)
  • :target_comp_id - Target component ID (required)
  • :password - FIX password (optional)
  • :sender_sub_id - SenderSubID (50), sent when set
  • :target_sub_id - TargetSubID (57), sent when set
  • :fix_version - FIX version string (default: "FIX.4.4")
  • :heartbeat_interval - Heartbeat interval in seconds (default: 30)
  • :reset_seq_number - Reset sequence on login (default: "Y")
  • :user_on_login - Send username/password in logon message (default: false)
  • :handlers - Subscriber modules to supervise with the session (default: [])
  • :connection_id - Unique ID for Registry naming (default: auto-generated)
  • :spec_file - Path to FIX spec XML file (default: from app config)
  • :app_spec_file - Path to the application dictionary XML, required when :spec_file is a FIXT transport dictionary (default: from app config)

disconnect(conn)

@spec disconnect(GenServer.server()) :: :ok

See FixAlchemy.Client.stop/1.

get_capabilities(conn)

@spec get_capabilities(GenServer.server()) :: FixAlchemy.Capabilities.t()

Trading capabilities derived from the connection's FIX specification.

send_message(conn, message)

@spec send_message(
  GenServer.server(),
  {binary(), list()}
) :: :ok

Send a custom FIX message built from {msg_type, fields}.

Examples

FixAlchemy.send_message(conn, {"D", [{55, "EUR/USD"}, {54, "1"}, {38, "1000"}]})

subscribe(conn, type, value \\ :all, opts \\ [])

@spec subscribe(GenServer.server(), binary(), binary() | :all, keyword()) :: :ok

Subscribe the calling process to a message type on this session.

  • subscribe(conn, type) — every message of that type
  • subscribe(conn, type, value) — where the routing tag equals value
  • subscribe(conn, type, :all, tag: t, where: fun) — where fun.(value)

Examples

FixAlchemy.subscribe(conn, "W", "EUR/USD")
FixAlchemy.subscribe(conn, "8", :all, tag: 271, where: &(String.to_integer(&1) > 10_000))

unsubscribe(conn, subscriber \\ nil)

@spec unsubscribe(GenServer.server(), pid()) :: :ok

Remove every subscription held by the calling process (or subscriber).