Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions application.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package quickfix

//The Application interface should be implemented by FIX Applications.
//Application interface should be implemented by FIX Applications.
//This is the primary interface for processing messages from a FIX Session.
type Application interface {
//Notification of a session begin created.
//OnCreate notification of a session begin created.
OnCreate(sessionID SessionID)

//Notification of a session successfully logging on.
//OnLogon notification of a session successfully logging on.
OnLogon(sessionID SessionID)

//Notification of a session logging off or disconnecting.
//OnLogout notification of a session logging off or disconnecting.
OnLogout(sessionID SessionID)

//Notification of admin message being sent to target.
//ToAdmin notification of admin message being sent to target.
ToAdmin(message *Message, sessionID SessionID)

//Notification of app message being sent to target.
//ToApp notification of app message being sent to target.
ToApp(message *Message, sessionID SessionID) error

//Notification of admin message being received from target.
//FromAdmin notification of admin message being received from target.
FromAdmin(message *Message, sessionID SessionID) MessageRejectError

//Notification of app message being received from target.
//FromApp notification of app message being received from target.
FromApp(message *Message, sessionID SessionID) MessageRejectError
}
13 changes: 8 additions & 5 deletions datadictionary/datadictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/xml"
"io"
"os"

"github.com/pkg/errors"
)

//DataDictionary models FIX messages, components, and fields.
Expand Down Expand Up @@ -297,24 +299,25 @@ func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
return &msg
}

//Parse loads and and build a datadictionary instance from an xml file.
//Parse loads and build a datadictionary instance from an xml file.
func Parse(path string) (*DataDictionary, error) {
var xmlFile *os.File
xmlFile, err := os.Open(path)
var err error
xmlFile, err = os.Open(path)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "problem opening file: %v", path)
}
defer xmlFile.Close()

return ParseSrc(xmlFile)
}

//ParseSrc loads and and build a datadictionary instance from an xml source.
//ParseSrc loads and build a datadictionary instance from an xml source.
func ParseSrc(xmlSrc io.Reader) (*DataDictionary, error) {
doc := new(XMLDoc)
decoder := xml.NewDecoder(xmlSrc)
if err := decoder.Decode(doc); err != nil {
return nil, err
return nil, errors.Wrapf(err, "problem parsing XML file")
}

b := new(builder)
Expand Down
5 changes: 3 additions & 2 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package quickfix

//FieldValueWriter is an interface for writing field values
type FieldValueWriter interface {
//Writes out the contents of the FieldValue to a []byte
//Write writes out the contents of the FieldValue to a []byte
Write() []byte
}

//FieldValueReader is an interface for reading field values
type FieldValueReader interface {
//Reads the contents of the []byte into FieldValue. Returns an error if there are issues in the data processing
//Read reads the contents of the []byte into FieldValue.
//Returns an error if there are issues in the data processing
Read([]byte) error
}

Expand Down
5 changes: 3 additions & 2 deletions filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/pkg/errors"

"github.com/quickfixgo/quickfix/config"
)

Expand Down Expand Up @@ -275,11 +276,11 @@ func (store *fileStore) CreationTime() time.Time {
}

