- Add worker storage layer with PostgreSQL/sqlc setup - Add migration files for worker backbone schema - Add job runner and built-in jobs implementation - Add Redis key definitions for worker state management - Archive socket-session-loop milestone (completed/renamed) - Update roadmap current.md and foundation-alignment phase - Add socket endpoint integration and runtime smoke tests - Add infra-check, worker-storage-check, worker-storage-gen CLI tools - Update API socket server and config - Add pubspec dependencies and client socket endpoint changes - Add config tests for API and worker services
249 lines
5.4 KiB
Go
249 lines
5.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: queries.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getBars = `-- name: GetBars :many
|
|
SELECT instrument_id, timeframe, timestamp, open, high, low, close, volume
|
|
FROM bars
|
|
WHERE instrument_id = $1 AND timeframe = $2 AND timestamp >= $3 AND timestamp <= $4
|
|
ORDER BY timestamp ASC
|
|
`
|
|
|
|
type GetBarsParams struct {
|
|
InstrumentID string
|
|
Timeframe string
|
|
Timestamp pgtype.Timestamptz
|
|
Timestamp_2 pgtype.Timestamptz
|
|
}
|
|
|
|
func (q *Queries) GetBars(ctx context.Context, arg GetBarsParams) ([]Bar, error) {
|
|
rows, err := q.db.Query(ctx, getBars,
|
|
arg.InstrumentID,
|
|
arg.Timeframe,
|
|
arg.Timestamp,
|
|
arg.Timestamp_2,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Bar
|
|
for rows.Next() {
|
|
var i Bar
|
|
if err := rows.Scan(
|
|
&i.InstrumentID,
|
|
&i.Timeframe,
|
|
&i.Timestamp,
|
|
&i.Open,
|
|
&i.High,
|
|
&i.Low,
|
|
&i.Close,
|
|
&i.Volume,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getInstrument = `-- name: GetInstrument :one
|
|
SELECT id, market, venue, symbol, name, currency, provider_symbols
|
|
FROM instruments
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetInstrument(ctx context.Context, id string) (Instrument, error) {
|
|
row := q.db.QueryRow(ctx, getInstrument, id)
|
|
var i Instrument
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Market,
|
|
&i.Venue,
|
|
&i.Symbol,
|
|
&i.Name,
|
|
&i.Currency,
|
|
&i.ProviderSymbols,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getRun = `-- name: GetRun :one
|
|
SELECT id, strategy_id, market, timeframe, from_time, to_time, status, created_at, updated_at
|
|
FROM backtest_runs
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetRun(ctx context.Context, id string) (BacktestRun, error) {
|
|
row := q.db.QueryRow(ctx, getRun, id)
|
|
var i BacktestRun
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.StrategyID,
|
|
&i.Market,
|
|
&i.Timeframe,
|
|
&i.FromTime,
|
|
&i.ToTime,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listInstruments = `-- name: ListInstruments :many
|
|
SELECT id, market, venue, symbol, name, currency, provider_symbols
|
|
FROM instruments
|
|
`
|
|
|
|
func (q *Queries) ListInstruments(ctx context.Context) ([]Instrument, error) {
|
|
rows, err := q.db.Query(ctx, listInstruments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Instrument
|
|
for rows.Next() {
|
|
var i Instrument
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Market,
|
|
&i.Venue,
|
|
&i.Symbol,
|
|
&i.Name,
|
|
&i.Currency,
|
|
&i.ProviderSymbols,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const upsertBar = `-- name: UpsertBar :exec
|
|
INSERT INTO bars (instrument_id, timeframe, timestamp, open, high, low, close, volume)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
ON CONFLICT (instrument_id, timeframe, timestamp) DO UPDATE SET
|
|
open = EXCLUDED.open,
|
|
high = EXCLUDED.high,
|
|
low = EXCLUDED.low,
|
|
close = EXCLUDED.close,
|
|
volume = EXCLUDED.volume
|
|
`
|
|
|
|
type UpsertBarParams struct {
|
|
InstrumentID string
|
|
Timeframe string
|
|
Timestamp pgtype.Timestamptz
|
|
Open pgtype.Numeric
|
|
High pgtype.Numeric
|
|
Low pgtype.Numeric
|
|
Close pgtype.Numeric
|
|
Volume pgtype.Numeric
|
|
}
|
|
|
|
func (q *Queries) UpsertBar(ctx context.Context, arg UpsertBarParams) error {
|
|
_, err := q.db.Exec(ctx, upsertBar,
|
|
arg.InstrumentID,
|
|
arg.Timeframe,
|
|
arg.Timestamp,
|
|
arg.Open,
|
|
arg.High,
|
|
arg.Low,
|
|
arg.Close,
|
|
arg.Volume,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const upsertInstrument = `-- name: UpsertInstrument :exec
|
|
INSERT INTO instruments (id, market, venue, symbol, name, currency, provider_symbols)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
market = EXCLUDED.market,
|
|
venue = EXCLUDED.venue,
|
|
symbol = EXCLUDED.symbol,
|
|
name = EXCLUDED.name,
|
|
currency = EXCLUDED.currency,
|
|
provider_symbols = EXCLUDED.provider_symbols
|
|
`
|
|
|
|
type UpsertInstrumentParams struct {
|
|
ID string
|
|
Market string
|
|
Venue string
|
|
Symbol string
|
|
Name string
|
|
Currency string
|
|
ProviderSymbols []byte
|
|
}
|
|
|
|
func (q *Queries) UpsertInstrument(ctx context.Context, arg UpsertInstrumentParams) error {
|
|
_, err := q.db.Exec(ctx, upsertInstrument,
|
|
arg.ID,
|
|
arg.Market,
|
|
arg.Venue,
|
|
arg.Symbol,
|
|
arg.Name,
|
|
arg.Currency,
|
|
arg.ProviderSymbols,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const upsertRun = `-- name: UpsertRun :exec
|
|
INSERT INTO backtest_runs (id, strategy_id, market, timeframe, from_time, to_time, status, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
strategy_id = EXCLUDED.strategy_id,
|
|
market = EXCLUDED.market,
|
|
timeframe = EXCLUDED.timeframe,
|
|
from_time = EXCLUDED.from_time,
|
|
to_time = EXCLUDED.to_time,
|
|
status = EXCLUDED.status,
|
|
created_at = EXCLUDED.created_at,
|
|
updated_at = EXCLUDED.updated_at
|
|
`
|
|
|
|
type UpsertRunParams struct {
|
|
ID string
|
|
StrategyID string
|
|
Market string
|
|
Timeframe string
|
|
FromTime pgtype.Timestamptz
|
|
ToTime pgtype.Timestamptz
|
|
Status string
|
|
CreatedAt pgtype.Timestamptz
|
|
UpdatedAt pgtype.Timestamptz
|
|
}
|
|
|
|
func (q *Queries) UpsertRun(ctx context.Context, arg UpsertRunParams) error {
|
|
_, err := q.db.Exec(ctx, upsertRun,
|
|
arg.ID,
|
|
arg.StrategyID,
|
|
arg.Market,
|
|
arg.Timeframe,
|
|
arg.FromTime,
|
|
arg.ToTime,
|
|
arg.Status,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|