Table of content
The exhaustive material of FIX API
Download SimpleFix-Go library
$ go get -u github.com/b2broker/simplefix-go
Install generator if you want to use your own scheme.
$ cd $GOPATH/src/github.com/b2broker/simplefix-go && go install ./...
Generator create message structures, tag and msg type constants and methods for work with any FIX API.
You can see basic result of Generator working at tests directory. It is short version of FIX 4.4 generated from scheme located in ./source directory.
fixgen -o=./fix44 -s=./source/fix44.xml -t=./source/types.xml
So, now you have your library code in ./fix44 directory.
-o
– output directory
-s
– path to main XML-scheme, you can see examples in ./source directory
-t
– path to XML file with types mapping. This file provides generator information about type casting. FIX protocol
has a lot of types, but in Go we should have small set of types for use FIX API.
According to parameters we must have two XML files for make our own library. You can use existing files or modify them as you want.
This is message builder, field and message tags for session pipelines. This structure will be generated by fixgen command very soon.
// fixgen is your generated fix package
var sessionOpts = session.Opts{
MessageBuilders: session.MessageBuilders{
HeaderBuilder: fixgen.Header{}.New(),
TrailerBuilder: fixgen.Trailer{}.New(),
LogonBuilder: fixgen.Logon{}.New(),
LogoutBuilder: fixgen.Logout{}.New(),
RejectBuilder: fixgen.Reject{}.New(),
HeartbeatBuilder: fixgen.Heartbeat{}.New(),
TestRequestBuilder: fixgen.TestRequest{}.New(),
ResendRequestBuilder: fixgen.ResendRequest{}.New(),
},
Tags: &messages.Tags{
MsgType: mustConvToInt(fixgen.FieldMsgType),
MsgSeqNum: mustConvToInt(fixgen.FieldMsgSeqNum),
HeartBtInt: mustConvToInt(fixgen.FieldHeartBtInt),
EncryptedMethod: mustConvToInt(fixgen.FieldEncryptMethod),
},
AllowedEncryptedMethods: map[string]struct{}{
fixgen.EnumEncryptMethodNoneother: {},
},
SessionErrorCodes: &messages.SessionErrorCodes{
InvalidTagNumber: mustConvToInt(fixgen.EnumSessionRejectReasonInvalidtagnumber),
RequiredTagMissing: mustConvToInt(fixgen.EnumSessionRejectReasonRequiredtagmissing),
TagNotDefinedForMessageType: mustConvToInt(fixgen.EnumSessionRejectReasonTagNotDefinedForThisMessageType),
UndefinedTag: mustConvToInt(fixgen.EnumSessionRejectReasonUndefinedtag),
TagSpecialWithoutValue: mustConvToInt(fixgen.EnumSessionRejectReasonTagspecifiedwithoutavalue),
IncorrectValue: mustConvToInt(fixgen.EnumSessionRejectReasonValueisincorrectoutofrangeforthistag),
IncorrectDataFormatValue: mustConvToInt(fixgen.EnumSessionRejectReasonIncorrectdataformatforvalue),
DecryptionProblem: mustConvToInt(fixgen.EnumSessionRejectReasonDecryptionproblem),
SignatureProblem: mustConvToInt(fixgen.EnumSessionRejectReasonSignatureproblem),
CompIDProblem: mustConvToInt(fixgen.EnumSessionRejectReasonCompidproblem),
Other: mustConvToInt(fixgen.EnumSessionRejectReasonOther),
},
}
Initiator is a FIX API client, which connect to an existing server by.
You can see example here.
Acceptor is a listener. It accepts and handles client connections. According to the FIX protocol acceptor could be provider or receiver of data. It means acceptor can send requests to the clients and read data streams of them.
You can see example here.
Session package provides you ready functional for work with default processes of FIX API such as authentication, logout, heartbeats, rejects and typical errors. It means that if you want to customize you default messages such as Logon (A) or Heartbeat (0), you should customize Session structure. There are two ways to do this:
-
Aggregate existing structure in your new one or just copy and edit it in you client code.
-
Modify builder for message which you want to change.
Standard Session structure accepts MessageBuilders as Opts field. Each of message builders is an interface. So it means you can create your own builder and library will use it as default.
For example, you want to add a new field "CounterPartyID" (tag number 22000) in you Logon message. You modified your XML document by adding new field in 'fields' section and in your Logon message:
<fix>
. . .
<messages>
<message name='Logon' msgcat='admin' msgtype='A'>
. . .
<field name='CounterPartyID' required='Y'/>
...
</message>
</messages>
. . .
<fields>
<field number="22000" name="CounterPartyID" type="STRING"/>
</fields>
. . .
</fix>
Then you generated code by fixgen. But you want to fill this fields manually. And this is time for custom builder:
// fixgen is your generated fix package
type CustomLogon struct {
*fixgen.Logon
}
func (cl *CustomLogon) New() messages.LogonBuilder {
l := cl.New()
l.SetFieldCounterParty(os.Getenv("COUNTER_PARTY_ID"))
return l
}
Now you can use your CustomLogon with new field as LogonBuilder in default FIX API pipelines.
- Add custom fields to protocol
- Add custom messages to protocol
- Add custom types to protocol
- Features for session pipelines
- Acceptor (server)
- Initiator (client)
- Validation of incoming messages
- Validation of outgoing messages
- Mock server with testing data
- Anything you want Just with submit a new issue