Created
October 28, 2017 02:37
-
-
Save kennyxcao/fe8238cd4446b64e9703c9390f582f56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| date_trunc('hour', dt) dt, | |
| ((array_agg(bid ORDER BY dt ASC))[1] + | |
| (array_agg(ask ORDER BY dt ASC))[1])/2 o, | |
| (MAX(bid) + MAX(ask))/2 h, | |
| (MIN(bid) + MIN(ask))/2 l, | |
| ((array_agg(bid ORDER BY dt DESC))[1] + | |
| (array_agg(ask ORDER BY dt DESC))[1])/2 c, | |
| SUM(bid_vol) bid_vol, | |
| SUM(ask_vol) ask_vol, | |
| COUNT(*) ticks | |
| FROM EURUSD | |
| WHERE dt >= '2017-07-01' | |
| GROUP BY date_trunc('hour', dt) | |
| ORDER BY dt DESC | |
| LIMIT 5; | |
| dt | o | h | l | c | bid_vol | ask_vol | ticks | |
| ------------------------+------------------------+------------------------+------------------------+------------------------+-------------+-------------+------- | |
| 2017-10-24 23:00:00-07 | 1.17646000000000000000 | 1.17659500000000000000 | 1.17580500000000000000 | 1.17601500000000000000 | 3305130000 | 3114120000 | 1416 | |
| 2017-10-24 22:00:00-07 | 1.17638000000000000000 | 1.17701000000000000000 | 1.17636500000000000000 | 1.17646500000000000000 | 3559260000 | 3777400000 | 1901 | |
| 2017-10-24 21:00:00-07 | 1.17611500000000000000 | 1.17654500000000000000 | 1.17606500000000000000 | 1.17637500000000000000 | 4837150000 | 4910810000 | 3194 | |
| 2017-10-24 20:00:00-07 | 1.17599500000000000000 | 1.17659000000000000000 | 1.17593500000000000000 | 1.17613000000000000000 | 4272990000 | 5269880000 | 2104 | |
| 2017-10-24 19:00:00-07 | 1.17852500000000000000 | 1.17928500000000000000 | 1.17581500000000000000 | 1.17600500000000000000 | 19965819993 | 19465699999 | 7968 | |
| (5 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment