Live Trading Boundary의 남은 account-sync/audit-trail 작업을 완료해 운영자 headless workflow와 roadmap 완료 후보 상태를 함께 반영한다.
91 lines
3.6 KiB
SQL
91 lines
3.6 KiB
SQL
-- name: UpsertInstrument :exec
|
|
INSERT INTO instruments (id, market, venue, symbol, name, currency, provider_symbols, asset_type)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
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,
|
|
asset_type = EXCLUDED.asset_type;
|
|
|
|
-- name: GetInstrument :one
|
|
SELECT id, market, venue, symbol, name, currency, provider_symbols, asset_type
|
|
FROM instruments
|
|
WHERE id = $1;
|
|
|
|
-- name: ListInstruments :many
|
|
SELECT id, market, venue, symbol, name, currency, provider_symbols, asset_type
|
|
FROM instruments;
|
|
|
|
-- 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;
|
|
|
|
-- 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;
|
|
|
|
-- 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;
|
|
|
|
-- name: GetRun :one
|
|
SELECT id, strategy_id, market, timeframe, from_time, to_time, status, created_at, updated_at
|
|
FROM backtest_runs
|
|
WHERE id = $1;
|
|
|
|
-- name: ListRuns :many
|
|
SELECT id, strategy_id, market, timeframe, from_time, to_time, status, created_at, updated_at
|
|
FROM backtest_runs
|
|
WHERE (@status::text = '' OR status = @status::text)
|
|
ORDER BY created_at DESC, id ASC;
|
|
|
|
-- name: UpsertResult :exec
|
|
INSERT INTO backtest_results (run_id, starting_cash_currency, starting_cash_amount, ending_equity_currency, ending_equity_amount, trades, positions, total_return, trade_count, equity_curve)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
ON CONFLICT (run_id) DO UPDATE SET
|
|
starting_cash_currency = EXCLUDED.starting_cash_currency,
|
|
starting_cash_amount = EXCLUDED.starting_cash_amount,
|
|
ending_equity_currency = EXCLUDED.ending_equity_currency,
|
|
ending_equity_amount = EXCLUDED.ending_equity_amount,
|
|
trades = EXCLUDED.trades,
|
|
positions = EXCLUDED.positions,
|
|
total_return = EXCLUDED.total_return,
|
|
trade_count = EXCLUDED.trade_count,
|
|
equity_curve = EXCLUDED.equity_curve;
|
|
|
|
-- name: GetResult :one
|
|
SELECT run_id, starting_cash_currency, starting_cash_amount, ending_equity_currency, ending_equity_amount, trades, positions, total_return, trade_count, equity_curve
|
|
FROM backtest_results
|
|
WHERE run_id = $1;
|
|
|
|
-- name: AppendLiveAuditEvent :exec
|
|
INSERT INTO live_audit_events (event_id, account_id, broker, order_id, event_type, status, reason, actor, correlation_id, payload, created_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
|
|
|
|
-- name: ListLiveAuditEvents :many
|
|
SELECT event_id, account_id, broker, order_id, event_type, status, reason, actor, correlation_id, payload, created_at
|
|
FROM live_audit_events
|
|
WHERE (@account_id::text = '' OR account_id = @account_id::text)
|
|
AND (@order_id::text = '' OR order_id = @order_id::text)
|
|
AND (@event_type::text = '' OR event_type = @event_type::text)
|
|
ORDER BY created_at ASC;
|