Use POST /v1/currency-exchange-quotes to get actual buy price including spread, matching the Strike app. Fee is cached daily to calculate the pre-fee amount from the configured total (default 55 EUR). Store quote_sats in the strike_price DB table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.9 KiB
SQL
53 lines
1.9 KiB
SQL
-- queries for btcdata
|
|
|
|
-- :name insert-binance-price! :! :n
|
|
-- :doc Insert a Binance BTC price
|
|
INSERT INTO binance_price (price) VALUES (:price)
|
|
|
|
-- :name get-latest-binance-price :? :1
|
|
-- :doc Get the most recent Binance BTC price
|
|
SELECT price, recorded_at FROM binance_price ORDER BY id DESC LIMIT 1
|
|
|
|
-- :name upsert-kraken-hour! :! :n
|
|
-- :doc Upsert a Kraken hourly OHLC candle
|
|
INSERT INTO kraken_hour (ts, open, high, low, close, vwap, volume, trade_count)
|
|
VALUES (:ts, :open, :high, :low, :close, :vwap, :volume, :trade-count)
|
|
ON CONFLICT (ts) DO UPDATE
|
|
SET open = EXCLUDED.open,
|
|
high = EXCLUDED.high,
|
|
low = EXCLUDED.low,
|
|
close = EXCLUDED.close,
|
|
vwap = EXCLUDED.vwap,
|
|
volume = EXCLUDED.volume,
|
|
trade_count = EXCLUDED.trade_count
|
|
|
|
-- :name get-latest-kraken-hour :? :1
|
|
-- :doc Get the most recent Kraken hourly candle by timestamp
|
|
SELECT ts, open, high, low, close, vwap, volume, trade_count, created_at
|
|
FROM kraken_hour ORDER BY ts DESC LIMIT 1
|
|
|
|
-- :name upsert-kraken-day! :! :n
|
|
-- :doc Upsert a Kraken daily OHLC candle
|
|
INSERT INTO kraken_day (ts, open, high, low, close, vwap, volume, trade_count)
|
|
VALUES (:ts, :open, :high, :low, :close, :vwap, :volume, :trade-count)
|
|
ON CONFLICT (ts) DO UPDATE
|
|
SET open = EXCLUDED.open,
|
|
high = EXCLUDED.high,
|
|
low = EXCLUDED.low,
|
|
close = EXCLUDED.close,
|
|
vwap = EXCLUDED.vwap,
|
|
volume = EXCLUDED.volume,
|
|
trade_count = EXCLUDED.trade_count
|
|
|
|
-- :name get-latest-kraken-day :? :1
|
|
-- :doc Get the most recent Kraken daily candle by timestamp
|
|
SELECT ts FROM kraken_day ORDER BY ts DESC LIMIT 1
|
|
|
|
-- :name insert-strike-price! :! :n
|
|
-- :doc Insert a Strike ticker snapshot
|
|
INSERT INTO strike_price (rates, quote_sats) VALUES (:rates, :quote-sats)
|
|
|
|
-- :name get-latest-strike-price :? :1
|
|
-- :doc Get the most recent Strike ticker snapshot
|
|
SELECT rates, recorded_at FROM strike_price ORDER BY id DESC LIMIT 1
|