The price_history table stores historical hourly price and volume data going back years. This is your time-series data for long-term trend analysis, similar to OHLC (Open-High-Low-Close) stock data.Data Source:pricehistory API endpointUpdate Frequency: HourlyUse Case: Long-term trend analysis, price forecasting, volatility studiesAuthentication Required: Yes (Steam session cookies)
This endpoint requires Steam session cookies (sessionid and steamLoginSecure) in your .env file.
Default storage in the main SQLite database.Pros: Simple setup, no additional dependenciesCons: Less optimized for time-series queries, no automatic compression
PostgreSQL extension optimized for time-series data.Pros:
-- Unique constraint to prevent duplicatesUNIQUE(market_hash_name, time)-- Performance indexesCREATE INDEX idx_history_item_time ON price_history(market_hash_name, time DESC);CREATE INDEX idx_history_timestamp ON price_history(time DESC);
SELECT date(time) AS day, AVG(price) AS avg_price, SUM(volume) AS total_volumeFROM price_historyWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-30 days')GROUP BY date(time)ORDER BY day DESC;
WITH avg_price AS ( SELECT AVG(price) AS mean FROM price_history WHERE market_hash_name = 'AK-47 | Redline (Field-Tested)')SELECT time, price, volume, (price - mean) / mean * 100 AS spike_pctFROM price_history, avg_priceWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND price > mean * 1.2ORDER BY time DESC;
SELECT market_hash_name, MIN(price) AS low, MAX(price) AS high, MAX(price) - MIN(price) AS price_range, (MAX(price) - MIN(price)) / AVG(price) * 100 AS volatility_pctFROM price_historyWHERE time > datetime('now', '-24 hours')GROUP BY market_hash_nameORDER BY volatility_pct DESC;
SELECT strftime('%Y-W%W', time) AS week, AVG(price) AS avg_price, MIN(price) AS min_price, MAX(price) AS max_price, SUM(volume) AS total_volumeFROM price_historyWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-90 days')GROUP BY strftime('%Y-W%W', time)ORDER BY week DESC;
SELECT time, price, AVG(price) OVER ( ORDER BY time ROWS BETWEEN 167 PRECEDING AND CURRENT ROW ) AS sma_7dayFROM price_historyWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-30 days')ORDER BY time DESC;
Moving average uses 168 hours (7 days × 24 hours) of data.
The system intelligently handles incremental updates:
First Run: Inserts all available historical data (can be years)
Subsequent Runs: Only inserts new data points since last fetch
Duplicate Prevention:ON CONFLICT DO NOTHING prevents duplicate entries
# From SQLinserts.py# Only inserts data AFTER the most recent timestamplast_timestamp = await conn.fetchval( "SELECT MAX(time) FROM price_history WHERE market_hash_name = $1", market_hash_name)
To enable TimescaleDB storage, provide the connection string:
from src.SQLinserts import SQLinsertsasync with SQLinserts( sqlite_path="data/market_data.db", timescale_dsn="postgresql://user:pass@localhost/cs2market", timescale_pool_min=10, timescale_pool_max=100) as db: await db.store_data(price_history_data, item_config)