Created
September 22, 2022 11:23
-
-
Save castis/8e35d8d9129558a09a004e715b468c0d to your computer and use it in GitHub Desktop.
Flux OHLCV query
This file contains 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
base = from(bucket: "stocks") | |
|> range(start: _start) | |
|> filter(fn: (r) => r._measurement == "stock" and r.symbol == _symbol) | |
get = (field, fn) => | |
base | |
|> filter(fn: (r) => r._field == field) | |
|> aggregateWindow(every: _every, fn: fn, createEmpty: true) | |
union(tables: [ | |
get(field: "o", fn: first), | |
get(field: "h", fn: max), | |
get(field: "l", fn: min), | |
get(field: "c", fn: last), | |
get(field: "v", fn: sum) | |
]) | |
|> group() | |
|> pivot( | |
rowKey: ["_time"], | |
columnKey: ["_field"], | |
valueColumn: "_value" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment