/Go Documentation

Installation

Build and Install

QuickFIX/Go requires Go to be installed on your machine (version 1.6+ is required). To install QuickFIX/Go and its dependencies, use go get:

 

$ go get github.com/quickfixgo/quickfix

Staying up to date

To update QuickFIX/Go to the latest version, use:

 

go get -u github.com/quickfixgo/quickfix

Generating QuickFIX/Go Databases

Everything needed to generate your database is in the _sql directory. For MySQL, there are the script and batch files create.sh and create.bat. These scripts will work on a newly installed MySQL database with default permisions. The scripts will try to generate the database using the root MySQL account with no password. If you need to use a different account or need a password, you will have to edit the script. To select a different user, simply change 'root' to another user. To add a password, use pass the -p option after the username. Similar scripts are provided for MSSQL, PostgreSQL and Oracle.

Getting Started

Creating your QuickFIX/Go Application

Creating a FIX application is as easy as implementing the QuickFIX/Go Application interface.

 

package quickfix
type Application interface {
//Notification of a session begin created.
OnCreate(sessionID SessionID)
//Notification of a session successfully logging on.
OnLogon(sessionID SessionID)
//Notification of a session logging off or disconnecting.
OnLogout(sessionID SessionID)
//Notification of admin message being sent to target.
ToAdmin(message Message, sessionID SessionID)
//Notification of app message being sent to target.
ToApp(message Message, sessionID SessionID) error
//Notification of admin message being received from target.
FromAdmin(message Message, sessionID SessionID) MessageRejectError
//Notification of app message being received from target.
FromApp(message Message, sessionID SessionID) MessageRejectError
}

 

By implementing these interface methods in your derived type, you are requesting to be notified of events that occur on the FIX engine. The function that you should be most aware of is FromApp.

 

Here are explanations of what these callback functions provide for you.

 

OnCreate OnCreate is called when quickfix creates a new session. A session comes into and remains in existence for the life of the application. Sessions exist whether or not a counter party is connected to it. As soon as a session is created, you can begin sending messages to it. If no one is logged on, the messages will be sent at the time a connection is established with the counterparty.

 

OnLogon OnLogon notifies you when a valid logon has been established with a counter party. This is called when a connection has been established and the FIX logon process has completed with both parties exchanging valid logon messages.

 

OnLogout OnLogout notifies you when an FIX session is no longer online. This could happen during a normal logout exchange or because of a forced termination or a loss of network connection.

 

ToAdmin ToAdmin provides you with a peak at the administrative messages that are being sent from your FIX engine to the counter party. This is normally not useful for an application however it is provided for any logging you may wish to do. Notice that the Message is not const. This allows you to add fields before an administrative message is sent out.

 

ToApp ToApp notifies you of application messages that you are being sent to a counterparty. Notice that the Message is not const. This allows you to add fields before an application message before it is sent out.

 

FromAdmin FromAdmin notifies you when an administrative message is sent from a counterparty to your FIX engine. This can be useful for doing extra validation on logon messages such as for checking passwords.

 

FromApp FromApp is one of the core entry points for your FIX application. Every application level request will come through here. If, for example, your application is a sell-side OMS, this is where you will get your new order requests. If you were a buy side, you would get your execution reports here.

 

The sample code below shows how you might start up a FIX acceptor which listens on a socket. If you wanted an initiator, you would simply replace NewAcceptor in this code fragment with NewInitiator.

 

package main

import (
"flag"
"github.com/quickfixgo/quickfix"
"os"
)

func main() {
flag.Parse()
fileName := flag.Arg(0)

//FooApplication is your type that implements the Application interface
var app FooApplication

cfg, _ := os.Open(fileName)
appSettings, _ := quickfix.ParseSettings(cfg)
storeFactory := quickfix.NewMemoryStoreFactory()
logFactory, _ := quickfix.NewFileLogFactory(appSettings)
acceptor, _ := quickfix.NewAcceptor(app, storeFactory, appSettings, logFactory)

_ = acceptor.Start()
//for condition == true { do something }
acceptor.Stop()
}

Configuration

A QuickFIX/Go acceptor or initiator can maintain multiple FIX sessions. A FIX session is defined in QuickFIX/Go as a unique combination of a BeginString (the FIX version number), a SenderCompID (your ID), and a TargetCompID (the ID of your counterparty). A SessionQualifier can also be use to disambiguate otherwise identical sessions. The Settings type has the ability to parse settings out of any io.Reader such as a file. If you decide to write your own components (storage for a particular database, a new kind of connection, etc.), you can programatically configure QuickFIX/Go using the methods of a Settings instance. A settings file is set up with two types of headings, a [DEFAULT] and a [SESSION] heading. [SESSION] tells QuickFIX/Go that a new Session is being defined. [DEFAULT] is a where you can define settings that all sessions use by default. If you do not provide a setting that QuickFIX/Go needs, calling Start on a configured Acceptor or Initiator will return an error telling you what setting is missing or improperly formatted. Tablular data layout to be added

