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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions _gen/generate-messages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func genMessage(msg *datadictionary.MessageDef) string {
return fileOut
}

func genMessageNew(msg *datadictionary.MessageDef) string {
writer := new(bytes.Buffer)
gen.WriteNewMessage(writer, *msg)
return writer.String()
}

func genMessageSetters(msg *datadictionary.MessageDef) string {
writer := new(bytes.Buffer)
if err := gen.WriteFieldSetters(writer, "Message", msg.Parts); err != nil {
Expand Down Expand Up @@ -142,6 +148,7 @@ func genMessagePkg(msg *datadictionary.MessageDef) {
fileOut += writer.String()
fileOut += genGroupDeclarations(msg)
fileOut += genMessage(msg)
fileOut += genMessageNew(msg)
fileOut += genMessageSetters(msg)
fileOut += genMessageRoute(msg)

Expand Down
45 changes: 31 additions & 14 deletions _gen/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var genTemplate *template.Template

func init() {
tmplFuncs := template.FuncMap{
"fixFieldTypeToGoType": FixFieldTypeToGoType,
"fixFieldTypeToGoType": fixFieldTypeToGoType,
"toLower": strings.ToLower,
"partAsGoType": partAsGoType,
}
Expand All @@ -34,14 +34,22 @@ import ({{ range .}}
{{ end}}


{{/* template writes out a constructor for message and component type */}}
{{define "new"}}
{{/* template writes out a constructor for component type */}}
{{define "newcomponent"}}
//New returns an initialized {{.Name}} instance
func New({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
var m {{.Name}}
{{- range .RequiredParts}}
m.Set{{.Name}}({{toLower .Name}})
{{- end}}
{{- template "set_parts" .RequiredParts}}
return &m
}
{{end}}

{{/* template writes out a constructor for message type */}}
{{define "newmessage"}}
//New returns an initialized {{.Name}} instance
func New({{ template "parts_args" .RequiredParts}}) *Message {
var m Message
{{- template "set_parts" .RequiredParts}}
return &m
}
{{end}}
Expand All @@ -51,9 +59,7 @@ func New({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
//New{{.Name}} returns an initialized {{.Name}} instance
func New{{.Name}}({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
var m {{.Name}}
{{- range .RequiredParts}}
m.Set{{.Name}}({{toLower .Name}})
{{- end}}
{{- template "set_parts" .RequiredParts}}
return &m
}
{{end}}
Expand All @@ -63,6 +69,13 @@ func New{{.Name}}({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
{{- range $index, $field := . }}{{if $index}},{{end}}{{toLower $field.Name}} {{partAsGoType $field}}{{ end }}
{{- end }}

{{/* template sets parts*/}}
{{define "set_parts"}}
{{- range .}}
m.Set{{.Name}}({{toLower .Name}})
{{- end}}
{{- end}}

{{define "fieldSetter"}}
func (m *{{.Receiver}}) Set{{.Name}}(v {{ if .IsGroup}}[]{{.Name}}{{else}}{{fixFieldTypeToGoType .Type}}{{end}}) {
{{- if .IsGroup -}}m.{{.Name}} = v
Expand All @@ -78,7 +91,11 @@ func (m *{{.Receiver}}) Set{{.Name}}(v {{toLower .Name}}.{{ .Name}}) {
}

func WriteNewComponent(writer io.Writer, comp datadictionary.ComponentType) error {
return genTemplate.ExecuteTemplate(writer, "new", comp)
return genTemplate.ExecuteTemplate(writer, "newcomponent", comp)
}

func WriteNewMessage(writer io.Writer, msg datadictionary.MessageDef) error {
return genTemplate.ExecuteTemplate(writer, "newmessage", msg)
}

//WriteFieldSetters generates setters appropriate for Messages, Components or Repeating Groups
Expand Down Expand Up @@ -164,7 +181,7 @@ func collectRequiredImports(imports map[string]interface{}, pkg string, part dat
panic("Expected FieldDef")
}

if fieldType := FixFieldTypeToGoType(field.Type); fieldType == "time.Time" {
if fieldType := fixFieldTypeToGoType(field.Type); fieldType == "time.Time" {
imports["time"] = nil
}

Expand Down Expand Up @@ -228,7 +245,7 @@ func writeFieldDeclaration(fixSpecMajor int, fixSpecMinor int, part datadictiona
return
}

goType := FixFieldTypeToGoType(field.Type)
goType := fixFieldTypeToGoType(field.Type)
fixTags := strconv.Itoa(field.Tag)
if field.Tag == 8 {
if fixSpecMajor == 4 {
Expand Down Expand Up @@ -261,10 +278,10 @@ func partAsGoType(part datadictionary.MessagePart) string {
return fmt.Sprintf("[]%v", field.Name())
}

return FixFieldTypeToGoType(field.Type)
return fixFieldTypeToGoType(field.Type)
}

func FixFieldTypeToGoType(fieldType string) string {
func fixFieldTypeToGoType(fieldType string) string {
switch fieldType {
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING":
fallthrough
Expand Down
10 changes: 9 additions & 1 deletion datadictionary/datadictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,16 @@ type MessageDef struct {
Fields map[int]*FieldDef
//Parts are the MessageParts of contained in this MessageDef in declaration
//order
Parts []MessagePart
Parts []MessagePart
requiredParts []MessagePart

RequiredTags TagSet
Tags TagSet
}

//RequiredParts returns those parts that are required for this Message
func (m MessageDef) RequiredParts() []MessagePart { return m.requiredParts }

//NewMessageDef returns a pointer to an initialized MessageDef
func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
msg := MessageDef{
Expand All @@ -253,6 +257,10 @@ func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
}

for _, part := range parts {
if part.Required() {
msg.requiredParts = append(msg.requiredParts, part)
}

if comp, ok := part.(Component); ok {
for _, f := range comp.Fields() {
msg.Fields[f.Tag] = f
Expand Down
11 changes: 11 additions & 0 deletions fix40/advertisement/Advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Advertisement instance
func New(advid int, advtranstype string, symbol string, advside string, shares int) *Message {
var m Message
m.SetAdvId(advid)
m.SetAdvTransType(advtranstype)
m.SetSymbol(symbol)
m.SetAdvSide(advside)
m.SetShares(shares)
return &m
}

func (m *Message) SetAdvId(v int) { m.AdvId = v }
func (m *Message) SetAdvTransType(v string) { m.AdvTransType = v }
func (m *Message) SetAdvRefID(v int) { m.AdvRefID = &v }
Expand Down
15 changes: 15 additions & 0 deletions fix40/allocation/Allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Allocation instance
func New(allocid int, alloctranstype string, noorders []NoOrders, side string, symbol string, shares int, avgpx float64, tradedate string, noallocs []NoAllocs) *Message {
var m Message
m.SetAllocID(allocid)
m.SetAllocTransType(alloctranstype)
m.SetNoOrders(noorders)
m.SetSide(side)
m.SetSymbol(symbol)
m.SetShares(shares)
m.SetAvgPx(avgpx)
m.SetTradeDate(tradedate)
m.SetNoAllocs(noallocs)
return &m
}

func (m *Message) SetAllocID(v int) { m.AllocID = v }
func (m *Message) SetAllocTransType(v string) { m.AllocTransType = v }
func (m *Message) SetRefAllocID(v int) { m.RefAllocID = &v }
Expand Down
9 changes: 9 additions & 0 deletions fix40/allocationack/AllocationACK.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized AllocationACK instance
func New(allocid int, tradedate string, allocstatus int) *Message {
var m Message
m.SetAllocID(allocid)
m.SetTradeDate(tradedate)
m.SetAllocStatus(allocstatus)
return &m
}

func (m *Message) SetClientID(v string) { m.ClientID = &v }
func (m *Message) SetExecBroker(v string) { m.ExecBroker = &v }
func (m *Message) SetAllocID(v int) { m.AllocID = v }
Expand Down
12 changes: 12 additions & 0 deletions fix40/dontknowtrade/DontKnowTrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized DontKnowTrade instance
func New(dkreason string, symbol string, side string, orderqty int, lastshares int, lastpx float64) *Message {
var m Message
m.SetDKReason(dkreason)
m.SetSymbol(symbol)
m.SetSide(side)
m.SetOrderQty(orderqty)
m.SetLastShares(lastshares)
m.SetLastPx(lastpx)
return &m
}

func (m *Message) SetOrderID(v string) { m.OrderID = &v }
func (m *Message) SetExecID(v int) { m.ExecID = &v }
func (m *Message) SetDKReason(v string) { m.DKReason = v }
Expand Down
9 changes: 9 additions & 0 deletions fix40/email/Email.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Email instance
func New(emailtype string, linesoftext int, text string) *Message {
var m Message
m.SetEmailType(emailtype)
m.SetLinesOfText(linesoftext)
m.SetText(text)
return &m
}

func (m *Message) SetEmailType(v string) { m.EmailType = v }
func (m *Message) SetOrigTime(v time.Time) { m.OrigTime = &v }
func (m *Message) SetRelatdSym(v string) { m.RelatdSym = &v }
Expand Down
17 changes: 17 additions & 0 deletions fix40/executionreport/ExecutionReport.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized ExecutionReport instance
func New(orderid string, execid int, exectranstype string, ordstatus string, symbol string, side string, orderqty int, lastshares int, lastpx float64, cumqty int, avgpx float64) *Message {
var m Message
m.SetOrderID(orderid)
m.SetExecID(execid)
m.SetExecTransType(exectranstype)
m.SetOrdStatus(ordstatus)
m.SetSymbol(symbol)
m.SetSide(side)
m.SetOrderQty(orderqty)
m.SetLastShares(lastshares)
m.SetLastPx(lastpx)
m.SetCumQty(cumqty)
m.SetAvgPx(avgpx)
return &m
}

func (m *Message) SetOrderID(v string) { m.OrderID = v }
func (m *Message) SetClOrdID(v string) { m.ClOrdID = &v }
func (m *Message) SetClientID(v string) { m.ClientID = &v }
Expand Down
6 changes: 6 additions & 0 deletions fix40/heartbeat/Heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Heartbeat instance
func New() *Message {
var m Message
return &m
}

func (m *Message) SetTestReqID(v string) { m.TestReqID = &v }

//A RouteOut is the callback type that should be implemented for routing Message
Expand Down
11 changes: 11 additions & 0 deletions fix40/indicationofinterest/IndicationofInterest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized IndicationofInterest instance
func New(ioiid int, ioitranstype string, symbol string, side string, ioishares string) *Message {
var m Message
m.SetIOIid(ioiid)
m.SetIOITransType(ioitranstype)
m.SetSymbol(symbol)
m.SetSide(side)
m.SetIOIShares(ioishares)
return &m
}

func (m *Message) SetIOIid(v int) { m.IOIid = v }
func (m *Message) SetIOITransType(v string) { m.IOITransType = v }
func (m *Message) SetIOIRefID(v int) { m.IOIRefID = &v }
Expand Down
7 changes: 7 additions & 0 deletions fix40/listcancelrequest/ListCancelRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized ListCancelRequest instance
func New(listid string) *Message {
var m Message
m.SetListID(listid)
return &m
}

func (m *Message) SetListID(v string) { m.ListID = v }
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
func (m *Message) SetText(v string) { m.Text = &v }
Expand Down
7 changes: 7 additions & 0 deletions fix40/listexecute/ListExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized ListExecute instance
func New(listid string) *Message {
var m Message
m.SetListID(listid)
return &m
}

func (m *Message) SetListID(v string) { m.ListID = v }
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
func (m *Message) SetText(v string) { m.Text = &v }
Expand Down
10 changes: 10 additions & 0 deletions fix40/liststatus/ListStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized ListStatus instance
func New(listid string, norpts int, rptseq int, noorders []NoOrders) *Message {
var m Message
m.SetListID(listid)
m.SetNoRpts(norpts)
m.SetRptSeq(rptseq)
m.SetNoOrders(noorders)
return &m
}

func (m *Message) SetListID(v string) { m.ListID = v }
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
func (m *Message) SetNoRpts(v int) { m.NoRpts = v }
Expand Down
7 changes: 7 additions & 0 deletions fix40/liststatusrequest/ListStatusRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized ListStatusRequest instance
func New(listid string) *Message {
var m Message
m.SetListID(listid)
return &m
}

func (m *Message) SetListID(v string) { m.ListID = v }
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
func (m *Message) SetText(v string) { m.Text = &v }
Expand Down
8 changes: 8 additions & 0 deletions fix40/logon/Logon.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Logon instance
func New(encryptmethod int, heartbtint int) *Message {
var m Message
m.SetEncryptMethod(encryptmethod)
m.SetHeartBtInt(heartbtint)
return &m
}

func (m *Message) SetEncryptMethod(v int) { m.EncryptMethod = v }
func (m *Message) SetHeartBtInt(v int) { m.HeartBtInt = v }
func (m *Message) SetRawDataLength(v int) { m.RawDataLength = &v }
Expand Down
6 changes: 6 additions & 0 deletions fix40/logout/Logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type Message struct {
//Marshal converts Message to a quickfix.Message instance
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }

//New returns an initialized Logout instance
func New() *Message {
var m Message
return &m
}

func (m *Message) SetText(v string) { m.Text = &v }

//A RouteOut is the callback type that should be implemented for routing Message
Expand Down
Loading