Expand description
An opinionated FIX 4.2 client library for the buy-side.
ForgeFIX is an engine that implements a subset of the FIX protocol which allows users to connect to brokers or exchanges to send and receive messages.
§Terminology
-
FIX Connection– A single connection to a FIX Session. A network connection is made over TCP, then a FIX logon handshake is performed to establish the FIX connection. The FIX connection ends properly with a FIX logout, but is considered ended if the TCP connection breaks.- Note, the term ‘connection’ is overloaded and can also mean TCP connection. When unclear, a ‘connection’ will be specified as TCP or FIX.
-
FIX Session– A conceptual construct that represents the bidirectional stream of ordered messages between two peers. A FIX Session can live across multiple instances of a FIX connection. -
FIX Engine– A sub-process running in the background that manages a single FIX connection to a FIX Session. The engine starts, runs, and ends the FIX connection as defined by the FIX protocol, and manages all resources that support the connection.
§Examples
§Asynchronous API
use forgefix::{
ApplicationError, SessionSettings, EngineFactory, EngineHandle,
};
#[tokio::main]
async fn main() -> Result<(), ApplicationError> {
// build session settings
let settings = SessionSettings::builder()
.with_sender_comp_id("my_id")
.with_target_comp_id("peer_id")
.with_store_path("./store".into())
.with_log_dir("./log".into())
.with_socket_addr("127.0.0.1:0".parse().unwrap())
.build()?;
// create a FIX engine and intiate TCP connection
let (handle, mut event_receiver) = EngineFactory::initiator(settings, forgefix::log::FileLoggerFactory)?
.start()
.await?;
// handle incoming messages in the background...
tokio::spawn(async move {
while let Some(msg) = event_receiver.recv().await {
println!("got an application message: {}", msg);
}
});
// logon to the FIX session
handle.logon_async().await?;
// send messages here...
// logout from the FIX session
handle.logout_async().await?;
Ok(())
}§Synchronous API*
use forgefix::{
ApplicationError, SessionSettings, EngineFactory, EngineHandle,
};
fn main() -> Result<(), ApplicationError> {
let settings = SessionSettings::builder()
.with_sender_comp_id("my_id")
.with_target_comp_id("peer_id")
.with_store_path("./store".into())
.with_log_dir("./log".into())
.with_socket_addr("127.0.0.1:0".parse().unwrap())
.build()?;
let (handle, mut event_receiver) = EngineFactory::initiator(settings, forgefix::log::FileLoggerFactory)?
.start_sync()?;
std::thread::spawn(move || {
while let Some(msg) = event_receiver.blocking_recv() {
println!("got an application message: {}", msg);
}
});
handle.logon_sync()?;
// send messages here...
handle.logout_sync()?;
Ok(())
}*When using synchronous API, a tokio runtime is still created internally (see
EngineFactory::start_sync)
§Feature Flags
sqlite: Enables the sqlite3 database backed store. Allows messages and sequences numbers to be persisted to disk, so ForgeFIX can pick up in the middle of a session if restarted. Otherwise, every restart results in a new FIX session.
Modules§
- fix
- Modules implementing the FIX spec for encoding and decoding messages
- log
- Generic logging traits and FileLoggerFactory
Structs§
- Engine
Factory - A struct that can establish a TCP connections to the peer and create FIX engine instances.
- Engine
Handle - A handle on a FIX engine instance.
- Session
Settings - A collection of settings used to configurate a FIX session.
- Session
Settings Builder - A builder for easily configuring all the fields of a
SessionSettings
Enums§
- Application
Error - Errors that can occur while running ForgeFIX.