Skip to content

Commit eb432cc

Browse files
authored
Merge pull request #184 from cbusbey/gen_header_beginstring
Gen header beginstring
2 parents 1e65673 + 7c3e305 commit eb432cc

File tree

584 files changed

+635
-576
lines changed

Some content is hidden

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

584 files changed

+635
-576
lines changed

cmd/generate-fix/generate-fix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func genHeader(pkg string, spec *datadictionary.DataDictionary) {
5959
Package: pkg,
6060
Name: "Header",
6161
MessageDef: spec.Header,
62+
FIXSpec: spec,
6263
}
6364
if err := internal.HeaderTemplate.Execute(writer, c); err != nil {
6465
errors <- err

cmd/generate-fix/internal/template_helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ func requiredFields(m *datadictionary.MessageDef) (required []*datadictionary.Fi
171171
return
172172
}
173173

174+
func beginString(spec *datadictionary.DataDictionary) string {
175+
if spec.FIXType == "FIXT" || spec.Major == 5 {
176+
return "FIXT.1.1"
177+
}
178+
179+
return fmt.Sprintf("FIX.%v.%v", spec.Major, spec.Minor)
180+
}
181+
174182
func routerBeginString(spec *datadictionary.DataDictionary) (routerBeginString string) {
175183
switch {
176184
case spec.FIXType == "FIXT":

cmd/generate-fix/internal/templates.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
tmplFuncs := template.FuncMap{
1919
"toLower": strings.ToLower,
2020
"requiredFields": requiredFields,
21+
"beginString": beginString,
2122
"routerBeginString": routerBeginString,
2223
"importRootPath": getImportPathRoot,
2324
"quickfixType": quickfixType,
@@ -146,6 +147,13 @@ type Header struct {
146147
quickfix.Header
147148
}
148149
150+
//NewHeader returns a new, initialized Header instance
151+
func NewHeader() (h Header) {
152+
h.Init()
153+
h.SetBeginString("{{ beginString .FIXSpec }}")
154+
return
155+
}
156+
149157
{{ template "setters" .}}
150158
{{ template "getters" . }}
151159
{{ template "hasers" . }}
@@ -222,7 +230,7 @@ func (m {{ .Name }}) ToMessage() quickfix.Message {
222230
{{ $required_fields := requiredFields .MessageDef -}}
223231
//New returns a {{ .Name }} initialized with the required fields for {{ .Name }}
224232
func New({{template "field_args" $required_fields }}) (m {{ .Name }}) {
225-
m.Header.Init()
233+
m.Header = {{ .TransportPackage }}.NewHeader()
226234
m.Init()
227235
m.Trailer.Init()
228236

fix40/advertisement/Advertisement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m Advertisement) ToMessage() quickfix.Message {
4040

4141
//New returns a Advertisement initialized with the required fields for Advertisement
4242
func New(advid field.AdvIdField, advtranstype field.AdvTransTypeField, symbol field.SymbolField, advside field.AdvSideField, shares field.SharesField) (m Advertisement) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/allocation/Allocation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m Allocation) ToMessage() quickfix.Message {
4040

4141
//New returns a Allocation initialized with the required fields for Allocation
4242
func New(allocid field.AllocIDField, alloctranstype field.AllocTransTypeField, side field.SideField, symbol field.SymbolField, shares field.SharesField, avgpx field.AvgPxField, tradedate field.TradeDateField) (m Allocation) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/allocationack/AllocationACK.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m AllocationACK) ToMessage() quickfix.Message {
4040

4141
//New returns a AllocationACK initialized with the required fields for AllocationACK
4242
func New(allocid field.AllocIDField, tradedate field.TradeDateField, allocstatus field.AllocStatusField) (m AllocationACK) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/dontknowtrade/DontKnowTrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m DontKnowTrade) ToMessage() quickfix.Message {
4040

4141
//New returns a DontKnowTrade initialized with the required fields for DontKnowTrade
4242
func New(dkreason field.DKReasonField, symbol field.SymbolField, side field.SideField, orderqty field.OrderQtyField, lastshares field.LastSharesField, lastpx field.LastPxField) (m DontKnowTrade) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/email/Email.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m Email) ToMessage() quickfix.Message {
4040

4141
//New returns a Email initialized with the required fields for Email
4242
func New(emailtype field.EmailTypeField, linesoftext field.LinesOfTextField, text field.TextField) (m Email) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/executionreport/ExecutionReport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m ExecutionReport) ToMessage() quickfix.Message {
4040

4141
//New returns a ExecutionReport initialized with the required fields for ExecutionReport
4242
func New(orderid field.OrderIDField, execid field.ExecIDField, exectranstype field.ExecTransTypeField, ordstatus field.OrdStatusField, symbol field.SymbolField, side field.SideField, orderqty field.OrderQtyField, lastshares field.LastSharesField, lastpx field.LastPxField, cumqty field.CumQtyField, avgpx field.AvgPxField) (m ExecutionReport) {
43-
m.Header.Init()
43+
m.Header = fix40.NewHeader()
4444
m.Init()
4545
m.Trailer.Init()
4646

fix40/header.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ type Header struct {
1313
quickfix.Header
1414
}
1515

16+
//NewHeader returns a new, initialized Header instance
17+
func NewHeader() (h Header) {
18+
h.Init()
19+
h.SetBeginString("FIX.4.0")
20+
return
21+
}
22+
1623
//SetBeginString sets BeginString, Tag 8
1724
func (h Header) SetBeginString(v string) {
1825
h.Set(field.NewBeginString(v))

0 commit comments

Comments
 (0)