Include latest and earliest record times in state #34

Merged
natercio merged 2 commits from state-time-boundaries into main 2026-10-12 23:09:40 +01:00
2 changed files with 22 additions and 6 deletions
Showing only changes of commit 79151422b0 - Show all commits

No files matched your search

+19 -6
View File
@@ -96,11 +96,9 @@ func (fs *JSONStore) Load(ctx context.Context) (map[string]*FillerQueue, error)
// the same directory followed by an atomic rename so a crash mid-write cannot
// leave a half-written state file.
func (fs *JSONStore) Save(ctx context.Context, queue map[string]*FillerQueue) error {
state := State{
Version: StateVersion,
Platform: fs.platform,
Queues: make(map[string][]persistedFiller),
}
queues := make(map[string][]persistedFiller)
latest := time.Time{}
earliest := time.Time{}
for symbol, q := range queue {
if q == nil || q.Len() == 0 {
@@ -119,8 +117,23 @@ func (fs *JSONStore) Save(ctx context.Context, queue map[string]*FillerQueue) er
Price: f.Price(),
Filled: f.Filled(),
})
if f.Timestamp().After(latest) {
latest = f.Timestamp()
}
state.Queues[symbol] = persisted
if f.Timestamp().Before(earliest) || earliest.IsZero() {
earliest = f.Timestamp()
}
}
queues[symbol] = persisted
}
state := State{
Version: StateVersion,
Platform: fs.platform,
Queues: queues,
Latest: latest,
Earliest: earliest,
}
buf := &bytes.Buffer{}
+3
View File
@@ -3,6 +3,7 @@ package internal
import (
"context"
"encoding/json"
"time"
"github.com/shopspring/decimal"
)
@@ -15,6 +16,8 @@ const StateVersion = "2"
type State struct {
Version string `json:"version"`
Platform string `json:"platform"`
Latest time.Time `json:"latest"`
Earliest time.Time `json:"earliest"`
Queues map[string][]persistedFiller `json:"queues"`
}