QuickFIX/Go Settings

ID Description Valid Values Default
Session
BeginString Version of FIX this session should use
  • FIXT.1.1
  • FIX.4.4
  • FIX.4.3
  • FIX.4.2
  • FIX.4.1
  • FIX.4.0
SenderCompID Your ID as associated with this FIX session case-sensitive alpha-numeric string
SenderSubID (Optional) Your subID as associated with this FIX session case-sensitive alpha-numeric string
SenderLocationID (Optional) Your locationID as associated with this FIX session case-sensitive alpha-numeric string
TargetCompID Counter parties ID as associated with this FIX session case-sensitive alpha-numeric string
TargetSubID (Optional) Counterparty's subID as associated with this FIX session case-sensitive alpha-numeric string
TargetLocationID (Optional) Counterparty's locationID as associated with this FIX session case-sensitive alpha-numeric string
SessionQualifier Additional qualifier to disambiguate otherwise identical sessions case-sensitive alpha-numeric string
DefaultApplVerID Required only for FIXT 1.1 (and newer). Ignored for earlier transport versions. Specifies the default application version ID for the session. This can either be the ApplVerID enum (see the ApplVerID field) or the BeginString for the default version.
  • FIX.5.0SP2
  • FIX.5.0SP1
  • FIX.5.0
  • FIX.4.4
  • FIX.4.3
  • FIX.4.2
  • FIX.4.1
  • FIX.4.0
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 3
  • 2
TimeZone Time zone for this session; if specified, the session start and end will be converted from this zone to UTC.
  • IANA Time zone ID (America/New_York, Asia/Tokyo, Europe/London, etc.)
  • Local (The Zone on host)
UTC
StartTime Time of day that this FIX session becomes activated. Time in the format of HH:MM:SS, time is represented in time zone configured by TimeZone
EndTime Time of day that this FIX session becomes deactivated. Time in the format of HH:MM:SS, time is represented in time zone configured by TimeZone
StartDay For week long sessions, the starting day of week for the session. Use in combination with StartTime. Full day of week in English, or 3 letter abbreviation (i.e. Monday and Mon are valid)
EndDay For week long sessions, the ending day of week for the session. Use in combination with EndTime. Full day of week in English, or 3 letter abbreviation (i.e. Monday and Mon are valid)
ResetOnLogon Determines if sequence numbers should be reset when recieving a logon request. Acceptors only.
  • Y
  • N
N
ResetOnLogout Determines if sequence numbers should be reset to 1 after a normal logout termination.
  • Y
  • N
N
ResetOnDisconnect Determines if sequence numbers should be reset to 1 after an abnormal termination.
  • Y
  • N
N
RefreshOnLogon Determines if session state should be restored from persistence layer when logging on. Useful for creating hot failover sessions.
  • Y
  • N
N
EnableLastMsgSeqNumProcessed Add the last message sequence number processed in the header (optional tag 369).
  • Y
  • N
N
ResendRequestChunkSize

Setting to limit the size of a resend request in case of missing messages. This is useful when the remote FIX engine does not allow to ask for more than n message for a ResendRequest.

E.g. if the ResendRequestChunkSize is set to 5 and a gap of 7 messages is detected, a first resend request will be sent for 5 messages. When this gap has been filled, another resend request for 2 messages will be sent. If the ResendRequestChunkSize is set to 0, only one ResendRequest for all the missing messages will be sent.

Value must be a positive integer 0 (disables splitting)
TimeStampPrecision

Determines precision for timestamps in (Orig)SendingTime fields that are sent out. Only available for FIX.4.2 and greater, FIX versions earlier than FIX.4.2 will use timestamp resolution in seconds.

  • SECONDS
  • MILLIS
  • MICROS
  • NANOS
MILLIS
Validation
DataDictionary

XML definition file for validating incoming FIX messages. If no DataDictionary is supplied, only basic message validation will be done.

This setting should only be used with FIX transport versions older than FIXT.1.1. See TransportDataDictionary and AppDataDictionary for FIXT.1.1 settings.

Value must be a valid XML data dictionary file. QuickFIX/Go comes with the following defaults in the spec/ directory

  • FIX44.xml
  • FIX43.xml
  • FIX42.xml
  • FIX41.xml
  • FIX40.xml
TransportDataDictionary XML definition file for validating admin (transport) messages. This setting is only valid for FIXT.1.1 (or newer) sessions. See DataDictionary for older transport versions (FIX.4.0 - FIX.4.4) for additional information.