func (store *fileStore) SaveMessage(seqNum int, msg []byte) error {
offset, err := store.bodyFile.Seek(0, os.SEEK_END)
offset, err := store.bodyFile.Seek(0, io.SeekEnd)
if err != nil {
return fmt.Errorf("unable to seek to end of file: %s: %s", store.bodyFname, err.Error())
}
if _, err := store.headerFile.Seek(0, os.SEEK_END); err != nil {
if _, err := store.headerFile.Seek(0, io.SeekEnd); err != nil {
return fmt.Errorf("unable to seek to end of file: %s: %s", store.headerFname, err.Error())
}
if _, err := fmt.Fprintf(store.headerFile, "%d,%d,%d\n", seqNum, offset, len(msg)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-sqlite3 v1.14.7
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.2.0
github.com/shopspring/decimal v1.3.1
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
Expand All @@ -28,10 +30,16 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
7 changes: 3 additions & 4 deletions internal/time_range.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package internal

import (
"errors"
"time"

"github.com/pkg/errors"
)

//TimeOfDay represents the time of day
Expand All @@ -13,8 +14,6 @@ type TimeOfDay struct {

const shortForm = "15:04:05"

var errParseTime = errors.New("Time must be in the format HH:MM:SS")

//NewTimeOfDay returns a newly initialized TimeOfDay
func NewTimeOfDay(hour, minute, second int) TimeOfDay {
d := time.Duration(second)*time.Second +
Expand All @@ -28,7 +27,7 @@ func NewTimeOfDay(hour, minute, second int) TimeOfDay {
func ParseTimeOfDay(str string) (TimeOfDay, error) {
t, err := time.Parse(shortForm, str)
if err != nil {
return TimeOfDay{}, errParseTime
return TimeOfDay{}, errors.Wrap(err, "time must be in the format HH:MM:SS")
}

return NewTimeOfDay(t.Clock()), nil
Expand Down
12 changes: 6 additions & 6 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package quickfix

//Log is a generic interface for logging FIX messages and events.
type Log interface {
//log incoming fix message
//OnIncoming log incoming fix message
OnIncoming([]byte)

//log outgoing fix message
//OnOutgoing log outgoing fix message
OnOutgoing([]byte)

//log fix event
//OnEvent log fix event
OnEvent(string)

//log fix event according to format specifier
//OnEventf log fix event according to format specifier
OnEventf(string, ...interface{})
}

//The LogFactory interface creates global and session specific Log instances
type LogFactory interface {
//global log
//Create global log
Create() (Log, error)

//session specific log
//CreateSessionLog session specific log
CreateSessionLog(sessionID SessionID) (Log, error)
}
2 changes: 1 addition & 1 deletion repeating_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type GroupItem interface {
//Tag returns the tag identifying this GroupItem
Tag() Tag

//Parameter to Read is tagValues. For most fields, only the first tagValue will be required.
//Read Parameter to Read is tagValues. For most fields, only the first tagValue will be required.
//The length of the slice extends from the tagValue mapped to the field to be read through the
//following fields. This can be useful for GroupItems made up of repeating groups.
//
Expand Down
29 changes: 27 additions & 2 deletions session_factory.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package quickfix

import (
"errors"
"net"
"strconv"
"time"

"github.com/pkg/errors"

"github.com/quickfixgo/quickfix/config"
"github.com/quickfixgo/quickfix/datadictionary"
"github.com/quickfixgo/quickfix/internal"
Expand Down Expand Up @@ -103,10 +104,18 @@ func (f sessionFactory) newSession(
}

if s.transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil {
err = errors.Wrapf(
err, "problem parsing XML datadictionary path '%v' for setting '%v",
settings.settings[config.TransportDataDictionary], config.TransportDataDictionary,
)
return
}

if s.appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil {
err = errors.Wrapf(
err, "problem parsing XML datadictionary path '%v' for setting '%v",
settings.settings[config.AppDataDictionary], config.AppDataDictionary,
)
return
}

Expand All @@ -119,6 +128,10 @@ func (f sessionFactory) newSession(
}

if s.appDataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil {
err = errors.Wrapf(
Copy link
Author

@rodoufu rodoufu Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an error happens here, we don't know which config is wrong neither which file does not exist.

err, "problem parsing XML datadictionary path '%v' for setting '%v",
settings.settings[config.DataDictionary], config.DataDictionary,
)
return
}

Expand Down Expand Up @@ -198,10 +211,18 @@ func (f sessionFactory) newSession(

var start, end internal.TimeOfDay
if start, err = internal.ParseTimeOfDay(startTimeStr); err != nil {
err = errors.Wrapf(
err, "problem parsing time of day '%v' for setting '%v",
settings.settings[config.StartTime], config.StartTime,
)
return
}

if end, err = internal.ParseTimeOfDay(endTimeStr); err != nil {
err = errors.Wrapf(
err, "problem parsing time of day '%v' for setting '%v",
settings.settings[config.EndTime], config.EndTime,
)
return
}

Expand All @@ -214,6 +235,10 @@ func (f sessionFactory) newSession(

loc, err = time.LoadLocation(locStr)
if err != nil {
err = errors.Wrapf(
err, "problem parsing time zone '%v' for setting '%v",
settings.settings[config.TimeZone], config.TimeZone,
)
return
}
}
Expand Down Expand Up @@ -404,7 +429,7 @@ func (f sessionFactory) buildHeartBtIntSettings(session *session, settings *Sess
return
}
}

if session.HeartBtIntOverride || mustProvide {
var heartBtInt int
if heartBtInt, err = settings.IntSetting(config.HeartBtInt); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion session_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *SessionSettings) DurationSetting(setting string) (val time.Duration, er
return
}

//BoolSetting returns the requested setting parsed as a boolean. Returns an errror if the setting is not set or cannot be parsed as a bool.
//BoolSetting returns the requested setting parsed as a boolean. Returns an error if the setting is not set or cannot be parsed as a bool.
func (s SessionSettings) BoolSetting(setting string) (bool, error) {
stringVal, err := s.Setting(setting)

Expand Down
2 changes: 1 addition & 1 deletion session_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ type sessionState interface {
//Stop triggers a clean stop
Stop(*session) (nextState sessionState)

//debugging convenience
//Stringer debugging convenience
fmt.Stringer
}

Expand Down
20 changes: 10 additions & 10 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,22 @@ func (s *MessageStoreTestSuite) TestMessageStore_SaveMessage_GetMessage() {
s.Equal(expectedMsgsBySeqNum[3], string(actualMsgs[2]))
}

func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_EmptyStore() {
func (s *MessageStoreTestSuite) TestMessageStore_GetMessages_EmptyStore() {
// When messages are retrieved from an empty store
messages, err := suite.msgStore.GetMessages(1, 2)
require.Nil(suite.T(), err)
messages, err := s.msgStore.GetMessages(1, 2)
require.Nil(s.T(), err)

// Then no messages should be returned
require.Empty(suite.T(), messages, "Did not expect messages from empty store")
require.Empty(s.T(), messages, "Did not expect messages from empty store")
}

func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges() {
t := suite.T()
func (s *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges() {
t := s.T()

// Given the following saved messages
require.Nil(t, suite.msgStore.SaveMessage(1, []byte("hello")))
require.Nil(t, suite.msgStore.SaveMessage(2, []byte("cruel")))
require.Nil(t, suite.msgStore.SaveMessage(3, []byte("world")))
require.Nil(t, s.msgStore.SaveMessage(1, []byte("hello")))
require.Nil(t, s.msgStore.SaveMessage(2, []byte("cruel")))
require.Nil(t, s.msgStore.SaveMessage(3, []byte("world")))

// When the following requests are made to the store
var testCases = []struct {
Expand All @@ -148,7 +148,7 @@ func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges()

// Then the returned messages should be
for _, tc := range testCases {
actualMsgs, err := suite.msgStore.GetMessages(tc.beginSeqNo, tc.endSeqNo)
actualMsgs, err := s.msgStore.GetMessages(tc.beginSeqNo, tc.endSeqNo)
require.Nil(t, err)
require.Len(t, actualMsgs, len(tc.expectedBytes))
for i, expectedMsg := range tc.expectedBytes {
Expand Down