Files
zeekay 4532862f22 fix: use query-param format for crypto bars (sandbox single path 404s)
Same issue as snapshots — Alpaca sandbox returns 404 for
/v1beta3/crypto/us/{sym}/bars but works with
/v1beta3/crypto/us/bars?symbols={sym}. Also handle the wrapped
response format {"bars":{"BTC/USD":[...]}} vs stock {"bars":[...]}.
2025-12-24 00:57:08 -07:00

36 lines
916 B
Go

// Package db provides PostgreSQL connection management for the broker service.
package db
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
// NewPostgresPool creates a pgxpool connection pool from a database URL.
// The caller is responsible for closing the pool when done.
func NewPostgresPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {
config, err := pgxpool.ParseConfig(databaseURL)
if err != nil {
return nil, fmt.Errorf("parse database URL: %w", err)
}
pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
return nil, fmt.Errorf("create connection pool: %w", err)
}
if err := pool.Ping(ctx); err != nil {
pool.Close()
return nil, fmt.Errorf("ping database: %w", err)
}
return pool, nil
}
// HealthCheck pings the database to verify connectivity.
func HealthCheck(ctx context.Context, pool *pgxpool.Pool) error {
return pool.Ping(ctx)
}