From 4efc7eb2b78a9d7e58d51bfd8df0c171becfc021 Mon Sep 17 00:00:00 2001 From: Bryan Yue Date: Fri, 7 Nov 2025 06:08:18 -0800 Subject: [PATCH] Overlay Detections on Dashboard --- monitoring/grafana/dashboards/stocks.json | 335 +++++++++++++++++++--- requirements.txt | 1 + 2 files changed, 292 insertions(+), 44 deletions(-) diff --git a/monitoring/grafana/dashboards/stocks.json b/monitoring/grafana/dashboards/stocks.json index 79b7a90..466e139 100644 --- a/monitoring/grafana/dashboards/stocks.json +++ b/monitoring/grafana/dashboards/stocks.json @@ -79,7 +79,88 @@ ] } }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Value" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#4CAF50", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Avg" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#2196F3", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Std Dev" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#FFEB3B", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Detection" + }, + "properties": [ + { + "id": "custom.lineWidth", + "value": 0 + }, + { + "id": "custom.showPoints", + "value": "always" + }, + { + "id": "custom.pointSize", + "value": 6 + }, + { + "id": "custom.drawStyle", + "value": "points" + }, + { + "id": "color", + "value": { + "fixedColor": "#FF1744", + "mode": "fixed" + } + }, + { + "id": "custom.pointSymbol", + "value": "circle" + } + ] + } + ] }, "gridPos": { "h": 8, @@ -115,7 +196,7 @@ "editorMode": "code", "format": "time_series", "rawQuery": true, - "rawSql": "SELECT window_end_time AS \"time\", avg_price_percent_change AS \"avg\", std_dev_price_percent_change AS \"std_dev\"\r\nFROM feed_statistics\r\nWHERE ticker = ${ticker:sqlstring} AND window_length_minutes = ${window:int}", + "rawSql": "SELECT window_end_time AS \"time\", avg_price_percent_change AS \"Avg\", std_dev_price_percent_change AS \"Std Dev\"\r\nFROM feed_statistics\r\nWHERE ticker = ${ticker:sqlstring} AND window_length_minutes = ${window:int}", "refId": "A", "sql": { "columns": [ @@ -171,7 +252,7 @@ "format": "time_series", "hide": false, "rawQuery": true, - "rawSql": "SELECT \"time\", price_percent_change AS \"value\" FROM feed_bars WHERE ticker = ${ticker:sqlstring}", + "rawSql": "SELECT \"time\", price_percent_change AS \"Value\" FROM feed_bars WHERE ticker = ${ticker:sqlstring}", "refId": "B", "sql": { "columns": [ @@ -205,6 +286,23 @@ ] }, "table": "feed_bars" + }, + { + "dataset": "tradestrike_db", + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "timescale-postgres" + }, + "editorMode": "code", + "format": "time_series", + "rawQuery": true, + "rawSql": "SELECT time, price_percent_change AS \"Detection\"\r\nFROM feed_detection\r\nWHERE ticker = ${ticker:sqlstring}\r\n AND window_length_minutes = ${window:int}\r\nORDER BY time;", + "refId": "C", + "sql": { + "columns": [], + "groupBy": [] + }, + "table": "feed_detection" } ], "title": "Price % Change Statistics", @@ -268,7 +366,77 @@ ] } }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Value" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#4CAF50", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Detection" + }, + "properties": [ + { + "id": "custom.lineWidth", + "value": 0 + }, + { + "id": "custom.showPoints", + "value": "always" + }, + { + "id": "custom.pointSize", + "value": 6 + }, + { + "id": "custom.drawStyle", + "value": "points" + }, + { + "id": "color", + "value": { + "fixedColor": "#FF1744", + "mode": "fixed" + } + }, + { + "id": "custom.pointSymbol", + "value": "circle" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "volume_weighted_average_price" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#00BCD4", + "mode": "fixed" + } + }, + { + "id": "custom.lineWidth", + "value": 2 + } + ] + } + ] }, "gridPos": { "h": 8, @@ -304,7 +472,7 @@ "editorMode": "code", "format": "time_series", "rawQuery": true, - "rawSql": "SELECT \"time\", open_price, close_price, high_price, low_price, volume_weighted_average_price\r\nFROM feed_bars\r\nWHERE ticker = ${ticker:sqlstring}", + "rawSql": "SELECT \"time\", close_price AS \"Value\"\r\nFROM feed_bars\r\nWHERE ticker = ${ticker:sqlstring}", "refId": "A", "sql": { "columns": [ @@ -317,15 +485,6 @@ ], "type": "function" }, - { - "parameters": [ - { - "name": "open_price", - "type": "functionParameter" - } - ], - "type": "function" - }, { "parameters": [ { @@ -334,33 +493,6 @@ } ], "type": "function" - }, - { - "parameters": [ - { - "name": "high_price", - "type": "functionParameter" - } - ], - "type": "function" - }, - { - "parameters": [ - { - "name": "low_price", - "type": "functionParameter" - } - ], - "type": "function" - }, - { - "parameters": [ - { - "name": "volume_weighted_average_price", - "type": "functionParameter" - } - ], - "type": "function" } ], "groupBy": [ @@ -373,6 +505,23 @@ ] }, "table": "feed_bars" + }, + { + "dataset": "tradestrike_db", + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "timescale-postgres" + }, + "editorMode": "code", + "format": "time_series", + "rawQuery": true, + "rawSql": "SELECT detection_time AS \"time\", close_price AS \"Detection\"\r\nFROM feed_detection\r\nWHERE ticker = ${ticker:sqlstring}\r\n AND window_length_minutes = ${window:int}\r\nORDER BY detection_time;", + "refId": "B", + "sql": { + "columns": [], + "groupBy": [] + }, + "table": "feed_detection" } ], "title": "Price", @@ -436,7 +585,88 @@ ] } }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Value" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#4CAF50", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Avg" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#2196F3", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Std Dev" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#FFEB3B", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Detection" + }, + "properties": [ + { + "id": "custom.lineWidth", + "value": 0 + }, + { + "id": "custom.showPoints", + "value": "always" + }, + { + "id": "custom.pointSize", + "value": 6 + }, + { + "id": "custom.drawStyle", + "value": "points" + }, + { + "id": "color", + "value": { + "fixedColor": "#FF1744", + "mode": "fixed" + } + }, + { + "id": "custom.pointSymbol", + "value": "circle" + } + ] + } + ] }, "gridPos": { "h": 8, @@ -472,7 +702,7 @@ "editorMode": "code", "format": "time_series", "rawQuery": true, - "rawSql": "SELECT window_end_time AS \"time\", avg_volume, std_dev_volume AS \"std_dev\" FROM feed_statistics WHERE ticker = ${ticker:sqlstring} AND window_length_minutes = ${window:int}", + "rawSql": "SELECT window_end_time AS \"time\", avg_volume AS \"Avg\", std_dev_volume AS \"Std Dev\" FROM feed_statistics WHERE ticker = ${ticker:sqlstring} AND window_length_minutes = ${window:int}", "refId": "A", "sql": { "columns": [ @@ -527,7 +757,7 @@ "format": "time_series", "hide": false, "rawQuery": true, - "rawSql": "SELECT \"time\", volume AS \"value\" FROM feed_bars\r\nWHERE ticker = ${ticker:sqlstring}", + "rawSql": "SELECT \"time\", volume AS \"Value\" FROM feed_bars\r\nWHERE ticker = ${ticker:sqlstring}", "refId": "B", "sql": { "columns": [ @@ -560,6 +790,23 @@ ] }, "table": "feed_bars" + }, + { + "dataset": "tradestrike_db", + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "timescale-postgres" + }, + "editorMode": "code", + "format": "time_series", + "rawQuery": true, + "rawSql": "SELECT time AS \"time\", volume AS \"Detection\"\r\nFROM feed_detection\r\nWHERE ticker = ${ticker:sqlstring}\r\n AND window_length_minutes = ${window:int}\r\nORDER BY time;", + "refId": "C", + "sql": { + "columns": [], + "groupBy": [] + }, + "table": "feed_detection" } ], "title": "Volume Statistics", diff --git a/requirements.txt b/requirements.txt index 0644300..a6a99fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pytest>=8.3.5,<9.0 pytest-cov>=5.0.0,<6.0 ruff>=0.6.9,<0.7 +pre-commit>=4.3.0,<4.4 \ No newline at end of file