|
| 1 | +package heartbeat |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/quickfixgo/field" |
| 5 | + "github.com/quickfixgo/fixt11" |
| 6 | + "github.com/quickfixgo/quickfix" |
| 7 | + "github.com/quickfixgo/tag" |
| 8 | +) |
| 9 | + |
| 10 | +//Heartbeat is the fixt11 Heartbeat type, MsgType = 0 |
| 11 | +type Heartbeat struct { |
| 12 | + fixt11.Header |
| 13 | + *quickfix.Body |
| 14 | + fixt11.Trailer |
| 15 | + Message *quickfix.Message |
| 16 | +} |
| 17 | + |
| 18 | +//FromMessage creates a Heartbeat from a quickfix.Message instance |
| 19 | +func FromMessage(m *quickfix.Message) Heartbeat { |
| 20 | + return Heartbeat{ |
| 21 | + Header: fixt11.Header{&m.Header}, |
| 22 | + Body: &m.Body, |
| 23 | + Trailer: fixt11.Trailer{&m.Trailer}, |
| 24 | + Message: m, |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +//ToMessage returns a quickfix.Message instance |
| 29 | +func (m Heartbeat) ToMessage() *quickfix.Message { |
| 30 | + return m.Message |
| 31 | +} |
| 32 | + |
| 33 | +//New returns a Heartbeat initialized with the required fields for Heartbeat |
| 34 | +func New() (m Heartbeat) { |
| 35 | + m.Message = quickfix.NewMessage() |
| 36 | + m.Header = fixt11.NewHeader(&m.Message.Header) |
| 37 | + m.Body = &m.Message.Body |
| 38 | + m.Trailer.Trailer = &m.Message.Trailer |
| 39 | + |
| 40 | + m.Header.Set(field.NewMsgType("0")) |
| 41 | + |
| 42 | + return |
| 43 | +} |
| 44 | + |
| 45 | +//A RouteOut is the callback type that should be implemented for routing Message |
| 46 | +type RouteOut func(msg Heartbeat, sessionID quickfix.SessionID) quickfix.MessageRejectError |
| 47 | + |
| 48 | +//Route returns the beginstring, message type, and MessageRoute for this Message type |
| 49 | +func Route(router RouteOut) (string, string, quickfix.MessageRoute) { |
| 50 | + r := func(msg *quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError { |
| 51 | + return router(FromMessage(msg), sessionID) |
| 52 | + } |
| 53 | + return "FIXT.1.1", "0", r |
| 54 | +} |
| 55 | + |
| 56 | +//SetTestReqID sets TestReqID, Tag 112 |
| 57 | +func (m Heartbeat) SetTestReqID(v string) { |
| 58 | + m.Set(field.NewTestReqID(v)) |
| 59 | +} |
| 60 | + |
| 61 | +//GetTestReqID gets TestReqID, Tag 112 |
| 62 | +func (m Heartbeat) GetTestReqID() (v string, err quickfix.MessageRejectError) { |
| 63 | + var f field.TestReqIDField |
| 64 | + if err = m.Get(&f); err == nil { |
| 65 | + v = f.Value() |
| 66 | + } |
| 67 | + return |
| 68 | +} |
| 69 | + |
| 70 | +//HasTestReqID returns true if TestReqID is present, Tag 112 |
| 71 | +func (m Heartbeat) HasTestReqID() bool { |
| 72 | + return m.Has(tag.TestReqID) |
| 73 | +} |
0 commit comments