Skip to content

Commit

Permalink
Implement Bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Dec 21, 2024
1 parent bc6cd32 commit f010a28
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 0 additions & 1 deletion itch/5.0/order_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (o OrderAdd) Type() uint8 {

func (o OrderAdd) Bytes() []byte {
data := make([]byte, orderAddSize)
// TODO: implement

data[0] = MESSAGE_ORDER_ADD
binary.BigEndian.PutUint16(data[1:3], o.StockLocate)
Expand Down
21 changes: 20 additions & 1 deletion itch/5.0/participant_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,26 @@ func (p ParticipantPosition) Type() uint8 {

func (p ParticipantPosition) Bytes() []byte {
data := make([]byte, participantPositionSize)
// TODO: implement

data[0] = MESSAGE_PARTICIPANT_POSITION
binary.BigEndian.PutUint16(data[1:3], p.StockLocate)

// Order of these fields are important. We write timestamp to 3:11 first to let us write a uint64, then overwrite 3:5 with tracking number
binary.BigEndian.PutUint64(data[3:11], uint64(p.Timestamp.Nanoseconds()))
binary.BigEndian.PutUint16(data[3:5], p.TrackingNumber)

copy(data[11:15], []byte(fmt.Sprintf("%-4s", p.Mpid)))
copy(data[15:23], []byte(fmt.Sprintf("%-8s", p.Stock)))

if p.PrimaryMM {
data[23] = 'Y'
} else {
data[23] = 'N'
}

data[24] = byte(p.Mode)
data[25] = byte(p.State)

return data
}

Expand Down
13 changes: 13 additions & 0 deletions itch/5.0/stock_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ func (s StockDirectory) Bytes() []byte {
data[29] = 'T'
}

data[30] = []byte(s.ShortSaleThresholdIndicator)[0]
data[31] = []byte(s.IpoFlag)[0]
data[32] = []byte(s.LuldReferencePriceTier)[0]
data[33] = []byte(s.EtpFlag)[0]

binary.BigEndian.PutUint32(data[34:38], s.EtpLeverageFactor)

if s.InverseIndicator {
data[38] = 'Y'
} else {
data[38] = 'N'
}

return data
}

Expand Down

0 comments on commit f010a28

Please sign in to comment.