forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
136 lines (106 loc) · 3.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"fmt"
"time"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/enum"
"github.com/quickfixgo/quickfix/field"
"github.com/quickfixgo/quickfix/fix40/newordersingle"
"github.com/quickfixgo/quickfix/tag"
)
type NoOrders struct {
quickfix.Group
}
func (m *NoOrders) SetClOrdID(f field.ClOrdIDField) {
m.Set(f)
}
func (m NoOrders) GetClOrdID() (f field.ClOrdIDField, err quickfix.MessageRejectError) {
err = m.Get(&f)
return
}
func (m NoOrders) HasClOrdID() bool {
return m.Has(tag.ClOrdID)
}
type MyRepeatingGroup struct {
*quickfix.RepeatingGroup
}
func NewMyRepeatingGroup() MyRepeatingGroup {
return MyRepeatingGroup{
quickfix.NewRepeatingGroup(tag.Side,
quickfix.GroupTemplate{quickfix.GroupElement(tag.Price)})}
}
type NoOrdersRepeatingGroup struct {
*quickfix.RepeatingGroup
}
func NewNoOrdersRepeatingGroup() NoOrdersRepeatingGroup {
return NoOrdersRepeatingGroup{quickfix.NewRepeatingGroup(tag.NoOrders,
quickfix.GroupTemplate{quickfix.GroupElement(tag.ClOrdID), NewMyRepeatingGroup()})}
}
func (m *NoOrdersRepeatingGroup) Add() NoOrders {
g := m.RepeatingGroup.Add()
return NoOrders{g}
}
func (m NoOrdersRepeatingGroup) Get(i int) NoOrders {
return NoOrders{m.RepeatingGroup.Get(i)}
}
func main() {
fmt.Println("hello world")
msg := quickfix.NewMessage()
group := NewNoOrdersRepeatingGroup()
order1 := group.Add()
order1.SetClOrdID(field.ClOrdIDField{FIXString: "1"})
order2 := group.Add()
order2.SetClOrdID(field.ClOrdIDField{FIXString: "2"})
msg.Header.Set(field.NewBeginString(enum.BeginStringFIX42))
msg.Header.Set(field.NewMsgType(enum.MsgType_NEW_ORDER_CROSS))
msg.Body.SetGroup(group)
b, _ := msg.Build()
fmt.Println(string(b))
m, err := quickfix.ParseMessage(b)
if err != nil {
panic(err)
}
g := NewNoOrdersRepeatingGroup()
m.Body.GetGroup(g)
fmt.Println(g.Len())
clordid1, _ := g.Get(0).GetClOrdID()
clordid2, _ := g.Get(1).GetClOrdID()
fmt.Println(clordid1)
fmt.Println(clordid2)
m, err = quickfix.ParseMessage([]byte("8=FIX.4.29=10835=D34=249=TW52=20160421-14:43:5056=ISLD11=ID21=440=154=138=002000.0055=INTC60=20160421-14:43:5010=004"))
// m, err = quickfix.ParseMessage([]byte("8=FIX.4.29=10835=D34=249=TW52=20160421-14:43:5056=ISLD11=ID21=438=002000.0040=154=255=INTC60=20160421-14:43:5010=005"))
// m, err = quickfix.ParseMessage([]byte("8=FIX.4.29=11835=D34=249=TW52=20160421-14:43:5056=ISLD11=ID21=438=002000.0040=154=255=INTC58=oh hai60=20160421-14:43:5010=218"))
if err != nil {
panic(err)
}
nos := newordersingle.FromMessage(m)
if side, err := nos.GetSide(); err != nil {
panic(err)
} else {
fmt.Printf("Side is %v\n", side)
}
nos.SetSide(enum.Side_SELL)
nos.Set(field.NewText("oh hai"))
m = nos.ToMessage()
b, err = m.Build()
if err != nil {
panic(err)
}
fmt.Println(string(b))
newNos := newordersingle.New(
field.NewClOrdID("1234"),
field.NewHandlInst("1"),
field.NewSymbol("TSLA"),
field.NewSide(enum.Side_BUY),
field.NewOrderQty(100.0),
field.NewOrdType(enum.OrdType_MARKET),
)
//newNos.Set(field.NewTransactTime(time.Now()))
newNos.Set(field.NewTransactTimeNoMillis(time.Now()))
m = newNos.ToMessage()
b, err = m.Build()
if err != nil {
panic(err)
}
fmt.Println(string(b))
}