1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! # fixer
//!
//! A full-featured [FIX protocol](https://www.fixtrading.org/) 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).
//!
//! ```rust,no_run
//! 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 [`FieldMap`]s |
//! | [`SessionID`] | Identifies a session by `BeginString` + `SenderCompID` + `TargetCompID` |
//! | [`MessageStoreFactoryEnum`] | Creates message stores (memory, file, SQL, `MongoDB`) |
//! | [`LogFactoryEnum`] | Creates loggers (screen, file, SQL, `MongoDB`, composite) |
//!
//! [`Application`]: application::Application
//! [`Acceptor`]: acceptor::Acceptor
//! [`Initiator`]: initiator::Initiator
//! [`Settings`]: settings::Settings
//! [`Message`]: message::Message
//! [`FieldMap`]: field_map::FieldMap
//! [`SessionID`]: session::session_id::SessionID
//! [`MessageStoreFactoryEnum`]: store::MessageStoreFactoryEnum
//! [`LogFactoryEnum`]: log::LogFactoryEnum
//!
//! ## 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`](https://docs.rs/fixer-fix) provides
//! code-generated, type-safe FIX messages. See its documentation for usage with
//! [`tag`](https://docs.rs/fixer-fix/latest/fixer_fix/tag/index.html),
//! [`field`](https://docs.rs/fixer-fix/latest/fixer_fix/field/index.html),
//! [`enums`](https://docs.rs/fixer-fix/latest/fixer_fix/enums/index.html), 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 sender
//! - **`trade_client`** — Initiator that sends orders using generated types
extern crate simple_error;
/// Constructs an `FxHashMap` from key-value pairs.
/// Constructs a `HashSet` from values.
/// Re-export for backward compatibility.
/// Re-export for backward compatibility.
//FIX BeginString string values
pub const BEGIN_STRING_FIX40: &str = "FIX.4.0";
pub const BEGIN_STRING_FIX41: &str = "FIX.4.1";
pub const BEGIN_STRING_FIX42: &str = "FIX.4.2";
pub const BEGIN_STRING_FIX43: &str = "FIX.4.3";
pub const BEGIN_STRING_FIX44: &str = "FIX.4.4";
pub const BEGIN_STRING_FIXT11: &str = "FIXT.1.1";