Value must be a valid XML data dictionary file, QuickFIX/Go comes with the following defaults in the spec/ directory

  • FIXT1.1.xml
AppDataDictionary

XML definition file for validating application messages. This setting is only valid for FIXT.1.1 (or newer) sessions. See DataDictionary for older transport versions (FIX.4.0 - FIX.4.4) for additional information.

This setting supports the possibility of a custom application data dictionary for each session. This setting would only be used with FIXT 1.1 and new transport protocols. This setting can be used as a prefix to specify multiple application dictionaries for the FIXT transport. For example:

DefaultApplVerID=FIX.4.2
# For default application version ID
AppDataDictionary=FIX42.xml
# For nondefault application version ID
# Use BeginString suffix for app version
AppDataDictionary.FIX.4.4=FIX44.xml
        

Value must be a valid XML data dictionary file. QuickFIX/Go comes with the following defaults in the spec/ directory

  • FIX50SP2.xml
  • FIX50SP1.xml
  • FIX50.xml
  • FIX44.xml
  • FIX43.xml
  • FIX42.xml
  • FIX41.xml
  • FIX40.xml
ValidateFieldsOutOfOrder If set to N, fields that are out of order (i.e. body fields in the header, or header fields in the body) will not be rejected. Useful for connecting to systems which do not properly order fields.
  • Y
  • N
Y
CheckLatency If set to Y, messages must be received from the counterparty within a defined number of seconds (see MaxLatency). It is useful to turn this off if a system uses localtime for it's timestamps instead of GMT.
  • Y
  • N
Y
MaxLatency If CheckLatency is set to Y, this defines the number of seconds latency allowed for a message to be processed. Value must be positive integer. 120
Initiator
ReconnectInterval Time between reconnection attempts in seconds. Only used for initiators. Value must be positive integer. 30
HeartBtInt Heartbeat interval in seconds. Only used for initiators. Value must be positive integer.
SocketConnectPort Socket port for connecting to a session. Only used for initiators. Must be positive integer
SocketConnectHost Host to connect to. Only used for initiators. Value must be a valid IPv4 or IPv6 address or a domain name
SocketConnectPort<n> Alternate socket ports for connecting to a session for failover, where n is a positive integer. (i.e.) SocketConnectPort1, SocketConnectPort2... must be consecutive and have a matching SocketConnectHost[n]. Value must be a positive integer.
SocketConnectHost<n> Alternate socket hosts for connecting to a session for failover, where n is a positive integer. (i.e.) SocketConnectHost1, SocketConnectHost2... must be consecutive and have a matching SocketConnectPort[n]. Value must be a valid IPv4 or IPv6 address or a domain name
Acceptor
SocketAcceptHost Socket host address for listening on incoming connections, only used for acceptors. Valid interface All available interfaces.
SocketAcceptPort Socket port for listening to incoming connections, only used for acceptors. Value must be a positive integer, valid open socket port.
Secure Communication
SocketPrivateKeyFile Private key to use for secure TLS connections. Must be used with SocketCertificateFile. File Path
SocketCertificateFile Certificate to use for secure TLS connections. Must be used with SocketPrivateKeyFile. File Path
SocketCAFile Optional root CA to use for secure TLS connections. For acceptors, client certificates will be verified against this CA. For initiators, clients will use the CA to verify the server certificate. If not configurated, initiators will verify the server certificate using the host's root CA set. File Path
SocketInsecureSkipVerify Controls whether a client verifies the server's certificate chain and host name. If InsecureSkipVerify is true, TLS accepts any certificate presented by the server and any host name in that certificate. In this mode, TLS is susceptible to man-in-the-middle attacks. This should be used only for testing.
  • Y
  • N
N
Storage
PersistMessages If set to N, no messages will be persisted. This will force QuickFIX/Go to always send GapFills instead of resending messages. Use this if you know you never want to resend a message. Useful for market data streams.
  • Y
  • N
Y
FileStorePath Directory to store sequence number and message files. Only used with FileStoreFactory. Valid directory for storing files, must have write access
SQLStoreDriver The name of the database driver to use. Only used with SqlStoreFactory. See https://github.com/golang/go/wiki/SQLDrivers for the list of available drivers
SQLStoreDataSourceName The driver-specific data source name of the database to use. Only used with SqlStoreFactory.
SQLStoreConnMaxLifetime

SQLStoreConnMaxLifetime sets the maximum duration of time that a database connection may be reused (see https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime). Defaults to zero, which causes connections to be reused forever. Only used with SqlStoreFactory.

If your database server has a config option to close inactive connections after some duration (e.g. MySQL "wait_timeout"), set SQLStoreConnMaxLifetime to a value less than that duration.

Example Values:

SQLStoreConnMaxLifetime=14400s # 14400 seconds
SQLStoreConnMaxLifetime=2h45m  # 2 hours and 45 minutes
        
