Skip to content

Commit

Permalink
Merge pull request #2 from longbridgeapp/feat/extend_entries
Browse files Browse the repository at this point in the history
add Side field to NoMDEntries of MarketDataSnapshotFullRefresh
  • Loading branch information
level2player authored Jun 28, 2023
2 parents 1bc8a0e + 2fbd14f commit ba2e755
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package marketdatasnapshotfullrefresh

import (
"github.com/shopspring/decimal"
"time"

"github.com/quickfixgo/enum"
"github.com/quickfixgo/field"
"github.com/quickfixgo/fix44"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/tag"
"github.com/shopspring/decimal"
)

//MarketDataSnapshotFullRefresh is the fix44 MarketDataSnapshotFullRefresh type, MsgType = W
Expand Down Expand Up @@ -1186,6 +1186,11 @@ func (m NoMDEntries) SetEncodedText(v string) {
m.Set(field.NewEncodedText(v))
}

//SetSide sets Side, Tag 54
func (m NoMDEntries) SetSide(v enum.Side) {
m.Set(field.NewSide(v))
}

//GetMDEntryType gets MDEntryType, Tag 269
func (m NoMDEntries) GetMDEntryType() (v enum.MDEntryType, err quickfix.MessageRejectError) {
var f field.MDEntryTypeField
Expand Down Expand Up @@ -1483,6 +1488,15 @@ func (m NoMDEntries) GetEncodedText() (v string, err quickfix.MessageRejectError
return
}

//GetSide gets Side, Tag 54
func (m NoMDEntries) GetSide() (v enum.Side, err quickfix.MessageRejectError) {
var f field.SideField
if err = m.Get(&f); err == nil {
v = f.Value()
}
return
}

//HasMDEntryType returns true if MDEntryType is present, Tag 269
func (m NoMDEntries) HasMDEntryType() bool {
return m.Has(tag.MDEntryType)
Expand Down Expand Up @@ -1648,6 +1662,11 @@ func (m NoMDEntries) HasEncodedText() bool {
return m.Has(tag.EncodedText)
}

//HasSide returns true if Side is present, Tag 54
func (m NoMDEntries) HasSide() bool {
return m.Has(tag.Side)
}

//NoMDEntriesRepeatingGroup is a repeating group, Tag 268
type NoMDEntriesRepeatingGroup struct {
*quickfix.RepeatingGroup
Expand All @@ -1657,7 +1676,7 @@ type NoMDEntriesRepeatingGroup struct {
func NewNoMDEntriesRepeatingGroup() NoMDEntriesRepeatingGroup {
return NoMDEntriesRepeatingGroup{
quickfix.NewRepeatingGroup(tag.NoMDEntries,
quickfix.GroupTemplate{quickfix.GroupElement(tag.MDEntryType), quickfix.GroupElement(tag.MDEntryPx), quickfix.GroupElement(tag.Currency), quickfix.GroupElement(tag.MDEntrySize), quickfix.GroupElement(tag.MDEntryDate), quickfix.GroupElement(tag.MDEntryTime), quickfix.GroupElement(tag.TickDirection), quickfix.GroupElement(tag.MDMkt), quickfix.GroupElement(tag.TradingSessionID), quickfix.GroupElement(tag.TradingSessionSubID), quickfix.GroupElement(tag.QuoteCondition), quickfix.GroupElement(tag.TradeCondition), quickfix.GroupElement(tag.MDEntryOriginator), quickfix.GroupElement(tag.LocationID), quickfix.GroupElement(tag.DeskID), quickfix.GroupElement(tag.OpenCloseSettlFlag), quickfix.GroupElement(tag.TimeInForce), quickfix.GroupElement(tag.ExpireDate), quickfix.GroupElement(tag.ExpireTime), quickfix.GroupElement(tag.MinQty), quickfix.GroupElement(tag.ExecInst), quickfix.GroupElement(tag.SellerDays), quickfix.GroupElement(tag.OrderID), quickfix.GroupElement(tag.QuoteEntryID), quickfix.GroupElement(tag.MDEntryBuyer), quickfix.GroupElement(tag.MDEntrySeller), quickfix.GroupElement(tag.NumberOfOrders), quickfix.GroupElement(tag.MDEntryPositionNo), quickfix.GroupElement(tag.Scope), quickfix.GroupElement(tag.PriceDelta), quickfix.GroupElement(tag.Text), quickfix.GroupElement(tag.EncodedTextLen), quickfix.GroupElement(tag.EncodedText)})}
quickfix.GroupTemplate{quickfix.GroupElement(tag.MDEntryType), quickfix.GroupElement(tag.MDEntryPx), quickfix.GroupElement(tag.Currency), quickfix.GroupElement(tag.MDEntrySize), quickfix.GroupElement(tag.MDEntryDate), quickfix.GroupElement(tag.MDEntryTime), quickfix.GroupElement(tag.TickDirection), quickfix.GroupElement(tag.MDMkt), quickfix.GroupElement(tag.TradingSessionID), quickfix.GroupElement(tag.TradingSessionSubID), quickfix.GroupElement(tag.QuoteCondition), quickfix.GroupElement(tag.TradeCondition), quickfix.GroupElement(tag.MDEntryOriginator), quickfix.GroupElement(tag.LocationID), quickfix.GroupElement(tag.DeskID), quickfix.GroupElement(tag.OpenCloseSettlFlag), quickfix.GroupElement(tag.TimeInForce), quickfix.GroupElement(tag.ExpireDate), quickfix.GroupElement(tag.ExpireTime), quickfix.GroupElement(tag.MinQty), quickfix.GroupElement(tag.ExecInst), quickfix.GroupElement(tag.SellerDays), quickfix.GroupElement(tag.OrderID), quickfix.GroupElement(tag.QuoteEntryID), quickfix.GroupElement(tag.MDEntryBuyer), quickfix.GroupElement(tag.MDEntrySeller), quickfix.GroupElement(tag.NumberOfOrders), quickfix.GroupElement(tag.MDEntryPositionNo), quickfix.GroupElement(tag.Scope), quickfix.GroupElement(tag.PriceDelta), quickfix.GroupElement(tag.Text), quickfix.GroupElement(tag.EncodedTextLen), quickfix.GroupElement(tag.EncodedText), quickfix.GroupElement(tag.Side)})}
}

//Add create and append a new NoMDEntries to this group
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package marketdatasnapshotfullrefresh

import (
"bytes"
"testing"

"github.com/quickfixgo/enum"
"github.com/quickfixgo/quickfix"
. "github.com/smartystreets/goconvey/convey"
)

func Test_MarketDataSnapshotFullRefresh(t *testing.T) {
Convey("NoMDEntriesRepeatingGroup", t, func() {
Convey("Group data with side field", func() {
rowData := bytes.NewBufferString("8=FIX.4.49=20835=W34=53949=SenderCompID52=20230628-08:29:47.30056=TargetCompID55=ETHUSD262=staging-1687940826268=2269=2270=1857.1271=2.019273=08:29:47336=CONTINUOUS54=1269=B271=31767.82357346336=CONTINUOUS10=165")

msg := quickfix.NewMessage()
err := quickfix.ParseMessage(msg, rowData)
So(err, ShouldBeNil)

group := NewNoMDEntriesRepeatingGroup()
err = msg.ToMessage().Body.GetGroup(group)
So(err, ShouldBeNil)
So(group.Len(), ShouldEqual, 2)

entry := group.Get(0)
ok := entry.HasSide()
side, err := entry.GetSide()
So(ok, ShouldBeTrue)
So(err, ShouldBeNil)
So(side, ShouldEqual, enum.Side_BUY)
})

Convey("Group data without side field", func() {
rowData := bytes.NewBufferString("8=FIX.4.49=20335=W34=53949=SenderCompID52=20230628-08:29:47.30056=TargetCompID55=ETHUSD262=staging-1687940826268=2269=2270=1857.1271=2.019273=08:29:47336=CONTINUOUS269=B271=31767.82357346336=CONTINUOUS10=165")

msg := quickfix.NewMessage()
err := quickfix.ParseMessage(msg, rowData)
So(err, ShouldBeNil)

group := NewNoMDEntriesRepeatingGroup()
err = msg.ToMessage().Body.GetGroup(group)
So(err, ShouldBeNil)
So(group.Len(), ShouldEqual, 2)

newEntry := group.Add()
ok := newEntry.HasSide()
So(ok, ShouldBeFalse)

newEntry.SetSide(enum.Side_SELL)
ok = newEntry.HasSide()
side, err := newEntry.GetSide()
So(ok, ShouldBeTrue)
So(side, ShouldEqual, enum.Side_SELL)
})
})
}

0 comments on commit ba2e755

Please sign in to comment.