sending the messages by seqnum

This commit is contained in:
Ramiro Paz
2026-05-15 17:03:54 -03:00
parent 4270284362
commit 0f3ac0dd8d
4 changed files with 29 additions and 11 deletions

View File

@ -598,17 +598,29 @@ func (m *Manager) handleRawMessage(direction string, msg *quickfix.Message) {
m.messagesMu.Unlock()
}
// GetAllMessages returns a snapshot of every FIX application message recorded today,
// sorted ascending by CreatedAt.
func (m *Manager) GetAllMessages() []domain.Message {
// GetAllMessages returns today's FIX application messages with MsgSeqNum greater than
// the caller's last-seen sequence per direction (inSeq for IN, outSeq for OUT), sorted
// ascending by CreatedAt. Passing 0 for either cursor returns all messages on that side.
func (m *Manager) GetAllMessages(inSeq, outSeq int) []domain.Message {
m.messagesMu.RLock()
out := make([]domain.Message, len(m.messages))
copy(out, m.messages)
filtered := make([]domain.Message, 0, len(m.messages))
for _, msg := range m.messages {
switch msg.JMessage.Direction {
case "IN":
if msg.MsgSeqNum > inSeq {
filtered = append(filtered, msg)
}
case "OUT":
if msg.MsgSeqNum > outSeq {
filtered = append(filtered, msg)
}
}
}
m.messagesMu.RUnlock()
sort.Slice(out, func(i, j int) bool { return out[i].CreatedAt.Before(out[j].CreatedAt) })
sort.Slice(filtered, func(i, j int) bool { return filtered[i].CreatedAt.Before(filtered[j].CreatedAt) })
return out
return filtered
}
// loadTodayMessages rebuilds the in-memory message list from today's rows in the DB.