Logging
FileLogPath Directory to store logs. Value must be valid directory for storing files, application must have write access.

Sample Settings File

# default settings for sessions
[DEFAULT]
ReconnectInterval=60
SenderCompID=TW

# session definition
[SESSION]
# inherit ReconnectInterval and SenderCompID from default
BeginString=FIX.4.1
TargetCompID=ARCA
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=20
SocketConnectPort=9823
SocketConnectHost=123.123.123.123
DataDictionary=somewhere/FIX41.xml

[SESSION]
BeginString=FIX.4.0
TargetCompID=ISLD
StartTime=12:00:00
EndTime=23:00:00
HeartBtInt=30
SocketConnectPort=8323
SocketConnectHost=23.23.23.23
DataDictionary=somewhere/FIX40.xml

[SESSION]
BeginString=FIX.4.2
TargetCompID=INCA
StartTime=12:30:00
EndTime=21:30:00
# overide default setting for RecconnectInterval
ReconnectInterval=30
HeartBtInt=30
SocketConnectPort=6523
SocketConnectHost=3.3.3.3
# (optional) alternate connection ports and hosts to cycle through on failover
SocketConnectPort1=8392
SocketConnectHost1=8.8.8.8
SocketConnectPort2=2932
SocketConnectHost2=12.12.12.12
DataDictionary=somewhere/FIX42.xml

Validation

If configured to validate, QuickFIX/Go will validate and reject any poorly formed messages before they can reach your application. XML files define what messages, fields, and values a session supports. Several standard files are in included in the spec/ directory. The skeleton of a definition file looks like this.
<fix type="FIX" major="4" minor="1">
<header>
<field name="BeginString" required="Y"/>
...
</header>
<trailer>
<field name="CheckSum" required="Y"/>
...
</trailer>
<messages>
<message name="Heartbeat" msgtype="0" msgcat="admin">
<field name="TestReqID" required="N"/>
</message>
...
<message name="NewOrderSingle" msgtype="D" msgcat="app">
<field name="ClOrdID" required="Y"/>
...
</message>
...
</messages>
<fields>
<field number="1" name="Account" type="CHAR" />
...
<field number="4" name="AdvSide" type="CHAR">
<value enum="B" description="BUY" />
<value enum="S" description="SELL" />
<value enum="X" description="CROSS" />
<value enum="T" description="TRADE" />
</field>
...
</fields>
</fix>
The validator will not reject conditionally required fields because the rules for them are not clearly defined. Returning a MessageRejectError from an Application's FromApp or FromAdmin methods will cause a message to be rejected.

Working With Messages

Receiving Messages

Most of the messages you will be interested in looking at will be arriving in your FromApp function of your application. All messages have a header and trailer. If you want to get Header or Trailer fields, you must access those fields from the Header or Trailer embedded Struct. All other fields are accessible in the Body embedded struct. QuickFIX/Go has a type for all messages and fields defined in the standard spec. The easiest and most typesafe method of receiving messages is by using the QuickFIX/Go MessageRouter generated message types. Any messages you do not establish routes for will by default return an UnsupportedMessageType reject.
import (
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/field"
"github.com/quickfixgo/quickfix/fix41/newordersingle"
)

type MyApplication struct {
*quickfix.MessageRouter
}

func (m *MyApplication) init() {
m.MessageRouter=quickfix.NewMessageRouter()
m.AddRoute(newordersingle.Route(m.onNewOrderSingle))
}

func (m *MyApplication) FromApp(msg quickfix.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
return m.Route(msg, sessionID)
}

func (m *MyApplication) onNewOrderSingle(msg newordersingle.NewOrderSingle, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
clOrdID, err := msg.GetClOrdID()
if err != nil {
return
}

//compile time error!! field not defined in FIX41
clearingAccount, err := msg.GetClearingAccount()

...
return
}
You can also bypass the MessageRouter and type safe classes by inspecting the Message directly. The preferred way of doing this is to use the QuickFIX/Go generated Field types.
func (m *MyApplication) FromApp(msg quickfix.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
var price field.PriceField
if err = msg.Body.Get(&field); err!=nil {
return
}

...
return
}
Or you can go the least type safe route.
func (m *MyApplication) FromApp(msg quickfix.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
var field quickfix.FIXString
if err = msg.Body.GetField(quickfix.Tag(44), &field); err!=nil {
return
}

...
return
}

Sending Messages

Messages can be sent to the counter party with the Send and SendToTarget functions.
//Send determines the session to send Messagable using header fields BeginString, TargetCompID, SenderCompID
func Send(m Messagable) error

//SendToTarget sends Messagable based on the sessionID. Convenient for use in FromApp since it provides a session ID for incoming messages
func SendToTarget(m Messagable, sessionID SessionID) error