diff --git a/db.py b/db.py index 4c39f1a..e40a739 100644 --- a/db.py +++ b/db.py @@ -14,10 +14,6 @@ db = PostgresqlDatabase( port=getenv('DB_PORT', 5432) ) -def get_time(): - now = datetime.now() - now = now + timedelta(hours=7) - return now class Ticker(Model): id = AutoField() @@ -32,7 +28,7 @@ class Ticker(Model): spread_btc = DoubleField() spread_sats = IntegerField() spread_perc = DoubleField() - date = DateTimeField(default=get_time) + date = DateTimeField(default=datetime.utcnow) class Meta: database = db @@ -41,7 +37,22 @@ class Balance(Model): total = DoubleField() available = DoubleField() currency = CharField() - date = DateTimeField(default=get_time) + date = DateTimeField(default=datetime.utcnow) + + class Meta: + database = db + +class Portfolio(Model): + usd = DoubleField() + btc = DoubleField() + date = DateTimeField(default=datetime.utcnow) + + class Meta: + database = db + +class BitcoinPrice(Model): + price_usd = DoubleField() + date = DateTimeField(default=datetime.utcnow) class Meta: database = db @@ -55,7 +66,7 @@ class Order(Model): uuid = TextField(null=True) active = BooleanField(default=True) cancelled = BooleanField(default=False) - date = DateTimeField(default=get_time) + date = DateTimeField(default=datetime.utcnow) class Meta: database = db @@ -63,9 +74,9 @@ class Order(Model): class Earning(Model): trade_pair = CharField() quantity = DoubleField() - date = DateTimeField(default=get_time) + date = DateTimeField(default=datetime.utcnow) class Meta: database = db -db.create_tables([Ticker, Balance, Order, Earning]) +db.create_tables([Ticker, Balance, Order, Earning, BitcoinPrice, Portfolio]) diff --git a/docker-compose.yaml b/docker-compose.yaml index e132f72..fd61c4d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -20,11 +20,14 @@ services: GF_LOG_LEVEL: "debug" volumes: - grafana:/var/lib/grafana + - ./grafana/grafana.ini:/etc/grafana/grafana.ini:ro + - ./grafana/provisioning:/etc/grafana/provisioning:ro + - ./grafana/dashboards:/var/lib/grafana/dashboards:ro postgres: image: postgres:9.6.15-alpine container_name: trader_postgres ports: - - 5432:5432 + - 127.0.0.1:5432:5432 environment: POSTGRES_PASSWORD: ${DB_PASS} POSTGRES_USER: ${DB_USER} diff --git a/env-example b/env-example index cf7ffaf..bf6c18f 100644 --- a/env-example +++ b/env-example @@ -1,8 +1,8 @@ GRAFANA_PASSWORD=xxxx GRAFANA_URL=localhost:3000 -DB_PASS=yyyyy +DB_PASS=trader DB_USER=trader -DB_NAME=trader_xmr +DB_NAME=trader DB_HOST=127.0.0.1 TO_USER=zzzzzzzzz TO_PASS=vvvvvvvvv diff --git a/grafana/dashboards.yaml b/grafana/dashboards.yaml deleted file mode 100644 index ce46f5a..0000000 --- a/grafana/dashboards.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: 1 - -providers: -- name: 'default' - orgId: 1 - folder: '' - type: file - disableDeletion: true - editable: true - updateIntervalSeconds: 60 - allowUiUpdates: true - options: - path: /var/lib/grafana/dashboards diff --git a/grafana/wow_trader.json b/grafana/dashboards/trader.json similarity index 99% rename from grafana/wow_trader.json rename to grafana/dashboards/trader.json index 3740652..edfd572 100644 --- a/grafana/wow_trader.json +++ b/grafana/dashboards/trader.json @@ -21,7 +21,7 @@ "panels": [ { "content": "\n# Orders\n\nOrders placed on TradeOgre\n\n\n\n", - "datasource": null, + "datasource": "postgres", "gridPos": { "h": 3, "w": 24, @@ -72,7 +72,7 @@ "cacheTimeout": null, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 8, "fill": 1, "fillGradient": 0, @@ -360,7 +360,7 @@ "rgba(237, 129, 40, 0.89)", "#d44a3a" ], - "datasource": null, + "datasource": "postgres", "format": "none", "gauge": { "maxValue": 100, @@ -506,7 +506,7 @@ "rgba(237, 129, 40, 0.89)", "#d44a3a" ], - "datasource": null, + "datasource": "postgres", "format": "none", "gauge": { "maxValue": 100, @@ -643,7 +643,7 @@ }, { "content": "\n# Balances\n\nBalances and trade info of your account.\n\n\n\n", - "datasource": null, + "datasource": "postgres", "gridPos": { "h": 3, "w": 24, @@ -663,7 +663,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 8, "fill": 1, "fillGradient": 0, @@ -884,7 +884,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 8, "fill": 1, "fillGradient": 0, @@ -1104,7 +1104,7 @@ }, { "content": "\n# Markets\n\nGeneral stats and metrics of the $currency markets\n\n\n\n", - "datasource": null, + "datasource": "postgres", "gridPos": { "h": 3, "w": 24, @@ -1124,7 +1124,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 8, "fill": 1, "fillGradient": 0, @@ -1260,7 +1260,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 0, "fill": 1, "fillGradient": 0, @@ -1394,7 +1394,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": 8, "fill": 1, "fillGradient": 0, @@ -1547,7 +1547,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "fill": 1, "fillGradient": 0, "gridPos": { @@ -1678,7 +1678,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "datasource": null, + "datasource": "postgres", "decimals": null, "fill": 1, "fillGradient": 0, diff --git a/grafana/dashboards/wow_trading_desk.json b/grafana/dashboards/wow_trading_desk.json new file mode 100644 index 0000000..c9a7cdc --- /dev/null +++ b/grafana/dashboards/wow_trading_desk.json @@ -0,0 +1,1909 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "decimals": 3, + "format": "currencyUSD", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 0, + "y": 0 + }, + "id": 31, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [], + "hide": true, + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT\n date AS \"time\",\n ((\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n ) * (balance.total * (\n SELECT current_price\n FROM ticker\n WHERE trade_pair = 'BTC-WOW'\n ORDER BY date desc\n LIMIT 1\n ))) as \"WOW Balance\"\nFROM balance\nWHERE\n $__timeFilter(date)\nAND\n currency = 'WOW'\nORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "current_price" + ], + "type": "column" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + }, + { + "format": "time_series", + "group": [], + "hide": true, + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT\n date AS \"time\",\n ((\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n ) * balance.total) as \"BTC Balance\"\nFROM balance\nWHERE\n $__timeFilter(date)\nAND\n currency = 'BTC'\nORDER BY 1,2", + "refId": "B", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + }, + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "WITH btc_price as (\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n),\nwow_balance as (\n SELECT total\n FROM balance\n WHERE $__timeFilter(date) AND currency = 'WOW'\n ORDER BY date desc\n LIMIT 1\n),\nbtc_balance as (\n SELECT total\n FROM balance\n WHERE $__timeFilter(date) AND currency = 'BTC'\n ORDER BY date desc\n LIMIT 1\n),\nwow_price AS (\n SELECT current_price\n FROM ticker\n WHERE trade_pair = 'BTC-WOW'\n ORDER BY date desc\n LIMIT 1\n)\n\nSELECT\n date AS \"time\",\n (btc_price.price_usd * (wow_balance.total * wow_price.current_price)) + (btc_price.price_usd * btc_balance.total) as \"Total Balance\"\nFROM balance, btc_price, wow_balance, btc_balance, wow_price\nWHERE\n $__timeFilter(date)\nORDER BY 1,2", + "refId": "C", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Balance USD", + "type": "singlestat", + "valueFontSize": "150%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "current" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 10, + "w": 20, + "x": 4, + "y": 0 + }, + "hiddenSeries": false, + "id": 33, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "usd", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n date AS \"time\",\n usd\nFROM portfolio\nWHERE\n $__timeFilter(date)\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "usd" + ], + "type": "column" + } + ] + ], + "table": "portfolio", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Portfolio USD", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "currencyUSD", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 3, + "w": 4, + "x": 0, + "y": 4 + }, + "id": 24, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "pluginVersion": "6.5.0", + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeat": null, + "repeatDirection": "h", + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "none" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(price) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'false' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "count" + ], + "type": "aggregate" + }, + { + "params": [ + "price" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'false'" + ], + "type": "expression" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "cancelled", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Completed Orders", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 3, + "w": 4, + "x": 0, + "y": 7 + }, + "id": 25, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "pluginVersion": "6.5.0", + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeatDirection": "h", + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "none" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(id) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'true' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "id" + ], + "type": "column" + }, + { + "params": [ + "count" + ], + "type": "aggregate" + }, + { + "params": [ + "price" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'true'" + ], + "type": "expression" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "cancelled", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Active Orders", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 10 + }, + "hiddenSeries": false, + "id": 12, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "maxPerRow": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": "currency", + "repeatDirection": "h", + "scopedVars": { + "currency": { + "selected": false, + "text": "WOW", + "value": "WOW" + } + }, + "seriesOverrides": [ + { + "alias": "total", + "color": "#FF9830" + }, + { + "alias": "available", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'WOW'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "total" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'WOW'" + ], + "type": "expression" + } + ] + }, + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'WOW'\nGROUP BY 1\nORDER BY 1", + "refId": "B", + "select": [ + [ + { + "params": [ + "available" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "available" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'WOW'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "$currency Balance", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 10 + }, + "hiddenSeries": false, + "id": 29, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "maxPerRow": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": null, + "repeatDirection": "h", + "repeatIteration": 1677520544598, + "repeatPanelId": 12, + "scopedVars": { + "currency": { + "selected": false, + "text": "BTC", + "value": "BTC" + } + }, + "seriesOverrides": [ + { + "alias": "total", + "color": "#FF9830" + }, + { + "alias": "available", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'BTC'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "total" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'BTC'" + ], + "type": "expression" + } + ] + }, + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'BTC'\nGROUP BY 1\nORDER BY 1", + "refId": "B", + "select": [ + [ + { + "params": [ + "available" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "available" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'BTC'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "$currency Balance", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 18 + }, + "hiddenSeries": false, + "id": 2, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": false, + "min": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "bid", + "color": "#C4162A" + }, + { + "alias": "ask", + "color": "#37872D" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(ask) AS \"ask\",\n avg(bid) AS \"bid\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "ask" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "ask" + ], + "type": "alias" + } + ], + [ + { + "params": [ + "bid" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "bid" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Bid / Ask", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 8, + "format": "currencyBTC", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 0, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 18 + }, + "hiddenSeries": false, + "id": 6, + "legend": { + "alignAsTable": true, + "avg": true, + "current": false, + "max": true, + "min": true, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "spread_sats", + "color": "#8F3BB8" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(spread_sats) AS \"spread_sats\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "spread_sats" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "spread_sats" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Spread (sats)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 0, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 25 + }, + "hiddenSeries": false, + "id": 28, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "price_usd", + "color": "#FA6400" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n date AS \"time\",\n price_usd\nFROM bitcoinprice\nWHERE\n $__timeFilter(date)\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "price_usd" + ], + "type": "column" + } + ] + ], + "table": "bitcoinprice", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Bitcoin Price", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "currencyUSD", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 25 + }, + "hiddenSeries": false, + "id": 10, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "hideEmpty": false, + "hideZero": false, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*/", + "color": "#B877D9" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(volume) AS \"volume\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "volume" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "volume" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Volume (BTC)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "currencyBTC", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "decimals": 6, + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "cacheTimeout": null, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 34 + }, + "hiddenSeries": false, + "id": 20, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": false, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pluginVersion": "6.5.0", + "pointradius": 6, + "points": true, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "A Buy Orders", + "color": "#C4162A" + }, + { + "alias": "B Sell Orders", + "color": "#E0B400" + }, + { + "alias": "C Fulfilled Orders", + "color": "rgb(0, 0, 0)", + "pointradius": 3 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + }, + { + "params": [ + "buy" + ], + "type": "column" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Buy Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'true'\nGROUP BY 1, buy,2\nORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Buy Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "buy", + "=", + "'true'" + ], + "type": "expression" + } + ] + }, + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Sell Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'false'\nGROUP BY 1,2\nORDER BY 1,2", + "refId": "B", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Sell Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "buy", + "=", + "'false'" + ], + "type": "expression" + } + ] + }, + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Fulfilled Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n active = 'false'\nGROUP BY 1,2\nORDER BY 1,2", + "refId": "C", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Fulfilled Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Orders", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 8, + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "refresh": "30s", + "schemaVersion": 21, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-12h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "Wownero Trading Desk", + "uid": "1KF3M1DGz", + "version": 10 + } \ No newline at end of file diff --git a/grafana/dashboards/xmr_trading_desk.json b/grafana/dashboards/xmr_trading_desk.json new file mode 100644 index 0000000..0be9d16 --- /dev/null +++ b/grafana/dashboards/xmr_trading_desk.json @@ -0,0 +1,1909 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "decimals": 3, + "format": "currencyUSD", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 0, + "y": 0 + }, + "id": 31, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [], + "hide": true, + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT\n date AS \"time\",\n ((\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n ) * (balance.total * (\n SELECT current_price\n FROM ticker\n WHERE trade_pair = 'BTC-XMR'\n ORDER BY date desc\n LIMIT 1\n ))) as \"XMR Balance\"\nFROM balance\nWHERE\n $__timeFilter(date)\nAND\n currency = 'XMR'\nORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "current_price" + ], + "type": "column" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + }, + { + "format": "time_series", + "group": [], + "hide": true, + "metricColumn": "none", + "rawQuery": true, + "rawSql": "SELECT\n date AS \"time\",\n ((\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n ) * balance.total) as \"BTC Balance\"\nFROM balance\nWHERE\n $__timeFilter(date)\nAND\n currency = 'BTC'\nORDER BY 1,2", + "refId": "B", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + }, + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": true, + "rawSql": "WITH btc_price as (\n SELECT price_usd\n FROM bitcoinprice\n ORDER BY date desc\n LIMIT 1\n),\nxmr_balance as (\n SELECT total\n FROM balance\n WHERE $__timeFilter(date) AND currency = 'XMR'\n ORDER BY date desc\n LIMIT 1\n),\nbtc_balance as (\n SELECT total\n FROM balance\n WHERE $__timeFilter(date) AND currency = 'BTC'\n ORDER BY date desc\n LIMIT 1\n),\nxmr_price AS (\n SELECT current_price\n FROM ticker\n WHERE trade_pair = 'BTC-XMR'\n ORDER BY date desc\n LIMIT 1\n)\n\nSELECT\n date AS \"time\",\n (btc_price.price_usd * (xmr_balance.total * xmr_price.current_price)) + (btc_price.price_usd * btc_balance.total) as \"Total Balance\"\nFROM balance, btc_price, xmr_balance, btc_balance, xmr_price\nWHERE\n $__timeFilter(date)\nORDER BY 1,2", + "refId": "C", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Balance USD", + "type": "singlestat", + "valueFontSize": "150%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "current" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 10, + "w": 20, + "x": 4, + "y": 0 + }, + "hiddenSeries": false, + "id": 33, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "usd", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n date AS \"time\",\n usd\nFROM portfolio\nWHERE\n $__timeFilter(date)\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "usd" + ], + "type": "column" + } + ] + ], + "table": "portfolio", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Portfolio USD", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "currencyUSD", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 3, + "w": 4, + "x": 0, + "y": 4 + }, + "id": 24, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "pluginVersion": "6.5.0", + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeat": null, + "repeatDirection": "h", + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "none" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(price) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'false' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "count" + ], + "type": "aggregate" + }, + { + "params": [ + "price" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'false'" + ], + "type": "expression" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "cancelled", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Completed Orders", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "postgres", + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 3, + "w": 4, + "x": 0, + "y": 7 + }, + "id": 25, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "pluginVersion": "6.5.0", + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeatDirection": "h", + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "none" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(id) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'true' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "id" + ], + "type": "column" + }, + { + "params": [ + "count" + ], + "type": "aggregate" + }, + { + "params": [ + "price" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'true'" + ], + "type": "expression" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "cancelled", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Active Orders", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "total" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 10 + }, + "hiddenSeries": false, + "id": 12, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "maxPerRow": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": "currency", + "repeatDirection": "h", + "scopedVars": { + "currency": { + "selected": false, + "text": "XMR", + "value": "XMR" + } + }, + "seriesOverrides": [ + { + "alias": "total", + "color": "#FF9830" + }, + { + "alias": "available", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'XMR'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "total" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'XMR'" + ], + "type": "expression" + } + ] + }, + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'XMR'\nGROUP BY 1\nORDER BY 1", + "refId": "B", + "select": [ + [ + { + "params": [ + "available" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "available" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'XMR'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "$currency Balance", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 10 + }, + "hiddenSeries": false, + "id": 29, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "maxPerRow": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": null, + "repeatDirection": "h", + "repeatIteration": 1677520544598, + "repeatPanelId": 12, + "scopedVars": { + "currency": { + "selected": false, + "text": "BTC", + "value": "BTC" + } + }, + "seriesOverrides": [ + { + "alias": "total", + "color": "#FF9830" + }, + { + "alias": "available", + "color": "#1F60C4" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'BTC'\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "total" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "total" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'BTC'" + ], + "type": "expression" + } + ] + }, + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = 'BTC'\nGROUP BY 1\nORDER BY 1", + "refId": "B", + "select": [ + [ + { + "params": [ + "available" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "available" + ], + "type": "alias" + } + ] + ], + "table": "balance", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "varchar", + "name": "", + "params": [ + "currency", + "=", + "'BTC'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "$currency Balance", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 18 + }, + "hiddenSeries": false, + "id": 2, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": false, + "min": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "bid", + "color": "#C4162A" + }, + { + "alias": "ask", + "color": "#37872D" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(ask) AS \"ask\",\n avg(bid) AS \"bid\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "ask" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "ask" + ], + "type": "alias" + } + ], + [ + { + "params": [ + "bid" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "bid" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Bid / Ask", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 8, + "format": "currencyBTC", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 0, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 18 + }, + "hiddenSeries": false, + "id": 6, + "legend": { + "alignAsTable": true, + "avg": true, + "current": false, + "max": true, + "min": true, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "spread_sats", + "color": "#8F3BB8" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": true, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(spread_sats) AS \"spread_sats\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "spread_sats" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "spread_sats" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Spread (sats)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 0, + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 25 + }, + "hiddenSeries": false, + "id": 28, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": false, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "price_usd", + "color": "#FA6400" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n date AS \"time\",\n price_usd\nFROM bitcoinprice\nWHERE\n $__timeFilter(date)\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "price_usd" + ], + "type": "column" + } + ] + ], + "table": "bitcoinprice", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Bitcoin Price", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "currencyUSD", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 25 + }, + "hiddenSeries": false, + "id": 10, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "hideEmpty": false, + "hideZero": false, + "max": true, + "min": true, + "rightSide": false, + "show": false, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "nullPointMode": "connected", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/.*/", + "color": "#B877D9" + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "time_series", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "metricColumn": "none", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(volume) AS \"volume\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", + "refId": "A", + "select": [ + [ + { + "params": [ + "volume" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "volume" + ], + "type": "alias" + } + ] + ], + "table": "ticker", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Volume (BTC)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": null, + "format": "currencyBTC", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "decimals": 6, + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "cacheTimeout": null, + "dashLength": 10, + "dashes": false, + "datasource": "postgres", + "decimals": 8, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 34 + }, + "hiddenSeries": false, + "id": 20, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": false, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pluginVersion": "6.5.0", + "pointradius": 6, + "points": true, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "A Buy Orders", + "color": "#C4162A" + }, + { + "alias": "B Sell Orders", + "color": "#E0B400" + }, + { + "alias": "C Fulfilled Orders", + "color": "rgb(0, 0, 0)", + "pointradius": 3 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + }, + { + "params": [ + "buy" + ], + "type": "column" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Buy Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'true'\nGROUP BY 1, buy,2\nORDER BY 1,2", + "refId": "A", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Buy Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "buy", + "=", + "'true'" + ], + "type": "expression" + } + ] + }, + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Sell Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'false'\nGROUP BY 1,2\nORDER BY 1,2", + "refId": "B", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Sell Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "buy", + "=", + "'false'" + ], + "type": "expression" + } + ] + }, + { + "format": "table", + "group": [ + { + "params": [ + "$__interval", + "NULL" + ], + "type": "time" + } + ], + "hide": false, + "metricColumn": "uuid", + "rawQuery": false, + "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Fulfilled Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n active = 'false'\nGROUP BY 1,2\nORDER BY 1,2", + "refId": "C", + "select": [ + [ + { + "params": [ + "price" + ], + "type": "column" + }, + { + "params": [ + "avg" + ], + "type": "aggregate" + }, + { + "params": [ + "Fulfilled Orders" + ], + "type": "alias" + } + ] + ], + "table": "\"order\"", + "timeColumn": "date", + "timeColumnType": "timestamp", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + }, + { + "datatype": "bool", + "name": "", + "params": [ + "active", + "=", + "'false'" + ], + "type": "expression" + } + ] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Orders", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 8, + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "refresh": "30s", + "schemaVersion": 21, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-12h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "Monero Trading Desk", + "uid": "1KF3M1DGz", + "version": 10 + } \ No newline at end of file diff --git a/grafana/grafana.ini b/grafana/grafana.ini new file mode 100644 index 0000000..7faa66c --- /dev/null +++ b/grafana/grafana.ini @@ -0,0 +1,29 @@ +[analytics] +reporting_enabled = false +check_for_updates = false + +[auth] +disable_login_form = true + +[auth.anonymous] +enabled = true +org_role = Admin + +[dashboards] +min_refresh_interval = 1m +default_home_dashboard_path = /var/lib/grafana/dashboards/xmr_trading_desk.json + +[paths] +provisioning = /etc/grafana/provisioning + +[server] +root_url = https://127.0.0.1 +enable_gzip = true +read_timeout = 2m + +[snapshots] +external_enabled = false + +[security] +admin_user = admin +admin_password = admin \ No newline at end of file diff --git a/grafana/prometheus.yaml b/grafana/prometheus.yaml deleted file mode 100644 index 75672ce..0000000 --- a/grafana/prometheus.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: 1 - -datasources: -- name: PostgreSQL - type: postgresql - url: http://prometheus:9090 - access: proxy - isDefault: true - timeInterval: 10s diff --git a/grafana/provisioning/dashboards/all.yaml b/grafana/provisioning/dashboards/all.yaml new file mode 100644 index 0000000..bcbdf2c --- /dev/null +++ b/grafana/provisioning/dashboards/all.yaml @@ -0,0 +1,12 @@ +apiVersion: 1 + +providers: + - name: 'fs' + orgId: 1 + folder: '' + type: 'file' + updateIntervalSeconds: 30 + allowUiUpdates: true + options: + path: '/var/lib/grafana/dashboards' + foldersFromFilesStructure: true \ No newline at end of file diff --git a/grafana/provisioning/datasources/all.yaml b/grafana/provisioning/datasources/all.yaml new file mode 100644 index 0000000..146a560 --- /dev/null +++ b/grafana/provisioning/datasources/all.yaml @@ -0,0 +1,17 @@ +apiVersion: 1 + +datasources: + - name: postgres + type: postgres + url: trader_postgres:5432 + database: trader + user: trader + secureJsonData: + password: "trader" + jsonData: + sslmode: "disable" + maxOpenConns: 0 + maxIdleConns: 2 + connMaxLifetime: 14400 + postgresVersion: 906 + timescaledb: false \ No newline at end of file diff --git a/grafana/xmr_trader.json b/grafana/xmr_trader.json deleted file mode 100644 index 843518a..0000000 --- a/grafana/xmr_trader.json +++ /dev/null @@ -1,2094 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": true, - "gnetId": null, - "graphTooltip": 0, - "id": 2, - "iteration": 1602880809008, - "links": [], - "panels": [ - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 24, - "x": 0, - "y": 0 - }, - "hiddenSeries": false, - "id": 28, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [ - { - "alias": "/.*/", - "color": "#C4162A" - } - ], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "none" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n avg(quantity) AS \"quantity\"\nFROM earning\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "quantity" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "quantity" - ], - "type": "alias" - } - ] - ], - "table": "earning", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Earnings (XMR)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "content": "\n# Orders\n\nOrders placed on TradeOgre\n\n\n\n", - "datasource": "PostgreSQL-xmr", - "gridPos": { - "h": 3, - "w": 24, - "x": 0, - "y": 8 - }, - "id": 22, - "mode": "markdown", - "options": {}, - "targets": [ - { - "format": "time_series", - "group": [], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n date AS \"time\",\n total\nFROM balance\nWHERE\n $__timeFilter(date)\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "total" - ], - "type": "column" - } - ] - ], - "table": "balance", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "timeFrom": null, - "timeShift": null, - "title": "", - "type": "text" - }, - { - "aliasColors": {}, - "bars": false, - "cacheTimeout": null, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 8, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 18, - "x": 0, - "y": 11 - }, - "hiddenSeries": false, - "id": 20, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": false, - "linewidth": 1, - "links": [], - "nullPointMode": "null", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pluginVersion": "6.5.0", - "pointradius": 6, - "points": true, - "renderer": "flot", - "seriesOverrides": [ - { - "alias": "A Buy Orders", - "color": "#C4162A" - }, - { - "alias": "B Sell Orders", - "color": "#E0B400" - }, - { - "alias": "C Fulfilled Orders", - "color": "rgb(251, 251, 251)", - "pointradius": 3 - }, - { - "alias": "D Cancelled Orders", - "color": "rgb(0, 0, 0)", - "pointradius": 3 - } - ], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "table", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - }, - { - "params": [ - "buy" - ], - "type": "column" - } - ], - "hide": false, - "metricColumn": "uuid", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Buy Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'true'\nGROUP BY 1, buy,2\nORDER BY 1,2", - "refId": "A", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "Buy Orders" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "buy", - "=", - "'true'" - ], - "type": "expression" - } - ] - }, - { - "format": "table", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "hide": false, - "metricColumn": "uuid", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Sell Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n buy = 'false'\nGROUP BY 1,2\nORDER BY 1,2", - "refId": "B", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "Sell Orders" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "buy", - "=", - "'false'" - ], - "type": "expression" - } - ] - }, - { - "format": "table", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "hide": false, - "metricColumn": "uuid", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Fulfilled Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n active = 'false' AND\n cancelled = 'false'\nGROUP BY 1,2\nORDER BY 1,2", - "refId": "C", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "Fulfilled Orders" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "active", - "=", - "'false'" - ], - "type": "expression" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "cancelled", - "=", - "'false'" - ], - "type": "expression" - } - ] - }, - { - "format": "table", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "hide": false, - "metricColumn": "uuid", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n uuid AS metric,\n avg(price) AS \"Cancelled Orders\"\nFROM \"order\"\nWHERE\n $__timeFilter(date) AND\n active = 'false' AND\n cancelled = 'true'\nGROUP BY 1,2\nORDER BY 1,2", - "refId": "D", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "Cancelled Orders" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "active", - "=", - "'false'" - ], - "type": "expression" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "cancelled", - "=", - "'true'" - ], - "type": "expression" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Orders", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": 8, - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "cacheTimeout": null, - "colorBackground": false, - "colorPrefix": false, - "colorValue": false, - "colors": [ - "#299c46", - "rgba(237, 129, 40, 0.89)", - "#d44a3a" - ], - "datasource": "PostgreSQL-xmr", - "format": "none", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true - }, - "gridPos": { - "h": 8, - "w": 3, - "x": 18, - "y": 11 - }, - "id": 24, - "interval": null, - "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], - "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "options": {}, - "pluginVersion": "6.5.0", - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "repeat": null, - "repeatDirection": "h", - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false, - "ymax": null, - "ymin": null - }, - "tableColumn": "", - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "none" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(price) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'false' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "count" - ], - "type": "aggregate" - }, - { - "params": [ - "price" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "datatype": "bool", - "name": "", - "params": [ - "active", - "=", - "'false'" - ], - "type": "expression" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "cancelled", - "=", - "'false'" - ], - "type": "expression" - } - ] - } - ], - "thresholds": "", - "timeFrom": null, - "timeShift": null, - "title": "Completed Orders", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "total" - }, - { - "cacheTimeout": null, - "colorBackground": false, - "colorPrefix": false, - "colorValue": false, - "colors": [ - "#299c46", - "rgba(237, 129, 40, 0.89)", - "#d44a3a" - ], - "datasource": "PostgreSQL-xmr", - "format": "none", - "gauge": { - "maxValue": 100, - "minValue": 0, - "show": false, - "thresholdLabels": false, - "thresholdMarkers": true - }, - "gridPos": { - "h": 8, - "w": 3, - "x": 21, - "y": 11 - }, - "id": 25, - "interval": null, - "links": [], - "mappingType": 1, - "mappingTypes": [ - { - "name": "value to text", - "value": 1 - }, - { - "name": "range to text", - "value": 2 - } - ], - "maxDataPoints": 100, - "nullPointMode": "connected", - "nullText": null, - "options": {}, - "pluginVersion": "6.5.0", - "postfix": "", - "postfixFontSize": "50%", - "prefix": "", - "prefixFontSize": "50%", - "rangeMaps": [ - { - "from": "null", - "text": "N/A", - "to": "null" - } - ], - "repeatDirection": "h", - "sparkline": { - "fillColor": "rgba(31, 118, 189, 0.18)", - "full": false, - "lineColor": "rgb(31, 120, 193)", - "show": false, - "ymax": null, - "ymin": null - }, - "tableColumn": "", - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "none" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval),\n count(price) AS \"price\"\nFROM \"order\"\nWHERE\n active = 'true' AND\n cancelled = 'false'\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "price" - ], - "type": "column" - }, - { - "params": [ - "count" - ], - "type": "aggregate" - }, - { - "params": [ - "price" - ], - "type": "alias" - } - ] - ], - "table": "\"order\"", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "datatype": "bool", - "name": "", - "params": [ - "active", - "=", - "'true'" - ], - "type": "expression" - }, - { - "datatype": "bool", - "name": "", - "params": [ - "cancelled", - "=", - "'false'" - ], - "type": "expression" - } - ] - } - ], - "thresholds": "", - "timeFrom": null, - "timeShift": null, - "title": "Active Orders", - "type": "singlestat", - "valueFontSize": "80%", - "valueMaps": [ - { - "op": "=", - "text": "N/A", - "value": "null" - } - ], - "valueName": "total" - }, - { - "content": "\n# Balances\n\nBalances and trade info of your account.\n\n\n\n", - "datasource": "PostgreSQL-xmr", - "gridPos": { - "h": 3, - "w": 24, - "x": 0, - "y": 19 - }, - "id": 17, - "mode": "markdown", - "options": {}, - "timeFrom": null, - "timeShift": null, - "title": "", - "type": "text" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 8, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 22 - }, - "hiddenSeries": false, - "id": 12, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": true, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "maxPerRow": 2, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "repeat": "currency", - "repeatDirection": "h", - "scopedVars": { - "currency": { - "selected": false, - "text": "BTC", - "value": "BTC" - } - }, - "seriesOverrides": [ - { - "alias": "total", - "color": "#FF9830" - }, - { - "alias": "available", - "color": "#1F60C4" - } - ], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = $currency\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "total" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "total" - ], - "type": "alias" - } - ] - ], - "table": "balance", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "varchar", - "name": "", - "params": [ - "currency", - "=", - "$currency" - ], - "type": "expression" - } - ] - }, - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = $currency\nGROUP BY 1\nORDER BY 1", - "refId": "B", - "select": [ - [ - { - "params": [ - "available" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "available" - ], - "type": "alias" - } - ] - ], - "table": "balance", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "varchar", - "name": "", - "params": [ - "currency", - "=", - "$currency" - ], - "type": "expression" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "$currency Balance", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": null, - "format": "none", - "label": null, - "logBase": 1, - "max": null, - "min": "0", - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 8, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 12, - "y": 22 - }, - "hiddenSeries": false, - "id": 29, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": true, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "maxPerRow": 2, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "repeat": null, - "repeatDirection": "h", - "repeatIteration": 1602880809008, - "repeatPanelId": 12, - "scopedVars": { - "currency": { - "selected": false, - "text": "XMR", - "value": "XMR" - } - }, - "seriesOverrides": [ - { - "alias": "total", - "color": "#FF9830" - }, - { - "alias": "available", - "color": "#1F60C4" - } - ], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(total) AS \"total\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = $currency\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "total" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "total" - ], - "type": "alias" - } - ] - ], - "table": "balance", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "varchar", - "name": "", - "params": [ - "currency", - "=", - "$currency" - ], - "type": "expression" - } - ] - }, - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(available) AS \"available\"\nFROM balance\nWHERE\n $__timeFilter(date) AND\n currency = $currency\nGROUP BY 1\nORDER BY 1", - "refId": "B", - "select": [ - [ - { - "params": [ - "available" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "available" - ], - "type": "alias" - } - ] - ], - "table": "balance", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - }, - { - "datatype": "varchar", - "name": "", - "params": [ - "currency", - "=", - "$currency" - ], - "type": "expression" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "$currency Balance", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": null, - "format": "none", - "label": null, - "logBase": 1, - "max": null, - "min": "0", - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "content": "\n# Markets\n\nGeneral stats and metrics of the $currency markets\n\n\n\n", - "datasource": "PostgreSQL-xmr", - "gridPos": { - "h": 3, - "w": 24, - "x": 0, - "y": 30 - }, - "id": 15, - "mode": "markdown", - "options": {}, - "timeFrom": null, - "timeShift": null, - "title": "", - "type": "text" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 8, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 12, - "x": 0, - "y": 33 - }, - "hiddenSeries": false, - "id": 4, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "hideEmpty": false, - "hideZero": false, - "max": false, - "min": false, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(current_price) AS \"current_price\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "current_price" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "current_price" - ], - "type": "alias" - } - ] - ], - "table": "ticker", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Price", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "cumulative" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": 8, - "format": "currencyBTC", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 0, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 12, - "x": 12, - "y": 33 - }, - "hiddenSeries": false, - "id": 6, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": true, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(spread_sats) AS \"spread_sats\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "spread_sats" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "spread_sats" - ], - "type": "alias" - } - ] - ], - "table": "ticker", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Spread (sats)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": 0, - "format": "none", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": 8, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 12, - "x": 0, - "y": 40 - }, - "hiddenSeries": false, - "id": 2, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": false, - "min": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(ask) AS \"ask\",\n avg(bid) AS \"bid\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "ask" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "ask" - ], - "type": "alias" - } - ], - [ - { - "params": [ - "bid" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "bid" - ], - "type": "alias" - } - ] - ], - "table": "ticker", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Bid / Ask", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": 8, - "format": "currencyBTC", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 12, - "x": 12, - "y": 40 - }, - "hiddenSeries": false, - "id": 8, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": true, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(spread_perc) AS \"spread_perc\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "spread_perc" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "spread_perc" - ], - "type": "alias" - } - ] - ], - "table": "ticker", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Spread (%)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "percent", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PostgreSQL-xmr", - "decimals": null, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 24, - "x": 0, - "y": 47 - }, - "hiddenSeries": false, - "id": 10, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "hideEmpty": false, - "hideZero": false, - "max": true, - "min": true, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "dataLinks": [] - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [ - { - "alias": "/.*/", - "color": "#B877D9" - } - ], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "format": "time_series", - "group": [ - { - "params": [ - "$__interval", - "NULL" - ], - "type": "time" - } - ], - "metricColumn": "none", - "rawQuery": false, - "rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,NULL),\n avg(volume) AS \"volume\"\nFROM ticker\nWHERE\n $__timeFilter(date)\nGROUP BY 1\nORDER BY 1", - "refId": "A", - "select": [ - [ - { - "params": [ - "volume" - ], - "type": "column" - }, - { - "params": [ - "avg" - ], - "type": "aggregate" - }, - { - "params": [ - "volume" - ], - "type": "alias" - } - ] - ], - "table": "ticker", - "timeColumn": "date", - "timeColumnType": "timestamp", - "where": [ - { - "name": "$__timeFilter", - "params": [], - "type": "macro" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Volume (BTC)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "decimals": null, - "format": "currencyBTC", - "label": null, - "logBase": 1, - "max": null, - "min": "0", - "show": true - }, - { - "decimals": 6, - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": false - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - } - ], - "refresh": "30s", - "schemaVersion": 21, - "style": "dark", - "tags": [], - "templating": { - "list": [ - { - "allValue": null, - "current": { - "selected": false, - "text": "All", - "value": "$__all" - }, - "datasource": "PostgreSQL-xmr", - "definition": "SELECT currency FROM balance", - "hide": 0, - "includeAll": true, - "label": null, - "multi": false, - "name": "currency", - "options": [], - "query": "SELECT currency FROM balance", - "refresh": 2, - "regex": "/.*/", - "skipUrlSync": false, - "sort": 0, - "tagValuesQuery": "", - "tags": [], - "tagsQuery": "", - "type": "query", - "useTags": false - } - ] - }, - "time": { - "from": "now-3h", - "to": "now" - }, - "timepicker": { - "refresh_intervals": [ - "5s", - "10s", - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ] - }, - "timezone": "", - "title": "XMR", - "uid": "SKVAcXDGk", - "version": 9 -} diff --git a/trade.py b/trade.py index 980d606..1c5a79d 100755 --- a/trade.py +++ b/trade.py @@ -8,7 +8,7 @@ from datetime import datetime from decimal import Decimal from random import uniform from time import sleep -from db import Ticker, Balance, Order, Earning +from db import * from tradeogre import TradeOgre @@ -22,16 +22,17 @@ class Trader(TradeOgre): load_dotenv('.env') satoshi = .00000001 + satoshi_multiplier = getenv('SATOSHI_MULTIPLIER', 10) base_currency = getenv('BASE_CURRENCY', 'BTC') - trade_currency = getenv('TRADE_CURRENCY', 'WOW') + trade_currency = getenv('TRADE_CURRENCY', 'XMR') trade_pair = f'{base_currency}-{trade_currency}' - trade_amount = float(getenv('TRADE_AMOUNT', 200)) - spread_target = float(getenv('SPREAD_TARGET', 4)) + trade_amount = float(getenv('TRADE_AMOUNT', .5)) + spread_target = float(getenv('SPREAD_TARGET', 10)) amount_multiplier = float(getenv('AMOUNT_MULTIPLIER', 1.2)) active_order_limit = float(getenv('ACTIVE_ORDER_LIMIT', 10)) def get_market_data(self): - logging.info(f'[MARKET] Getting market data for trade pair {self.trade_pair}') + logging.info(f'Getting market data for trade pair {self.trade_pair}') res = self.get_trade_pair(self.trade_pair) spread_btc = Decimal(res['ask']) - Decimal(res['bid']) spread_sats = float(spread_btc / Decimal(self.satoshi)) @@ -58,38 +59,40 @@ class Trader(TradeOgre): spread_perc=res['spread_perc'] ) t.save() - logging.info(f'[MARKET] Stored market data as ID {t.id}') + logging.info(f'Stored market data as ID {t.id}') return t - def store_balance(self, currency): - logging.info(f'[BALANCE] Storing balance for currency {currency}') + def store_balance(self, currency, dst): + logging.info(f'Storing balance for currency {currency}') res = self.get_balance(currency) logging.debug(res) b = Balance( currency=currency, total=res['balance'], - available=res['available'] + available=res['available'], + date=dst ) b.save() - logging.info(f'[BALANCE] Stored market data as ID {b.id}') + logging.info(f'Stored market data as ID {b.id}') return b def store_balances(self): + now = datetime.utcnow() for cur in self.base_currency, self.trade_currency: - self.store_balance(cur) + self.store_balance(cur, now) sleep(3) def get_active_orders(self): - logging.info('[ORDERS] Getting active orders in local database') - orders = Order.select().where(Order.active==True, Order.trade_pair==self.trade_pair) + logging.info('Getting active orders in local database') + orders = Order.select().where(Order.active == True, Order.trade_pair == self.trade_pair) logging.debug(f'Found {len(orders)} in database') return orders def reconcile_orders(self): - logging.info('[ORDERS] Reconciling orders on TradeOgre with local database') + logging.info('Reconciling orders on TradeOgre with local database') to_orders = self.get_orders(self.trade_pair) for order in to_orders: - if not Order.filter(Order.uuid==order['uuid']): + if not Order.filter(Order.uuid == order['uuid']): o = Order( trade_pair=order['market'], trade_type='manual', @@ -100,10 +103,10 @@ class Trader(TradeOgre): date=datetime.utcfromtimestamp(order['date']) ) o.save() - logging.info(f'[ORDERS] Saved order {order["uuid"]} to the database') + logging.info(f'Saved order {order["uuid"]} to the database') def update_orders(self): - logging.info('[ORDERS] Updating orders in local database against TradeOgre') + logging.info('Updating orders in local database against TradeOgre') for order in self.get_active_orders(): logging.info(f'Checking order {order.uuid}') o = self.get_order(order.uuid) @@ -116,7 +119,7 @@ class Trader(TradeOgre): def calculate_earnings(self): orders = {'buy': [], 'sell': []} - completed_orders = Order.select().where(Order.cancelled==False, Order.active==False) + completed_orders = Order.select().where(Order.cancelled == False, Order.active == False) for order in completed_orders: if order.buy: type = 'buy' @@ -133,23 +136,42 @@ class Trader(TradeOgre): quantity=orders['total_earnings'] ) e.save() + + def update_portfolio(self): + logging.info('Updating portfolio') + base_balance = Balance.select().where(Balance.currency == self.base_currency).order_by(Balance.date.desc()).first() + trade_balance = Balance.select().where(Balance.currency == self.trade_currency).order_by(Balance.date.desc()).first() + trade_ticker = Ticker.select().where(Ticker.trade_pair == self.trade_pair).order_by(Ticker.date.desc()).first() + btc_price = BitcoinPrice.select().order_by(BitcoinPrice.date.desc()).first() + portfolio_btc = (trade_balance.total * trade_ticker.current_price) + base_balance.total + portfolio_usd = portfolio_btc * btc_price.price_usd + p = Portfolio( + usd=float(portfolio_usd), + btc=float(portfolio_btc) + ) + p.save() + + def update_bitcoin_price(self): + logging.info('Updating Bitcoin price') + btc = BitcoinPrice(price_usd=float(self.get_bitcoin_price())) + btc.save() def start_market_maker(self): - logging.info('[MARKET MAKER] Starting market maker') - latest = Ticker.select().where(Ticker.trade_pair==self.trade_pair).order_by(Ticker.date.desc()).get() + logging.info('Starting market maker') + latest = Ticker.select().where(Ticker.trade_pair == self.trade_pair).order_by(Ticker.date.desc()).get() trade_type = 'market_maker' active_orders = len(self.get_active_orders()) - if active_orders > self.active_order_limit: - logging.info(f'[MARKET MAKER] Too many active orders in place ({active_orders}). Skipping.') + if active_orders >= self.active_order_limit: + logging.info(f'Too many active orders in place ({active_orders}). Skipping.') return False if latest.spread_sats >= self.spread_target: bid_amount = uniform(self.trade_amount, self.trade_amount * self.amount_multiplier) ask_amount = uniform(self.trade_amount, self.trade_amount * self.amount_multiplier) - bid_price = '{:.8f}'.format(latest.bid + self.satoshi) - ask_price = '{:.8f}'.format(latest.ask - self.satoshi) - logging.info(f'[MARKET MAKER] Submitting buy order for {bid_amount} at {bid_price} {self.trade_pair}') + bid_price = '{:.8f}'.format(latest.bid + self.satoshi * self.satoshi_multiplier) + ask_price = '{:.8f}'.format(latest.ask - self.satoshi * self.satoshi_multiplier) + logging.info(f'Submitting buy order for {bid_amount} at {bid_price} {self.trade_pair}') buy = self.submit_order('buy', self.trade_pair, bid_amount, bid_price) logging.debug(buy) if 'uuid' in buy: @@ -169,10 +191,10 @@ class Trader(TradeOgre): active=active ) _bo.save() - logging.info(f'[MARKET MAKER] Stored buy order as ID {_bo.id}') + logging.info(f'Stored buy order as ID {_bo.id}') sleep(3) - logging.info(f'[MARKET MAKER] Submitting sell order for {ask_amount} at {ask_price} {self.trade_pair}') + logging.info(f'Submitting sell order for {ask_amount} at {ask_price} {self.trade_pair}') sell = self.submit_order('sell', self.trade_pair, ask_amount, ask_price) logging.debug(sell) if 'uuid' in sell: @@ -192,13 +214,13 @@ class Trader(TradeOgre): active=active ) _so.save() - logging.info(f'[MARKET MAKER] Stored sell order as ID {_so.id}') + logging.info(f'Stored sell order as ID {_so.id}') else: logging.info(sell) else: logging.info(buy) else: - logging.info(f'[MARKET MAKER] Not enough bid-ask spread ({latest.spread_sats} sats). Skipping market maker.') + logging.info(f'Not enough bid-ask spread ({latest.spread_sats} sats). Skipping market maker.') if __name__ == '__main__': @@ -208,12 +230,14 @@ if __name__ == '__main__': parser.add_argument('--update-orders', action='store_true', help='Update status of orders') parser.add_argument('--market-data', action='store_true', help='Update market data') parser.add_argument('--calculate-earnings', action='store_true', help='Calculate earnings from all trades') + parser.add_argument('--update-bitcoin-price', action='store_true', help='Update Bitcoin price (USD)') parser.add_argument('--run', action='store_true', help='Run continuously') args = parser.parse_args() t = Trader() orders_counter = 0 balances_counter = 0 + bitcoin_counter = 0 if not args.run and args.update_orders: t.reconcile_orders() @@ -224,12 +248,16 @@ if __name__ == '__main__': if not args.run and args.balances: t.store_balances() + t.update_portfolio() if not args.run and args.market_data: t.store_market_data() if not args.run and args.calculate_earnings: t.calculate_earnings() + + if not args.run and args.update_bitcoin_price: + t.update_bitcoin_price() if args.run: while True: @@ -237,6 +265,15 @@ if __name__ == '__main__': t.store_market_data() except Exception as e: logging.info('[ERROR] Unable to store market data!', e) + + # update bitcoin price every 10 runs + if args.update_bitcoin_price: + if bitcoin_counter == 10: + try: + t.update_bitcoin_price() + bitcoin_counter = 0 + except Exception as e: + logging.info('Unable to update Bitcoin price!', e) # update orders every 4 runs if args.update_orders: @@ -254,6 +291,7 @@ if __name__ == '__main__': if balances_counter == 2: try: t.store_balances() + t.update_portfolio() logging.info('[BALANCE] Resetting balances counter') balances_counter = 0 except Exception as e: @@ -268,8 +306,9 @@ if __name__ == '__main__': orders_counter += 1 balances_counter += 1 + bitcoin_counter += 1 # sleep - sleep_time = int(getenv('SLEEP_TIME', 20)) + sleep_time = int(getenv('SLEEP_TIME', 1)) logging.info(f'Sleeping for {sleep_time} seconds') sleep(sleep_time) diff --git a/tradeogre.py b/tradeogre.py index df5c261..9d9566a 100644 --- a/tradeogre.py +++ b/tradeogre.py @@ -48,3 +48,18 @@ class TradeOgre(object): route = f'/account/orders' data = {'market': pair} return self.req(route, 'post', data) + + def get_bitcoin_price(self): + url = 'https://api.coingecko.com/api/v3/coins/bitcoin' + headers = {'accept': 'application/json'} + data = { + 'localization': False, + 'tickers': False, + 'market_data': True, + 'community_data': False, + 'developer_data': False, + 'sparkline': False + } + r = requests_get(url, headers=headers, data=data) + return r.json()['market_data']['current_price']['usd'] +