Include latest and earliest record times in state (#34)
Badges / coveralls (push) Successful in 1m1s

Reviewed-on: #34
Co-authored-by: Natercio Moniz <[email protected]>
This commit was merged in pull request #34.
This commit is contained in:
natercio authored and Natercio Moniz committed 2026-10-12 23:09:39 +01:00
1 parent 47f38fce2b
commit 41b287c804
3 files changed
+47 -11

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()
}
if f.Timestamp().Before(earliest) || earliest.IsZero() {
earliest = f.Timestamp()
}
}
state.Queues[symbol] = persisted
queues[symbol] = persisted
}
state := State{
Version: StateVersion,
Platform: fs.platform,
Queues: queues,
Latest: latest,
Earliest: earliest,
}
buf := &bytes.Buffer{}