price pipeline
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
d7ec1fb355
commit
d9581d7f7e
16 changed files with 790 additions and 10 deletions
31
internal/store/ticker_cache.go
Normal file
31
internal/store/ticker_cache.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// GetTicker retourne le ticker (ou CoinGecko ID) mis en cache pour un instrument.
|
||||
// Retourne pgx.ErrNoRows si absent.
|
||||
func (s *Store) GetTicker(ctx context.Context, instrumentID int32) (string, error) {
|
||||
var ticker string
|
||||
err := s.pool.QueryRow(ctx,
|
||||
`SELECT ticker FROM instrument_ticker_cache WHERE instrument_id = $1`,
|
||||
instrumentID).Scan(&ticker)
|
||||
return ticker, err
|
||||
}
|
||||
|
||||
// UpsertTicker met à jour ou insère le ticker pour un instrument.
|
||||
func (s *Store) UpsertTicker(ctx context.Context, instrumentID int32, ticker string) error {
|
||||
_, err := s.pool.Exec(ctx,
|
||||
`INSERT INTO instrument_ticker_cache (instrument_id, ticker, fetched_at)
|
||||
VALUES ($1, $2, NOW())
|
||||
ON CONFLICT (instrument_id) DO UPDATE SET ticker = EXCLUDED.ticker, fetched_at = NOW()`,
|
||||
instrumentID, ticker)
|
||||
return err
|
||||
}
|
||||
|
||||
func isNotFound(err error) bool {
|
||||
return err == pgx.ErrNoRows
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue