ninth version
Deploy / Test, build and deploy (push) Failing after 1m6s

This commit is contained in:
2026-06-08 14:25:44 +00:00
parent e8b7d8e27c
commit 20cc8506ad
21 changed files with 847 additions and 148 deletions
+6 -14
View File
@@ -30,7 +30,6 @@ func (l *Loader) SetClock(clock timeutil.Clock) {
func (l Loader) BackfillDaily(ctx context.Context, instruments []domain.Instrument, from, to time.Time) error {
eligible := 0
succeeded := 0
var firstErr error
for _, instrument := range instruments {
if !instrument.Enabled || instrument.Quarantine {
continue
@@ -38,18 +37,15 @@ func (l Loader) BackfillDaily(ctx context.Context, instruments []domain.Instrume
eligible++
candles, err := l.gateway.GetCandles(ctx, instrument.InstrumentUID, "day", from, to)
if err != nil {
if firstErr == nil {
firstErr = fmt.Errorf("load candles %s: %w", instrument.Ticker, err)
}
continue
return fmt.Errorf("load daily candles %s: %w", instrument.Ticker, err)
}
if err := l.repo.UpsertDailyCandles(ctx, candles); err != nil {
return fmt.Errorf("persist candles %s: %w", instrument.Ticker, err)
}
succeeded++
}
if eligible > 0 && succeeded == 0 && firstErr != nil {
return fmt.Errorf("all daily candle loads failed: %w", firstErr)
if eligible > 0 && succeeded == 0 {
return fmt.Errorf("no daily candles loaded for eligible instruments")
}
return nil
}
@@ -57,7 +53,6 @@ func (l Loader) BackfillDaily(ctx context.Context, instruments []domain.Instrume
func (l Loader) BackfillMinute(ctx context.Context, instruments []domain.Instrument, from, to time.Time) error {
eligible := 0
succeeded := 0
var firstErr error
for _, instrument := range instruments {
if !instrument.Enabled || instrument.Quarantine {
continue
@@ -65,18 +60,15 @@ func (l Loader) BackfillMinute(ctx context.Context, instruments []domain.Instrum
eligible++
candles, err := l.gateway.GetCandles(ctx, instrument.InstrumentUID, "minute", from, to)
if err != nil {
if firstErr == nil {
firstErr = fmt.Errorf("load minute candles %s: %w", instrument.Ticker, err)
}
continue
return fmt.Errorf("load minute candles %s: %w", instrument.Ticker, err)
}
if err := l.repo.UpsertMinuteCandles(ctx, candles); err != nil {
return fmt.Errorf("persist minute candles %s: %w", instrument.Ticker, err)
}
succeeded++
}
if eligible > 0 && succeeded == 0 && firstErr != nil {
return fmt.Errorf("all minute candle loads failed: %w", firstErr)
if eligible > 0 && succeeded == 0 {
return fmt.Errorf("no minute candles loaded for eligible instruments")
}
return nil
}
+44
View File
@@ -2,6 +2,7 @@ package marketdata
import (
"context"
"errors"
"strings"
"testing"
"time"
@@ -9,6 +10,7 @@ import (
"github.com/shopspring/decimal"
"overnight-trading-bot/internal/domain"
"overnight-trading-bot/internal/testutil"
"overnight-trading-bot/internal/tinvest"
)
@@ -41,3 +43,45 @@ func TestLatestQuoteUsesExchangeTimestampForFreshness(t *testing.T) {
t.Fatalf("LatestQuote err=%v, want stale exchange timestamp rejection", err)
}
}
func TestBackfillDailyFailsOnAnyEligibleInstrumentError(t *testing.T) {
ctx := context.Background()
gateway := tinvest.NewFakeGateway()
repo := testutil.NewMemoryRepository()
gateway.Candles["ok"] = []domain.Candle{{
InstrumentUID: "ok",
TradeDate: time.Date(2026, 6, 8, 0, 0, 0, 0, time.UTC),
Close: decimal.NewFromInt(100),
}}
gateway.CandleErrors["bad"] = errors.New("candles unavailable")
loader := NewLoader(repo, gateway)
err := loader.BackfillDaily(ctx, []domain.Instrument{
{InstrumentUID: "ok", Ticker: "OK", Enabled: true},
{InstrumentUID: "bad", Ticker: "BAD", Enabled: true},
}, time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC), time.Date(2026, 6, 8, 0, 0, 0, 0, time.UTC))
if err == nil {
t.Fatal("expected per-instrument backfill error")
}
}
func TestBackfillMinuteFailsOnAnyEligibleInstrumentError(t *testing.T) {
ctx := context.Background()
gateway := tinvest.NewFakeGateway()
repo := testutil.NewMemoryRepository()
gateway.Candles["ok"] = []domain.Candle{{
InstrumentUID: "ok",
TradeDate: time.Date(2026, 6, 8, 18, 10, 0, 0, time.UTC),
Close: decimal.NewFromInt(100),
}}
gateway.CandleErrors["bad"] = errors.New("minute candles unavailable")
loader := NewLoader(repo, gateway)
err := loader.BackfillMinute(ctx, []domain.Instrument{
{InstrumentUID: "ok", Ticker: "OK", Enabled: true},
{InstrumentUID: "bad", Ticker: "BAD", Enabled: true},
}, time.Date(2026, 6, 8, 18, 0, 0, 0, time.UTC), time.Date(2026, 6, 8, 19, 0, 0, 0, time.UTC))
if err == nil {
t.Fatal("expected per-instrument minute backfill error")
}
}