Skip to content

Instantly share code, notes, and snippets.

@anddam
Last active December 27, 2015 08:59
Show Gist options
  • Save anddam/7300707 to your computer and use it in GitHub Desktop.
Save anddam/7300707 to your computer and use it in GitHub Desktop.
extract candlestick data via SQL - original suggestion http://textuploader.com/IzDbe
// schema is
// trades(tid integer,amount real,price real,date integer);
SELECT
strftime('%Y-%m-%dT%H:%M:%S', (cast(date as integer)/86400) * 86400, 'unixepoch'),
MIN(date),
MAX(date),
MIN(price),
MAX(price),
SUM(amount)
FROM trades
WHERE date >= strftime('%s', '2013-01-01 00:00')
AND date < strftime('%s', '2013-01-04 00:00')
GROUP BY date/(86400)
ORDER BY date ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment