Expand description
§fixer
A full-featured FIX protocol engine for Rust. Supports FIX versions 4.0 through 5.0SP2 with spec-driven message validation, code-generated type-safe messages, and pluggable storage and logging backends.
§Quick Start
A FIX application has three parts: a configuration, an Application trait
implementation, and an Acceptor (server) or Initiator (client).
use fixer::{
acceptor::Acceptor,
application::Application,
errors::MessageRejectErrorResult,
log::screen_log::ScreenLogFactory,
message::Message,
registry::send_to_target,
session::session_id::SessionID,
settings::Settings,
store::MemoryStoreFactory,
};
use simple_error::SimpleResult;
use std::sync::Arc;
use tokio::io::BufReader;
struct MyApp;
impl Application for MyApp {
fn on_create(&self, session_id: &Arc<SessionID>) {
println!("Session created: {session_id}");
}
fn on_logon(&self, session_id: &Arc<SessionID>) {
println!("Logon: {session_id}");
}
fn on_logout(&self, session_id: &Arc<SessionID>) {
println!("Logout: {session_id}");
}
fn to_admin(&self, _msg: &mut Message, _session_id: &Arc<SessionID>) {}
fn to_app(
&self, _msg: &mut Message, _session_id: &Arc<SessionID>,
) -> SimpleResult<()> {
Ok(())
}
fn from_admin(
&self, _msg: &Message, _session_id: &Arc<SessionID>,
) -> MessageRejectErrorResult {
Ok(())
}
fn from_app(
&self, msg: &Message, session_id: &Arc<SessionID>,
) -> MessageRejectErrorResult {
// Echo the message back (see examples/echo_server for a full version)
println!("Received message from {session_id}");
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg = "\
[DEFAULT]
SocketAcceptPort=5001
SenderCompID=SERVER
TargetCompID=CLIENT
ResetOnLogon=Y
[SESSION]
BeginString=FIX.4.2
";
let settings = Settings::parse(BufReader::new(cfg.as_bytes())).await?;
let app: Arc<dyn Application> = Arc::new(MyApp);
let store_factory = MemoryStoreFactory::new();
let log_factory = ScreenLogFactory::new();
let mut acceptor =
Acceptor::new(app, store_factory, settings, log_factory).await?;
acceptor.start().await?;
tokio::signal::ctrl_c().await?;
acceptor.stop().await;
Ok(())
}§Architecture
| Concept | Description |
|---|---|
Application | Your code — callbacks for session events and messages |
Acceptor | Listens for inbound FIX connections (server side) |
Initiator | Connects to remote FIX servers (client side) |
Settings | INI-style configuration with [DEFAULT] and [SESSION] sections |
Message | A FIX message with Header, Body, and Trailer FieldMaps |
SessionID | Identifies a session by BeginString + SenderCompID + TargetCompID |
MessageStoreFactoryEnum | Creates message stores (memory, file, SQL, MongoDB) |
LogFactoryEnum | Creates loggers (screen, file, SQL, MongoDB, composite) |
§Feature Flags
All features are opt-in. By default only the in-memory store and screen/file loggers are available.
| Feature | Description |
|---|---|
sql_store | SQL-backed message store (SQLite, PostgreSQL, MySQL) via sqlx |
sql_log | SQL-backed logging via sqlx |
mongo_store | MongoDB-backed message store via mongodb |
mongo_log | MongoDB-backed logging via mongodb |
§Generated Types
The companion crate fixer-fix provides
code-generated, type-safe FIX messages. See its documentation for usage with
tag,
field,
enums, and
per-version message modules (fix40 through fix50sp2).
§Examples
See the examples/ directory for working applications:
echo_server— Acceptor that echoes messages back to the sendertrade_client— Initiator that sends orders using generated types
Modules§
- acceptor
- application
- config
- connection
- datadictionary
- errors
- field
- field_
map - fileutil
- fix_
boolean - fix_
bytes - fix_
decimal - fix_
float - fix_int
- fix_
string - fix_
utc_ timestamp - initiator
- log
- message
- message_
router - msg_
type - parser
- registry
- repeating_
group - session
- settings
- store
- tag
- tag_
value - tls
- validation