Skip to content

Commit 5fcdf50

Browse files
committed
Merge pull request quickfixgo#95 from cbusbey/new_message
new for generated messages
2 parents da50cea + e7d3cf9 commit 5fcdf50

File tree

578 files changed

+5427
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

578 files changed

+5427
-15
lines changed

_gen/generate-messages/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func genMessage(msg *datadictionary.MessageDef) string {
8888
return fileOut
8989
}
9090

91+
func genMessageNew(msg *datadictionary.MessageDef) string {
92+
writer := new(bytes.Buffer)
93+
gen.WriteNewMessage(writer, *msg)
94+
return writer.String()
95+
}
96+
9197
func genMessageSetters(msg *datadictionary.MessageDef) string {
9298
writer := new(bytes.Buffer)
9399
if err := gen.WriteFieldSetters(writer, "Message", msg.Parts); err != nil {
@@ -142,6 +148,7 @@ func genMessagePkg(msg *datadictionary.MessageDef) {
142148
fileOut += writer.String()
143149
fileOut += genGroupDeclarations(msg)
144150
fileOut += genMessage(msg)
151+
fileOut += genMessageNew(msg)
145152
fileOut += genMessageSetters(msg)
146153
fileOut += genMessageRoute(msg)
147154

_gen/helpers.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var genTemplate *template.Template
1515

1616
func init() {
1717
tmplFuncs := template.FuncMap{
18-
"fixFieldTypeToGoType": FixFieldTypeToGoType,
18+
"fixFieldTypeToGoType": fixFieldTypeToGoType,
1919
"toLower": strings.ToLower,
2020
"partAsGoType": partAsGoType,
2121
}
@@ -34,14 +34,22 @@ import ({{ range .}}
3434
{{ end}}
3535
3636
37-
{{/* template writes out a constructor for message and component type */}}
38-
{{define "new"}}
37+
{{/* template writes out a constructor for component type */}}
38+
{{define "newcomponent"}}
3939
//New returns an initialized {{.Name}} instance
4040
func New({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
4141
var m {{.Name}}
42-
{{- range .RequiredParts}}
43-
m.Set{{.Name}}({{toLower .Name}})
44-
{{- end}}
42+
{{- template "set_parts" .RequiredParts}}
43+
return &m
44+
}
45+
{{end}}
46+
47+
{{/* template writes out a constructor for message type */}}
48+
{{define "newmessage"}}
49+
//New returns an initialized {{.Name}} instance
50+
func New({{ template "parts_args" .RequiredParts}}) *Message {
51+
var m Message
52+
{{- template "set_parts" .RequiredParts}}
4553
return &m
4654
}
4755
{{end}}
@@ -51,9 +59,7 @@ func New({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
5159
//New{{.Name}} returns an initialized {{.Name}} instance
5260
func New{{.Name}}({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
5361
var m {{.Name}}
54-
{{- range .RequiredParts}}
55-
m.Set{{.Name}}({{toLower .Name}})
56-
{{- end}}
62+
{{- template "set_parts" .RequiredParts}}
5763
return &m
5864
}
5965
{{end}}
@@ -63,6 +69,13 @@ func New{{.Name}}({{ template "parts_args" .RequiredParts}}) *{{.Name}} {
6369
{{- range $index, $field := . }}{{if $index}},{{end}}{{toLower $field.Name}} {{partAsGoType $field}}{{ end }}
6470
{{- end }}
6571
72+
{{/* template sets parts*/}}
73+
{{define "set_parts"}}
74+
{{- range .}}
75+
m.Set{{.Name}}({{toLower .Name}})
76+
{{- end}}
77+
{{- end}}
78+
6679
{{define "fieldSetter"}}
6780
func (m *{{.Receiver}}) Set{{.Name}}(v {{ if .IsGroup}}[]{{.Name}}{{else}}{{fixFieldTypeToGoType .Type}}{{end}}) {
6881
{{- if .IsGroup -}}m.{{.Name}} = v
@@ -78,7 +91,11 @@ func (m *{{.Receiver}}) Set{{.Name}}(v {{toLower .Name}}.{{ .Name}}) {
7891
}
7992

8093
func WriteNewComponent(writer io.Writer, comp datadictionary.ComponentType) error {
81-
return genTemplate.ExecuteTemplate(writer, "new", comp)
94+
return genTemplate.ExecuteTemplate(writer, "newcomponent", comp)
95+
}
96+
97+
func WriteNewMessage(writer io.Writer, msg datadictionary.MessageDef) error {
98+
return genTemplate.ExecuteTemplate(writer, "newmessage", msg)
8299
}
83100

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

167-
if fieldType := FixFieldTypeToGoType(field.Type); fieldType == "time.Time" {
184+
if fieldType := fixFieldTypeToGoType(field.Type); fieldType == "time.Time" {
168185
imports["time"] = nil
169186
}
170187

@@ -228,7 +245,7 @@ func writeFieldDeclaration(fixSpecMajor int, fixSpecMinor int, part datadictiona
228245
return
229246
}
230247

231-
goType := FixFieldTypeToGoType(field.Type)
248+
goType := fixFieldTypeToGoType(field.Type)
232249
fixTags := strconv.Itoa(field.Tag)
233250
if field.Tag == 8 {
234251
if fixSpecMajor == 4 {
@@ -261,10 +278,10 @@ func partAsGoType(part datadictionary.MessagePart) string {
261278
return fmt.Sprintf("[]%v", field.Name())
262279
}
263280

264-
return FixFieldTypeToGoType(field.Type)
281+
return fixFieldTypeToGoType(field.Type)
265282
}
266283

267-
func FixFieldTypeToGoType(fieldType string) string {
284+
func fixFieldTypeToGoType(fieldType string) string {
268285
switch fieldType {
269286
case "MULTIPLESTRINGVALUE", "MULTIPLEVALUESTRING":
270287
fallthrough

datadictionary/datadictionary.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,16 @@ type MessageDef struct {
235235
Fields map[int]*FieldDef
236236
//Parts are the MessageParts of contained in this MessageDef in declaration
237237
//order
238-
Parts []MessagePart
238+
Parts []MessagePart
239+
requiredParts []MessagePart
239240

240241
RequiredTags TagSet
241242
Tags TagSet
242243
}
243244

245+
//RequiredParts returns those parts that are required for this Message
246+
func (m MessageDef) RequiredParts() []MessagePart { return m.requiredParts }
247+
244248
//NewMessageDef returns a pointer to an initialized MessageDef
245249
func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
246250
msg := MessageDef{
@@ -253,6 +257,10 @@ func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
253257
}
254258

255259
for _, part := range parts {
260+
if part.Required() {
261+
msg.requiredParts = append(msg.requiredParts, part)
262+
}
263+
256264
if comp, ok := part.(Component); ok {
257265
for _, f := range comp.Fields() {
258266
msg.Fields[f.Tag] = f

fix40/advertisement/Advertisement.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ type Message struct {
4848
//Marshal converts Message to a quickfix.Message instance
4949
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
5050

51+
//New returns an initialized Advertisement instance
52+
func New(advid int, advtranstype string, symbol string, advside string, shares int) *Message {
53+
var m Message
54+
m.SetAdvId(advid)
55+
m.SetAdvTransType(advtranstype)
56+
m.SetSymbol(symbol)
57+
m.SetAdvSide(advside)
58+
m.SetShares(shares)
59+
return &m
60+
}
61+
5162
func (m *Message) SetAdvId(v int) { m.AdvId = v }
5263
func (m *Message) SetAdvTransType(v string) { m.AdvTransType = v }
5364
func (m *Message) SetAdvRefID(v int) { m.AdvRefID = &v }

fix40/allocation/Allocation.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ type Message struct {
182182
//Marshal converts Message to a quickfix.Message instance
183183
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
184184

185+
//New returns an initialized Allocation instance
186+
func New(allocid int, alloctranstype string, noorders []NoOrders, side string, symbol string, shares int, avgpx float64, tradedate string, noallocs []NoAllocs) *Message {
187+
var m Message
188+
m.SetAllocID(allocid)
189+
m.SetAllocTransType(alloctranstype)
190+
m.SetNoOrders(noorders)
191+
m.SetSide(side)
192+
m.SetSymbol(symbol)
193+
m.SetShares(shares)
194+
m.SetAvgPx(avgpx)
195+
m.SetTradeDate(tradedate)
196+
m.SetNoAllocs(noallocs)
197+
return &m
198+
}
199+
185200
func (m *Message) SetAllocID(v int) { m.AllocID = v }
186201
func (m *Message) SetAllocTransType(v string) { m.AllocTransType = v }
187202
func (m *Message) SetRefAllocID(v int) { m.RefAllocID = &v }

fix40/allocationack/AllocationACK.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ type Message struct {
3434
//Marshal converts Message to a quickfix.Message instance
3535
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3636

37+
//New returns an initialized AllocationACK instance
38+
func New(allocid int, tradedate string, allocstatus int) *Message {
39+
var m Message
40+
m.SetAllocID(allocid)
41+
m.SetTradeDate(tradedate)
42+
m.SetAllocStatus(allocstatus)
43+
return &m
44+
}
45+
3746
func (m *Message) SetClientID(v string) { m.ClientID = &v }
3847
func (m *Message) SetExecBroker(v string) { m.ExecBroker = &v }
3948
func (m *Message) SetAllocID(v int) { m.AllocID = v }

fix40/dontknowtrade/DontKnowTrade.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ type Message struct {
3535
//Marshal converts Message to a quickfix.Message instance
3636
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3737

38+
//New returns an initialized DontKnowTrade instance
39+
func New(dkreason string, symbol string, side string, orderqty int, lastshares int, lastpx float64) *Message {
40+
var m Message
41+
m.SetDKReason(dkreason)
42+
m.SetSymbol(symbol)
43+
m.SetSide(side)
44+
m.SetOrderQty(orderqty)
45+
m.SetLastShares(lastshares)
46+
m.SetLastPx(lastpx)
47+
return &m
48+
}
49+
3850
func (m *Message) SetOrderID(v string) { m.OrderID = &v }
3951
func (m *Message) SetExecID(v int) { m.ExecID = &v }
4052
func (m *Message) SetDKReason(v string) { m.DKReason = v }

fix40/email/Email.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ type Message struct {
3636
//Marshal converts Message to a quickfix.Message instance
3737
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
3838

39+
//New returns an initialized Email instance
40+
func New(emailtype string, linesoftext int, text string) *Message {
41+
var m Message
42+
m.SetEmailType(emailtype)
43+
m.SetLinesOfText(linesoftext)
44+
m.SetText(text)
45+
return &m
46+
}
47+
3948
func (m *Message) SetEmailType(v string) { m.EmailType = v }
4049
func (m *Message) SetOrigTime(v time.Time) { m.OrigTime = &v }
4150
func (m *Message) SetRelatdSym(v string) { m.RelatdSym = &v }

fix40/executionreport/ExecutionReport.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ type Message struct {
128128
//Marshal converts Message to a quickfix.Message instance
129129
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
130130

131+
//New returns an initialized ExecutionReport instance
132+
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 {
133+
var m Message
134+
m.SetOrderID(orderid)
135+
m.SetExecID(execid)
136+
m.SetExecTransType(exectranstype)
137+
m.SetOrdStatus(ordstatus)
138+
m.SetSymbol(symbol)
139+
m.SetSide(side)
140+
m.SetOrderQty(orderqty)
141+
m.SetLastShares(lastshares)
142+
m.SetLastPx(lastpx)
143+
m.SetCumQty(cumqty)
144+
m.SetAvgPx(avgpx)
145+
return &m
146+
}
147+
131148
func (m *Message) SetOrderID(v string) { m.OrderID = v }
132149
func (m *Message) SetClOrdID(v string) { m.ClOrdID = &v }
133150
func (m *Message) SetClientID(v string) { m.ClientID = &v }

fix40/heartbeat/Heartbeat.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ type Message struct {
1919
//Marshal converts Message to a quickfix.Message instance
2020
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2121

22+
//New returns an initialized Heartbeat instance
23+
func New() *Message {
24+
var m Message
25+
return &m
26+
}
27+
2228
func (m *Message) SetTestReqID(v string) { m.TestReqID = &v }
2329

2430
//A RouteOut is the callback type that should be implemented for routing Message

fix40/indicationofinterest/IndicationofInterest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ type Message struct {
5656
//Marshal converts Message to a quickfix.Message instance
5757
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
5858

59+
//New returns an initialized IndicationofInterest instance
60+
func New(ioiid int, ioitranstype string, symbol string, side string, ioishares string) *Message {
61+
var m Message
62+
m.SetIOIid(ioiid)
63+
m.SetIOITransType(ioitranstype)
64+
m.SetSymbol(symbol)
65+
m.SetSide(side)
66+
m.SetIOIShares(ioishares)
67+
return &m
68+
}
69+
5970
func (m *Message) SetIOIid(v int) { m.IOIid = v }
6071
func (m *Message) SetIOITransType(v string) { m.IOITransType = v }
6172
func (m *Message) SetIOIRefID(v int) { m.IOIRefID = &v }

fix40/listcancelrequest/ListCancelRequest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type Message struct {
2323
//Marshal converts Message to a quickfix.Message instance
2424
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2525

26+
//New returns an initialized ListCancelRequest instance
27+
func New(listid string) *Message {
28+
var m Message
29+
m.SetListID(listid)
30+
return &m
31+
}
32+
2633
func (m *Message) SetListID(v string) { m.ListID = v }
2734
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
2835
func (m *Message) SetText(v string) { m.Text = &v }

fix40/listexecute/ListExecute.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type Message struct {
2323
//Marshal converts Message to a quickfix.Message instance
2424
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2525

26+
//New returns an initialized ListExecute instance
27+
func New(listid string) *Message {
28+
var m Message
29+
m.SetListID(listid)
30+
return &m
31+
}
32+
2633
func (m *Message) SetListID(v string) { m.ListID = v }
2734
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
2835
func (m *Message) SetText(v string) { m.Text = &v }

fix40/liststatus/ListStatus.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ type Message struct {
5454
//Marshal converts Message to a quickfix.Message instance
5555
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
5656

57+
//New returns an initialized ListStatus instance
58+
func New(listid string, norpts int, rptseq int, noorders []NoOrders) *Message {
59+
var m Message
60+
m.SetListID(listid)
61+
m.SetNoRpts(norpts)
62+
m.SetRptSeq(rptseq)
63+
m.SetNoOrders(noorders)
64+
return &m
65+
}
66+
5767
func (m *Message) SetListID(v string) { m.ListID = v }
5868
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
5969
func (m *Message) SetNoRpts(v int) { m.NoRpts = v }

fix40/liststatusrequest/ListStatusRequest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type Message struct {
2323
//Marshal converts Message to a quickfix.Message instance
2424
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2525

26+
//New returns an initialized ListStatusRequest instance
27+
func New(listid string) *Message {
28+
var m Message
29+
m.SetListID(listid)
30+
return &m
31+
}
32+
2633
func (m *Message) SetListID(v string) { m.ListID = v }
2734
func (m *Message) SetWaveNo(v string) { m.WaveNo = &v }
2835
func (m *Message) SetText(v string) { m.Text = &v }

fix40/logon/Logon.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ type Message struct {
2525
//Marshal converts Message to a quickfix.Message instance
2626
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2727

28+
//New returns an initialized Logon instance
29+
func New(encryptmethod int, heartbtint int) *Message {
30+
var m Message
31+
m.SetEncryptMethod(encryptmethod)
32+
m.SetHeartBtInt(heartbtint)
33+
return &m
34+
}
35+
2836
func (m *Message) SetEncryptMethod(v int) { m.EncryptMethod = v }
2937
func (m *Message) SetHeartBtInt(v int) { m.HeartBtInt = v }
3038
func (m *Message) SetRawDataLength(v int) { m.RawDataLength = &v }

fix40/logout/Logout.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ type Message struct {
1919
//Marshal converts Message to a quickfix.Message instance
2020
func (m Message) Marshal() quickfix.Message { return quickfix.Marshal(m) }
2121

22+
//New returns an initialized Logout instance
23+
func New() *Message {
24+
var m Message
25+
return &m
26+
}
27+
2228
func (m *Message) SetText(v string) { m.Text = &v }
2329

2430
//A RouteOut is the callback type that should be implemented for routing Message

0 commit comments

Comments
 (0)