eighth version

This commit is contained in:
2026-06-08 11:55:36 +00:00
parent ebea17b411
commit e8b7d8e27c
15 changed files with 431 additions and 42 deletions
+1 -1
View File
@@ -356,7 +356,7 @@ INSERT INTO candles_minute (
:instrument_uid, :trade_date, :open, :high, :low, :close, :volume_lots, :source, :loaded_at
) ON DUPLICATE KEY UPDATE
open=VALUES(open), high=VALUES(high), low=VALUES(low), close=VALUES(close),
volume_lots=VALUES(volume_lots), source=VALUES(source), loaded_at=VALUES(loaded_at)`, candleRowFromDomain(candle))
volume_lots=VALUES(volume_lots), source=VALUES(source), loaded_at=VALUES(loaded_at)`, minuteCandleRowFromDomain(candle))
if err != nil {
return err
}
+14
View File
@@ -35,6 +35,20 @@ func candleRowFromDomain(candle domain.Candle) candleRow {
}
}
func minuteCandleRowFromDomain(candle domain.Candle) candleRow {
return candleRow{
InstrumentUID: candle.InstrumentUID,
TradeDate: candle.TradeDate.UTC(),
Open: candle.Open,
High: candle.High,
Low: candle.Low,
Close: candle.Close,
VolumeLots: candle.VolumeLots,
Source: candle.Source,
LoadedAt: candle.LoadedAt,
}
}
func (r candleRow) domain() domain.Candle {
return domain.Candle{
InstrumentUID: r.InstrumentUID,
+27
View File
@@ -0,0 +1,27 @@
package mysql
import (
"testing"
"time"
"github.com/shopspring/decimal"
"overnight-trading-bot/internal/domain"
)
func TestMinuteCandleRowPreservesTimestamp(t *testing.T) {
ts := time.Date(2026, 6, 8, 15, 25, 30, 123000000, time.UTC)
row := minuteCandleRowFromDomain(domain.Candle{
InstrumentUID: "uid",
TradeDate: ts,
Open: decimal.NewFromInt(1),
})
if !row.TradeDate.Equal(ts) {
t.Fatalf("minute timestamp=%s, want %s", row.TradeDate, ts)
}
daily := candleRowFromDomain(domain.Candle{InstrumentUID: "uid", TradeDate: ts})
if daily.TradeDate.Equal(ts) || daily.TradeDate.Hour() != 0 || daily.TradeDate.Minute() != 0 {
t.Fatalf("daily timestamp was not truncated to date: %s", daily.TradeDate)
}
}