deanpowers commited on
Commit
1db0bad
·
1 Parent(s): f98a741

feat: commit pending site changes (sideways/downward/financials/upward pages, widgets, templates)

Browse files
app.py CHANGED
@@ -19,6 +19,18 @@ from modules.stats import log_admin_stat
19
  app = Flask(__name__)
20
  CORS(app, resources={r"/*": {"origins": "*"}})
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  # ---------- Configuration ----------
23
  JOURNAL_FILE = 'trade_journal.csv'
24
  BINGX_API_KEY = os.environ.get('BINGX_API_KEY')
 
19
  app = Flask(__name__)
20
  CORS(app, resources={r"/*": {"origins": "*"}})
21
 
22
+ # Share the login session with subdomains (e.g. scan.blind-monkeys.com) so
23
+ # tools hosted there can recognize logged-in admins. Only widen the cookie
24
+ # domain when the site is reached via a blind-monkeys.com host; on other
25
+ # hosts (e.g. the raw run.app URL) keep the default host-only cookie.
26
+ @app.before_request
27
+ def _session_cookie_domain():
28
+ host = (request.host or "").split(":")[0].lower()
29
+ if host == "blind-monkeys.com" or host.endswith(".blind-monkeys.com"):
30
+ app.config["SESSION_COOKIE_DOMAIN"] = ".blind-monkeys.com"
31
+ else:
32
+ app.config["SESSION_COOKIE_DOMAIN"] = None
33
+
34
  # ---------- Configuration ----------
35
  JOURNAL_FILE = 'trade_journal.csv'
36
  BINGX_API_KEY = os.environ.get('BINGX_API_KEY')
local_app.py CHANGED
@@ -6,7 +6,7 @@ import json
6
  import requests
7
  from flask import Flask, jsonify, send_file, request, send_from_directory, Response
8
  from flask_cors import CORS
9
- from datetime import datetime
10
  import time
11
  import threading
12
  from flask import session, render_template, redirect
@@ -87,6 +87,18 @@ app = Flask(__name__)
87
  app.secret_key = os.environ.get("FLASK_SECRET", "dev-only-secret-change-me")
88
  CORS(app, resources={r"/*": {"origins": "*"}})
89
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # ===================================================================
91
  # GLOBAL LOGIN GATE ??? everything requires login except public endpoints
92
  # ===================================================================
@@ -110,6 +122,22 @@ PUBLIC_PATHS_EXACT = (
110
  '/about/',
111
  '/glossary',
112
  '/glossary/',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  '/robots.txt',
114
  '/sitemap.xml',
115
  '/llms.txt',
@@ -140,6 +168,11 @@ PUBLIC_PATHS_PREFIX = (
140
  '/bot/',
141
  '/api/win-rate',
142
  '/api/bot-pnl',
 
 
 
 
 
143
  '/api/debug/apis',
144
  '/api/debug/users',
145
  '/api/scan',
@@ -154,6 +187,8 @@ PUBLIC_PATHS_PREFIX = (
154
  '/api/price/batch',
155
  '/api/price/enriched',
156
  '/api/diagnostic',
 
 
157
  )
158
 
159
  @app.before_request
@@ -574,6 +609,22 @@ def eth_chart_hourly():
574
  except Exception as e:
575
  return jsonify({"error": str(e)}), 500
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  @app.route('/api/market-regime')
578
  def market_regime():
579
  """Check if ETH has dropped 2% from its 24-hour high"""
@@ -934,6 +985,266 @@ def debug_apis_api():
934
  out[k] = {"error": str(e)[:100]}
935
  return jsonify(out)
936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937
  @app.route('/api/bot-pnl')
938
  def bot_pnl_api():
939
  """Return Bybit bot P&L with 24h/7d/30d/YTD deltas computed from history."""
@@ -947,28 +1258,39 @@ def bot_pnl_api():
947
  snaps = sorted(history.get("snapshots", []), key=lambda x: x.get("updated_at", 0))
948
 
949
  current_bot_id = str(latest.get("bot_id", ""))
 
 
 
 
 
 
 
 
 
 
 
950
 
951
- def _pnl_at(seconds_ago):
952
- """Find closest snapshot to N seconds ago for the CURRENT bot only."""
953
- target = latest.get("updated_at", 0) - seconds_ago
954
- best = None
955
- best_delta = None
956
- for sn in snaps:
957
- if str(sn.get("bot_id", "")) != current_bot_id:
958
- continue # ignore snapshots from other bots
959
- d = abs(sn.get("updated_at", 0) - target)
960
- if best_delta is None or d < best_delta:
961
- best = sn
962
- best_delta = d
963
- # Only return if the snapshot is within ~50% of the target window
964
- # (avoids returning a too-recent snapshot that would inflate the delta)
965
- if best and best_delta is not None and best_delta > (seconds_ago * 0.5):
966
- return best
967
- return best if best and best_delta is not None and best_delta < 3600 else None
968
-
969
- def _delta(seconds_ago):
970
- past = _pnl_at(seconds_ago)
971
- if not past:
972
  return None
973
  try:
974
  now_v = float(latest.get("total_pnl", 0))
@@ -977,24 +1299,6 @@ def bot_pnl_api():
977
  except Exception:
978
  return None
979
 
980
- # YTD = since Jan 1 of current year
981
- import time as _t
982
- now_ts = int(_t.time())
983
- year_start = int(_t.time())
984
- # Compute Jan 1 timestamp
985
- import datetime as _dt
986
- year_start_dt = _dt.datetime(_dt.datetime.now().year, 1, 1)
987
- year_start_ts = int(year_start_dt.timestamp())
988
- ytd_target = year_start_ts
989
-
990
- ytd_snap = None
991
- for sn in snaps:
992
- if str(sn.get("bot_id", "")) != current_bot_id:
993
- continue
994
- if sn.get("updated_at", 0) >= year_start_ts:
995
- ytd_snap = sn
996
- break
997
-
998
  ytd_delta = None
999
  if ytd_snap:
1000
  try:
@@ -1014,9 +1318,9 @@ def bot_pnl_api():
1014
  "current_pnl_per": latest.get("total_pnl_per"),
1015
  "realized_pnl": latest.get("realized_pnl"),
1016
  "unrealized_pnl": latest.get("unrealized_pnl"),
1017
- "pnl_24h": _delta(86400),
1018
- "pnl_7d": _delta(7 * 86400),
1019
- "pnl_30d": _delta(30 * 86400),
1020
  "pnl_ytd": ytd_delta,
1021
  "updated_at": latest.get("updated_at"),
1022
  "snapshot_count": len(snaps),
@@ -1763,6 +2067,7 @@ def get_settings_api():
1763
  return jsonify(get_settings())
1764
 
1765
  @app.route('/api/settings', methods=['POST'])
 
1766
  def update_settings_api():
1767
  data = request.get_json()
1768
  if not data:
@@ -1772,6 +2077,7 @@ def update_settings_api():
1772
  return jsonify({"status": "updated", "settings": updated, "cache_cleared": True})
1773
 
1774
  @app.route('/api/settings/reset', methods=['POST'])
 
1775
  def reset_settings_api():
1776
  reset = reset_settings()
1777
  clear_cache()
@@ -1860,6 +2166,7 @@ def coins_api():
1860
  return jsonify({"count": get_coin_count(), "coins": get_all_coins()})
1861
 
1862
  @app.route('/api/coins/refresh', methods=['POST'])
 
1863
  def coins_refresh_api():
1864
  coins = refresh_coins()
1865
  return jsonify({"status": "refreshed", "count": len(coins), "coins": coins})
@@ -2065,6 +2372,23 @@ def terms_page():
2065
  def privacy_page():
2066
  return render_template('privacy.html')
2067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2068
  @app.route('/admin/users')
2069
  @require_admin
2070
  def admin_users_page():
@@ -2240,7 +2564,7 @@ def regime_panel():
2240
  @app.route('/<path:path>')
2241
  def serve_frontend(path):
2242
  if path in ('', 'home', 'home/'):
2243
- return redirect('/scan/')
2244
  if path:
2245
  clean_path = path.rstrip('/')
2246
  dir_path = os.path.join('static', clean_path)
 
6
  import requests
7
  from flask import Flask, jsonify, send_file, request, send_from_directory, Response
8
  from flask_cors import CORS
9
+ from datetime import datetime, timedelta, timezone
10
  import time
11
  import threading
12
  from flask import session, render_template, redirect
 
87
  app.secret_key = os.environ.get("FLASK_SECRET", "dev-only-secret-change-me")
88
  CORS(app, resources={r"/*": {"origins": "*"}})
89
 
90
+ # Share the login session with subdomains (e.g. scan.blind-monkeys.com) so
91
+ # tools hosted there can recognize logged-in admins. Only widen the cookie
92
+ # domain when the site is reached via a blind-monkeys.com host; on other
93
+ # hosts (e.g. the raw run.app URL) keep the default host-only cookie.
94
+ @app.before_request
95
+ def _session_cookie_domain():
96
+ host = (request.host or "").split(":")[0].lower()
97
+ if host == "blind-monkeys.com" or host.endswith(".blind-monkeys.com"):
98
+ app.config["SESSION_COOKIE_DOMAIN"] = ".blind-monkeys.com"
99
+ else:
100
+ app.config["SESSION_COOKIE_DOMAIN"] = None
101
+
102
  # ===================================================================
103
  # GLOBAL LOGIN GATE ??? everything requires login except public endpoints
104
  # ===================================================================
 
122
  '/about/',
123
  '/glossary',
124
  '/glossary/',
125
+ '/regimes',
126
+ '/regimes/',
127
+ '/upward',
128
+ '/upward/',
129
+ '/downward',
130
+ '/downward/',
131
+ '/sideways',
132
+ '/sideways/',
133
+ '/financials',
134
+ '/financials/',
135
+ '/performance',
136
+ '/performance/',
137
+ '/api/bybit-balance',
138
+ '/api/balance-history',
139
+ '/api/funding-summary',
140
+ '/api/futures-positions',
141
  '/robots.txt',
142
  '/sitemap.xml',
143
  '/llms.txt',
 
168
  '/bot/',
169
  '/api/win-rate',
170
  '/api/bot-pnl',
171
+ '/api/sp500-30d',
172
+ '/api/grid-returns',
173
+ '/api/grid-bots',
174
+ '/api/grid-archived',
175
+ '/api/grid-candidates',
176
  '/api/debug/apis',
177
  '/api/debug/users',
178
  '/api/scan',
 
187
  '/api/price/batch',
188
  '/api/price/enriched',
189
  '/api/diagnostic',
190
+ '/api/btc-chart/',
191
+ '/api/rising-coins',
192
  )
193
 
194
  @app.before_request
 
609
  except Exception as e:
610
  return jsonify({"error": str(e)}), 500
611
 
612
+ @app.route('/api/btc-chart/weekly')
613
+ def btc_chart_weekly():
614
+ """BTC spot price (last 7 days, hourly) for the market-condition line charts."""
615
+ try:
616
+ url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart"
617
+ params = {"vs_currency": "usd", "days": "7"}
618
+ response = requests.get(url, params=params, timeout=15)
619
+ if response.status_code != 200:
620
+ return jsonify({"error": "CoinGecko API failed"}), 500
621
+ prices = response.json().get("prices", [])
622
+ data = [{"t": int(p[0]), "close": float(p[1])} for p in prices]
623
+ return jsonify({"symbol": "BTCUSD", "interval": "auto", "data": data})
624
+ except Exception as e:
625
+ return jsonify({"error": str(e)}), 500
626
+
627
+
628
  @app.route('/api/market-regime')
629
  def market_regime():
630
  """Check if ETH has dropped 2% from its 24-hour high"""
 
985
  out[k] = {"error": str(e)[:100]}
986
  return jsonify(out)
987
 
988
+ @app.route('/api/sp500-30d')
989
+ def sp500_30d_api():
990
+ """S&P 500 return over the last 30 days — FRED primary, Yahoo fallback."""
991
+ # --- Primary: FRED daily SP500 series ---
992
+ try:
993
+ url = ('https://api.stlouisfed.org/fred/series/observations'
994
+ '?series_id=SP500&api_key={}&file_type=json&sort_order=desc&limit=25').format(FRED_API_KEY)
995
+ r = requests.get(url, timeout=10)
996
+ obs = [o for o in r.json().get('observations', []) if o.get('value', '.') != '.']
997
+ if obs:
998
+ latest = obs[0]
999
+ latest_dt = datetime.strptime(latest['date'], '%Y-%m-%d')
1000
+ cutoff = latest_dt - timedelta(days=30)
1001
+ base = None
1002
+ for o in obs[1:]:
1003
+ if datetime.strptime(o['date'], '%Y-%m-%d') <= cutoff:
1004
+ base = o
1005
+ break
1006
+ if base is None:
1007
+ base = obs[-1]
1008
+ ret = (float(latest['value']) / float(base['value']) - 1) * 100.0
1009
+ return jsonify({"status": "ok", "source": "fred",
1010
+ "as_of": latest['date'], "base_date": base['date'],
1011
+ "return_pct": round(ret, 2)})
1012
+ except Exception:
1013
+ pass # FRED down/maintenance — fall through to Yahoo
1014
+ # --- Fallback: Yahoo Finance chart API ---
1015
+ try:
1016
+ r = requests.get('https://query1.finance.yahoo.com/v8/finance/chart/%5EGSPC',
1017
+ params={'range': '2mo', 'interval': '1d'},
1018
+ headers={'User-Agent': 'Mozilla/5.0'}, timeout=10)
1019
+ res = r.json()['chart']['result'][0]
1020
+ pairs = []
1021
+ for t, c in zip(res['timestamp'], res['indicators']['quote'][0]['close']):
1022
+ if c is not None:
1023
+ pairs.append((datetime.fromtimestamp(t, timezone.utc), c))
1024
+ now_dt, now_px = pairs[-1]
1025
+ cutoff = now_dt - timedelta(days=30)
1026
+ older = [p for p in pairs if p[0] <= cutoff]
1027
+ s_dt, s_px = older[-1] if older else pairs[0]
1028
+ ret = (now_px / s_px - 1) * 100.0
1029
+ return jsonify({"status": "ok", "source": "yahoo",
1030
+ "as_of": now_dt.strftime('%Y-%m-%d'),
1031
+ "base_date": s_dt.strftime('%Y-%m-%d'),
1032
+ "return_pct": round(ret, 2)})
1033
+ except Exception as e:
1034
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1035
+
1036
+
1037
+ @app.route('/api/grid-returns')
1038
+ def grid_returns_api():
1039
+ """Grid-bot realized return (last 30 days) via the scanner service."""
1040
+ try:
1041
+ r = requests.get('https://scan.blind-monkeys.com/grid/returns', timeout=25)
1042
+ d = r.json()
1043
+ if d.get('status') != 'ok':
1044
+ return jsonify(d), 502
1045
+ return jsonify(d)
1046
+ except Exception as e:
1047
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1048
+
1049
+
1050
+ @app.route('/api/grid-bots')
1051
+ def grid_bots_api():
1052
+ """Live grid bots (running/paused) proxied from the scanner service."""
1053
+ try:
1054
+ r = requests.get('https://scan.blind-monkeys.com/grid/bots', timeout=25)
1055
+ r.raise_for_status()
1056
+ return Response(r.content, mimetype='application/json')
1057
+ except Exception as e:
1058
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1059
+
1060
+
1061
+ @app.route('/api/grid-archived')
1062
+ def grid_archived_api():
1063
+ """Archived/completed grid bots proxied from the scanner service."""
1064
+ try:
1065
+ r = requests.get('https://scan.blind-monkeys.com/grid/archived', timeout=25)
1066
+ r.raise_for_status()
1067
+ return Response(r.content, mimetype='application/json')
1068
+ except Exception as e:
1069
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1070
+
1071
+
1072
+ @app.route('/api/grid-candidates')
1073
+ def grid_candidates_api():
1074
+ """Range-bound grid candidates proxied from the scanner service."""
1075
+ try:
1076
+ r = requests.get('https://scan.blind-monkeys.com/grid/candidates.json', timeout=25)
1077
+ r.raise_for_status()
1078
+ return Response(r.content, mimetype='application/json')
1079
+ except Exception as e:
1080
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1081
+
1082
+
1083
+ @app.route('/api/grid-config', methods=['GET'])
1084
+ def grid_config_get_api():
1085
+ """Grid bot settings proxied from the scanner service (GET — read/view)."""
1086
+ url = 'https://scan.blind-monkeys.com/grid/config'
1087
+ try:
1088
+ r = requests.get(url, timeout=25)
1089
+ r.raise_for_status()
1090
+ return Response(r.content, mimetype='application/json')
1091
+ except Exception as e:
1092
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1093
+
1094
+
1095
+ @app.route('/api/grid-config', methods=['POST'])
1096
+ @require_admin
1097
+ def grid_config_post_api():
1098
+ """Grid bot settings proxied from the scanner service (POST — admin only)."""
1099
+ url = 'https://scan.blind-monkeys.com/grid/config'
1100
+ try:
1101
+ data = request.get_json(silent=True) or {}
1102
+ r = requests.post(url, json=data, timeout=25)
1103
+ r.raise_for_status()
1104
+ return Response(r.content, mimetype='application/json')
1105
+ except Exception as e:
1106
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1107
+
1108
+
1109
+ @app.route('/api/futures-config', methods=['GET'])
1110
+ def futures_config_get_api():
1111
+ """Futures auto-trade settings proxied from the scanner service (GET — read/view)."""
1112
+ url = 'https://scan.blind-monkeys.com/config'
1113
+ try:
1114
+ r = requests.get(url, timeout=25)
1115
+ r.raise_for_status()
1116
+ return Response(r.content, mimetype='application/json')
1117
+ except Exception as e:
1118
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1119
+
1120
+
1121
+ @app.route('/api/futures-config', methods=['POST'])
1122
+ @require_admin
1123
+ def futures_config_post_api():
1124
+ """Futures auto-trade settings proxied from the scanner service (POST — admin only)."""
1125
+ url = 'https://scan.blind-monkeys.com/config'
1126
+ try:
1127
+ data = request.get_json(silent=True) or {}
1128
+ r = requests.post(url, json=data, timeout=25)
1129
+ r.raise_for_status()
1130
+ return Response(r.content, mimetype='application/json')
1131
+ except Exception as e:
1132
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1133
+
1134
+
1135
+ @app.route('/api/grid-archive', methods=['POST'])
1136
+ @require_admin
1137
+ def grid_archive_api():
1138
+ """Archive a completed grid bot via the trader (admin only).
1139
+
1140
+ Moves the bot into the archive list so its slot frees up and its funds,
1141
+ already released by Bybit when the grid completed, are accounted for.
1142
+ """
1143
+ data = request.get_json(silent=True) or {}
1144
+ bot_id = (data.get('bot_id') or '').strip()
1145
+ if not bot_id:
1146
+ return "bot_id required", 400
1147
+ try:
1148
+ r = requests.get(
1149
+ 'https://blind-monkeys-trader-353804379600.europe-west1.run.app/grid/archive',
1150
+ params={'bot_id': bot_id}, timeout=30)
1151
+ return Response(r.text, status=r.status_code, mimetype='text/plain')
1152
+ except Exception as e:
1153
+ return f"archive failed: {str(e)[:120]}", 502
1154
+
1155
+
1156
+ @app.route('/performance')
1157
+ @app.route('/performance/')
1158
+ def performance_page_redirect():
1159
+ """The performance panels moved to /financials — keep old links working."""
1160
+ return redirect('/financials')
1161
+
1162
+
1163
+ @app.route('/api/bybit-balance')
1164
+ def bybit_balance_api():
1165
+ """Live Bybit account balances proxied from the scanner service."""
1166
+ try:
1167
+ r = requests.get('https://scan.blind-monkeys.com/grid/balance', timeout=25)
1168
+ r.raise_for_status()
1169
+ return Response(r.content, mimetype='application/json')
1170
+ except Exception as e:
1171
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1172
+
1173
+
1174
+ @app.route('/api/futures-positions')
1175
+ def futures_positions_api():
1176
+ """All open Bybit futures positions, proxied from the trader."""
1177
+ try:
1178
+ r = requests.get(
1179
+ 'https://blind-monkeys-trader-353804379600.europe-west1.run.app/positions/active',
1180
+ timeout=90)
1181
+ r.raise_for_status()
1182
+ return Response(r.content, mimetype='application/json')
1183
+ except Exception as e:
1184
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1185
+
1186
+
1187
+ @app.route('/api/funding-summary')
1188
+ def funding_summary_api():
1189
+ """Funding fees received/paid (7d/30d) from the trader's Bybit scan."""
1190
+ try:
1191
+ r = requests.get(
1192
+ 'https://blind-monkeys-trader-353804379600.europe-west1.run.app/funding/summary',
1193
+ timeout=60)
1194
+ r.raise_for_status()
1195
+ return Response(r.content, mimetype='application/json')
1196
+ except Exception as e:
1197
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1198
+
1199
+
1200
+ @app.route('/api/balance-history')
1201
+ def balance_history_api():
1202
+ """Daily Bybit balance snapshots proxied from the scanner service."""
1203
+ try:
1204
+ r = requests.get('https://scan.blind-monkeys.com/grid/balance-history', timeout=25)
1205
+ r.raise_for_status()
1206
+ return Response(r.content, mimetype='application/json')
1207
+ except Exception as e:
1208
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1209
+
1210
+
1211
+ @app.route('/api/riser-config', methods=['GET'])
1212
+ def riser_config_get_api():
1213
+ """Rising-coins trading rules proxied from the scanner service (GET — view)."""
1214
+ url = 'https://scan.blind-monkeys.com/riser/config'
1215
+ try:
1216
+ r = requests.get(url, timeout=25)
1217
+ r.raise_for_status()
1218
+ return Response(r.content, mimetype='application/json')
1219
+ except Exception as e:
1220
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1221
+
1222
+
1223
+ @app.route('/api/riser-config', methods=['POST'])
1224
+ @require_admin
1225
+ def riser_config_post_api():
1226
+ """Rising-coins trading rules proxied from the scanner service (POST — admin only)."""
1227
+ url = 'https://scan.blind-monkeys.com/riser/config'
1228
+ try:
1229
+ data = request.get_json(silent=True) or {}
1230
+ r = requests.post(url, json=data, timeout=25)
1231
+ r.raise_for_status()
1232
+ return Response(r.content, mimetype='application/json')
1233
+ except Exception as e:
1234
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1235
+
1236
+
1237
+ @app.route('/api/rising-coins')
1238
+ def rising_coins_api():
1239
+ """Rising-coins (relative strength) data proxied from the scanner service."""
1240
+ try:
1241
+ r = requests.get('https://scan.blind-monkeys.com/rising.json', timeout=60)
1242
+ r.raise_for_status()
1243
+ return Response(r.content, mimetype='application/json')
1244
+ except Exception as e:
1245
+ return jsonify({"status": "error", "message": str(e)[:120]}), 502
1246
+
1247
+
1248
  @app.route('/api/bot-pnl')
1249
  def bot_pnl_api():
1250
  """Return Bybit bot P&L with 24h/7d/30d/YTD deltas computed from history."""
 
1258
  snaps = sorted(history.get("snapshots", []), key=lambda x: x.get("updated_at", 0))
1259
 
1260
  current_bot_id = str(latest.get("bot_id", ""))
1261
+ base_ts = latest.get("updated_at", 0)
1262
+
1263
+ # Single pass over history: find, for the CURRENT bot only, the
1264
+ # snapshot closest to each window target (24h / 7d / 30d) and the
1265
+ # earliest snapshot on/after Jan 1 (YTD baseline).
1266
+ WINDOWS = ((86400, "w24h"), (7 * 86400, "w7d"), (30 * 86400, "w30d"))
1267
+ best = {"w24h": None, "w7d": None, "w30d": None} # (delta, snapshot)
1268
+
1269
+ import datetime as _dt
1270
+ year_start_ts = int(_dt.datetime(_dt.datetime.now().year, 1, 1).timestamp())
1271
+ ytd_snap = None
1272
 
1273
+ for sn in snaps:
1274
+ if str(sn.get("bot_id", "")) != current_bot_id:
1275
+ continue # ignore snapshots from other bots
1276
+ ts = sn.get("updated_at", 0)
1277
+ if ytd_snap is None and ts >= year_start_ts:
1278
+ ytd_snap = sn
1279
+ for w, key in WINDOWS:
1280
+ d = abs(ts - (base_ts - w))
1281
+ cur = best[key]
1282
+ if cur is None or d < cur[0]:
1283
+ best[key] = (d, sn)
1284
+
1285
+ def _delta_from(entry, window):
1286
+ """P&L delta vs. the closest snapshot, same validity rules as the
1287
+ original per-window scan (preserves displayed values):
1288
+ - closest snapshot farther than half the window: use it (sparse history)
1289
+ - otherwise require it within 1h of the target time."""
1290
+ if not entry:
1291
+ return None
1292
+ d, past = entry
1293
+ if d <= window * 0.5 and d >= 3600:
1294
  return None
1295
  try:
1296
  now_v = float(latest.get("total_pnl", 0))
 
1299
  except Exception:
1300
  return None
1301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1302
  ytd_delta = None
1303
  if ytd_snap:
1304
  try:
 
1318
  "current_pnl_per": latest.get("total_pnl_per"),
1319
  "realized_pnl": latest.get("realized_pnl"),
1320
  "unrealized_pnl": latest.get("unrealized_pnl"),
1321
+ "pnl_24h": _delta_from(best["w24h"], 86400),
1322
+ "pnl_7d": _delta_from(best["w7d"], 7 * 86400),
1323
+ "pnl_30d": _delta_from(best["w30d"], 30 * 86400),
1324
  "pnl_ytd": ytd_delta,
1325
  "updated_at": latest.get("updated_at"),
1326
  "snapshot_count": len(snaps),
 
2067
  return jsonify(get_settings())
2068
 
2069
  @app.route('/api/settings', methods=['POST'])
2070
+ @require_admin
2071
  def update_settings_api():
2072
  data = request.get_json()
2073
  if not data:
 
2077
  return jsonify({"status": "updated", "settings": updated, "cache_cleared": True})
2078
 
2079
  @app.route('/api/settings/reset', methods=['POST'])
2080
+ @require_admin
2081
  def reset_settings_api():
2082
  reset = reset_settings()
2083
  clear_cache()
 
2166
  return jsonify({"count": get_coin_count(), "coins": get_all_coins()})
2167
 
2168
  @app.route('/api/coins/refresh', methods=['POST'])
2169
+ @require_admin
2170
  def coins_refresh_api():
2171
  coins = refresh_coins()
2172
  return jsonify({"status": "refreshed", "count": len(coins), "coins": coins})
 
2372
  def privacy_page():
2373
  return render_template('privacy.html')
2374
 
2375
+ @app.route('/regimes')
2376
+ def regimes_page():
2377
+ return render_template('regimes.html')
2378
+
2379
+
2380
+ @app.route('/analytics')
2381
+ @require_admin
2382
+ def analytics_page():
2383
+ return render_template('analytics.html')
2384
+
2385
+
2386
+ @app.route('/admin')
2387
+ @require_admin
2388
+ def admin_home_page():
2389
+ return render_template('admin_home.html')
2390
+
2391
+
2392
  @app.route('/admin/users')
2393
  @require_admin
2394
  def admin_users_page():
 
2564
  @app.route('/<path:path>')
2565
  def serve_frontend(path):
2566
  if path in ('', 'home', 'home/'):
2567
+ return send_from_directory(os.path.join('static', 'scan'), 'index.html')
2568
  if path:
2569
  clean_path = path.rstrip('/')
2570
  dir_path = os.path.join('static', clean_path)
modules/saved_orders.py CHANGED
@@ -27,6 +27,10 @@ def get_orders_for_user(email):
27
  if o.get("user_email", "").lower() == email]
28
 
29
  def add_order(email, name, investment, atr_multiplier, coins, scan_mode="conservative"):
 
 
 
 
30
  data = _load()
31
  order_id = "ord_" + datetime.utcnow().strftime("%Y%m%d_%H%M%S") + "_" + secrets.token_hex(2)
32
  order = {
 
27
  if o.get("user_email", "").lower() == email]
28
 
29
  def add_order(email, name, investment, atr_multiplier, coins, scan_mode="conservative"):
30
+ try:
31
+ investment = min(float(investment or 0), 99999.0) # max planned invest: $99,999
32
+ except (TypeError, ValueError):
33
+ investment = 0.0
34
  data = _load()
35
  order_id = "ord_" + datetime.utcnow().strftime("%Y%m%d_%H%M%S") + "_" + secrets.token_hex(2)
36
  order = {
static/btc-chart.js ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // BTC spot price — 7-day continuous line chart (no candles).
2
+ // Renders into any element with [data-btc-chart] and writes the 7-day change
3
+ // into any element with [data-btc-change]. Self-contained, no dependencies.
4
+ (function () {
5
+ 'use strict';
6
+
7
+ var state = { data: null, pct: null, first: null, last: null };
8
+
9
+ function num(v) { return Number(v); }
10
+ function usd(v) { return '$' + num(v).toLocaleString(undefined, { maximumFractionDigits: 0 }); }
11
+ function pctFmt(v) { return (v >= 0 ? '+' : '') + v.toFixed(2) + '%'; }
12
+
13
+ function timeLabel(t) {
14
+ var d = new Date(t);
15
+ return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) + ' ' +
16
+ d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
17
+ }
18
+
19
+ function buildSvg(w, h) {
20
+ var data = state.data;
21
+ var padL = 64, padR = 18, padT = 16, padB = 30;
22
+ var iw = w - padL - padR, ih = h - padT - padB;
23
+ var closes = data.map(function (d) { return num(d.close); });
24
+ var min = Math.min.apply(null, closes), max = Math.max.apply(null, closes);
25
+ if (max - min === 0) { max += 1; min -= 1; }
26
+ var n = data.length;
27
+ function x(i) { return padL + (n <= 1 ? 0 : (i / (n - 1)) * iw); }
28
+ function y(v) { return padT + (1 - (v - min) / (max - min)) * ih; }
29
+
30
+ var s = '<svg xmlns="http://www.w3.org/2000/svg" width="' + w + '" height="' + h + '" viewBox="0 0 ' + w + ' ' + h + '" font-family="-apple-system, BlinkMacSystemFont, sans-serif">';
31
+ s += '<defs><linearGradient id="btcArea" x1="0" y1="0" x2="0" y2="1">';
32
+ s += '<stop offset="0%" stop-color="#f0b90b" stop-opacity="0.35"/>';
33
+ s += '<stop offset="100%" stop-color="#f0b90b" stop-opacity="0"/>';
34
+ s += '</linearGradient></defs>';
35
+
36
+ var ticks = 5;
37
+ for (var t = 0; t < ticks; t++) {
38
+ var val = min + (max - min) * t / (ticks - 1);
39
+ var yy = y(val);
40
+ s += '<line x1="' + padL + '" y1="' + yy.toFixed(1) + '" x2="' + (w - padR) + '" y2="' + yy.toFixed(1) + '" stroke="#30363d" stroke-width="1"/>';
41
+ s += '<text x="' + (padL - 8) + '" y="' + (yy + 4).toFixed(1) + '" fill="#8b949e" font-size="14" text-anchor="end">' + usd(val) + '</text>';
42
+ }
43
+
44
+ var xs = [0, Math.floor((n - 1) / 2), n - 1];
45
+ xs.forEach(function (i) {
46
+ var xx = x(i);
47
+ var anchor = i === 0 ? 'start' : (i === n - 1 ? 'end' : 'middle');
48
+ s += '<text x="' + xx.toFixed(1) + '" y="' + (h - 8) + '" fill="#8b949e" font-size="14" text-anchor="' + anchor + '">' + timeLabel(data[i].t) + '</text>';
49
+ });
50
+
51
+ var pts = data.map(function (d, i) { return x(i).toFixed(1) + ',' + y(num(d.close)).toFixed(1); });
52
+ var linePath = 'M' + pts.join(' L');
53
+ var areaPath = linePath + ' L' + x(n - 1).toFixed(1) + ',' + (padT + ih).toFixed(1) + ' L' + x(0).toFixed(1) + ',' + (padT + ih).toFixed(1) + ' Z';
54
+ s += '<path d="' + areaPath + '" fill="url(#btcArea)"/>';
55
+ s += '<path d="' + linePath + '" fill="none" stroke="#f0b90b" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>';
56
+ s += '</svg>';
57
+ return s;
58
+ }
59
+
60
+ function redraw() {
61
+ document.querySelectorAll('[data-btc-chart]').forEach(function (c) {
62
+ if (!state.data) return;
63
+ var w = c.clientWidth || 720;
64
+ c.innerHTML = buildSvg(w, 320);
65
+ });
66
+ }
67
+
68
+ function init() {
69
+ var changeEl = document.querySelector('[data-btc-change]');
70
+ fetch('/api/btc-chart/weekly')
71
+ .then(function (r) { if (!r.ok) throw new Error('http'); return r.json(); })
72
+ .then(function (res) {
73
+ var data = (res && res.data) || [];
74
+ if (!data || data.length < 2) throw new Error('nodata');
75
+ state.data = data;
76
+ state.first = num(data[0].close);
77
+ state.last = num(data[data.length - 1].close);
78
+ state.pct = (state.last - state.first) / state.first * 100;
79
+ if (changeEl) {
80
+ var cls = state.pct > 0.5 ? 'pos' : (state.pct < -0.5 ? 'neg' : 'mut');
81
+ changeEl.innerHTML = '7-Day Change: <span class="' + cls + '">' + pctFmt(state.pct) + '</span> <span class="mut" style="margin-left:8px;">' + usd(state.first) + ' → ' + usd(state.last) + '</span>';
82
+ }
83
+ redraw();
84
+ })
85
+ .catch(function () {
86
+ document.querySelectorAll('[data-btc-chart]').forEach(function (c) {
87
+ c.innerHTML = '<p class="muted" style="text-align:center;padding:20px;">Could not load BTC chart.</p>';
88
+ });
89
+ });
90
+ }
91
+
92
+ var resizeTimer;
93
+ window.addEventListener('resize', function () {
94
+ clearTimeout(resizeTimer);
95
+ resizeTimer = setTimeout(redraw, 150);
96
+ });
97
+
98
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
99
+ else init();
100
+ })();
static/css/nav.css CHANGED
@@ -7,7 +7,7 @@ body {
7
  color: #e6edf3;
8
  min-height: 100vh;
9
  padding: 0;
10
- padding-top: 60px;
11
  }
12
 
13
  /* ---------- Navigation Bar ---------- */
@@ -23,7 +23,7 @@ body {
23
  left: 0;
24
  right: 0;
25
  z-index: 1000;
26
- height: 60px;
27
  }
28
 
29
  .nav-brand {
@@ -33,7 +33,7 @@ body {
33
  text-decoration: none;
34
  white-space: nowrap;
35
  position: fixed;
36
- top: 14px;
37
  left: 24px;
38
  z-index: 1001;
39
  }
 
7
  color: #e6edf3;
8
  min-height: 100vh;
9
  padding: 0;
10
+ padding-top: 118px;
11
  }
12
 
13
  /* ---------- Navigation Bar ---------- */
 
23
  left: 0;
24
  right: 0;
25
  z-index: 1000;
26
+ height: 118px;
27
  }
28
 
29
  .nav-brand {
 
33
  text-decoration: none;
34
  white-space: nowrap;
35
  position: fixed;
36
+ top: 10px;
37
  left: 24px;
38
  z-index: 1001;
39
  }
static/css/nav.js CHANGED
@@ -1,5 +1,5 @@
1
  // Role-aware nav injection.
2
- // - Injects tagline under brand
3
  // - Hides /price/ link (always)
4
  // - Shows admin-only BingX link for admins
5
  // - Shows login link for anonymous visitors
@@ -9,29 +9,44 @@
9
  const navLinks = document.querySelector('.nav-links');
10
  if (!navLinks) return;
11
 
12
- // ---- Tagline under brand ----
13
  const brand = document.querySelector('.nav-brand');
14
- if (brand && !brand.querySelector('.nav-opensource')) {
15
- const os = document.createElement('span');
16
- os.className = 'nav-opensource';
17
- os.innerHTML = 'Free and Open Source Project · <a href="/license" style="color:#f0b90b;text-decoration:underline;">MIT License</a>';
18
- os.style.cssText = 'display:block;font-size:11px;color:#8b949e;margin-top:2px;line-height:1.2;letter-spacing:0.3px;';
19
- // Insert badge BEFORE the tagline so the order is: brand → badge → tagline
20
- const existing = brand.querySelector('.nav-tagline');
21
- if (existing) {
22
- brand.insertBefore(os, existing);
23
- } else {
24
- brand.appendChild(os);
25
- }
 
 
26
  }
27
-
28
  if (brand && !brand.querySelector('.nav-tagline')) {
29
  const tag = document.createElement('span');
30
  tag.className = 'nav-tagline';
31
- tag.innerHTML = '<span style="border-bottom:3px solid #ffffff;padding-bottom:2px;">Don\'t be a blind monkey.</span>';
32
- tag.style.cssText = 'display:block;font-size:inherit;font-weight:400;color:#ffffff;margin-top:1px;line-height:1.2;';
33
  brand.appendChild(tag);
34
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  // ---- Hamburger (mobile) ----
37
  var navBar = document.querySelector('.nav-bar');
@@ -65,8 +80,21 @@
65
  overlay.addEventListener('click', closeMenu);
66
  }
67
 
68
- // ---- Always: remove price link ----
69
  navLinks.querySelectorAll('a[href="/price/"]').forEach(function(a) { a.remove(); });
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  // ---- Always: ensure About + Glossary links present (visible to everyone) ----
72
  if (!navLinks.querySelector('a[href="/about"]')) {
@@ -149,16 +177,29 @@
149
 
150
  // ---- Logged in ----
151
  if (isAdmin) {
152
- // Add Users link (admin only) before Settings
153
- if (!navLinks.querySelector('a[href="/admin/users"]')) {
154
- const users = document.createElement('a');
155
- users.href = '/admin/users';
156
- users.className = 'nav-link';
157
- users.textContent = '👥 Users';
158
- const settings = navLinks.querySelector('a[href="/settings/"]');
159
- if (settings) navLinks.insertBefore(users, settings);
160
- else navLinks.appendChild(users);
161
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
  // Add Cron link (admin only) next to Users
 
1
  // Role-aware nav injection.
2
+ // - Brand stack: title, tagline, Free and Open Source, MIT License (last)
3
  // - Hides /price/ link (always)
4
  // - Shows admin-only BingX link for admins
5
  // - Shows login link for anonymous visitors
 
9
  const navLinks = document.querySelector('.nav-links');
10
  if (!navLinks) return;
11
 
12
+ // ---- Brand stack: tagline, open-source line, MIT license (last) ----
13
  const brand = document.querySelector('.nav-brand');
14
+ if (brand && !brand.querySelector('.nav-brand-icon')) {
15
+ // Enlarged image (3x) + title (2x); tagline lines follow.
16
+ const txt = brand.textContent.replace('\u{1F648}', '').trim();
17
+ brand.textContent = '';
18
+ const ic = document.createElement('span');
19
+ ic.className = 'nav-brand-icon';
20
+ ic.textContent = '\u{1F648}';
21
+ ic.style.cssText = 'font-size:54px;line-height:1;display:inline-block;vertical-align:middle;';
22
+ const tt = document.createElement('span');
23
+ tt.className = 'nav-brand-title';
24
+ tt.textContent = ' ' + txt;
25
+ tt.style.cssText = 'font-size:36px;font-weight:700;color:#f0b90b;';
26
+ brand.appendChild(ic);
27
+ brand.appendChild(tt);
28
  }
 
29
  if (brand && !brand.querySelector('.nav-tagline')) {
30
  const tag = document.createElement('span');
31
  tag.className = 'nav-tagline';
32
+ tag.innerHTML = 'Don\'t be a Blind Monkey.';
33
+ tag.style.cssText = 'display:block;font-family:inherit;font-size:16px;font-weight:400;color:#8b949e;margin-top:1px;line-height:1.15;';
34
  brand.appendChild(tag);
35
  }
36
+ if (brand && !brand.querySelector('.nav-opensource')) {
37
+ const os = document.createElement('span');
38
+ os.className = 'nav-opensource';
39
+ os.innerHTML = 'Free and Open Source';
40
+ os.style.cssText = 'display:block;font-family:inherit;font-size:16px;font-weight:400;color:#8b949e;line-height:1.15;';
41
+ brand.appendChild(os);
42
+ }
43
+ if (brand && !brand.querySelector('.nav-license')) {
44
+ const li = document.createElement('span');
45
+ li.className = 'nav-license';
46
+ li.innerHTML = '<a href="/license" style="color:#f0b90b;text-decoration:underline;">MIT License</a>';
47
+ li.style.cssText = 'display:block;font-size:10px;font-weight:400;line-height:1.15;letter-spacing:0.3px;';
48
+ brand.appendChild(li);
49
+ }
50
 
51
  // ---- Hamburger (mobile) ----
52
  var navBar = document.querySelector('.nav-bar');
 
80
  overlay.addEventListener('click', closeMenu);
81
  }
82
 
83
+ // ---- Always: remove price + scan links ----
84
  navLinks.querySelectorAll('a[href="/price/"]').forEach(function(a) { a.remove(); });
85
+ navLinks.querySelectorAll('a[href="/scan/"]').forEach(function(a) { a.remove(); });
86
+ navLinks.querySelectorAll('a[href="/scan"]').forEach(function(a) { a.remove(); });
87
+
88
+ // ---- Always: Regimes link (visible to everyone) ----
89
+ if (!navLinks.querySelector('a[href="/regimes"]')) {
90
+ const regLink = document.createElement('a');
91
+ regLink.href = '/regimes';
92
+ regLink.className = 'nav-link';
93
+ regLink.textContent = '🌍 Regimes';
94
+ const firstLink = navLinks.querySelector('a');
95
+ if (firstLink) navLinks.insertBefore(regLink, firstLink);
96
+ else navLinks.appendChild(regLink);
97
+ }
98
 
99
  // ---- Always: ensure About + Glossary links present (visible to everyone) ----
100
  if (!navLinks.querySelector('a[href="/about"]')) {
 
177
 
178
  // ---- Logged in ----
179
  if (isAdmin) {
180
+ // Admin nav: exact ordered set.
181
+ const items = [
182
+ ['🏠 Home', '/'],
183
+ ['ℹ️ About', '/about'],
184
+ ['🛠️ Admin', '/admin'],
185
+ ['📈 Analytics', '/analytics'],
186
+ ['💡 FAQ', '/faq'],
187
+ ['📊 Financials', '/financials/'],
188
+ ['📖 Glossary', '/glossary'],
189
+ ['🌍 Regimes', '/regimes'],
190
+ ['⚙️ Settings', '/settings/'],
191
+ ['👤 Profile', '/profile/'],
192
+ ['🚪 Logout', '/logout']
193
+ ];
194
+ navLinks.innerHTML = '';
195
+ items.forEach(function(it) {
196
+ const a = document.createElement('a');
197
+ a.href = it[1];
198
+ a.className = 'nav-link';
199
+ a.textContent = it[0];
200
+ navLinks.appendChild(a);
201
+ });
202
+ return;
203
  }
204
 
205
  // Add Cron link (admin only) next to Users
static/downward/index.html ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Downward Market — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <link rel="stylesheet" href="/static/help.css">
9
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
10
+ <style>
11
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
12
+ .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
13
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
14
+ .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
15
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
16
+ .breadcrumbs .bc-current { color: #e6edf3; }
17
+ @media (max-width: 640px) { .breadcrumbs { display: none; } }
18
+
19
+ .section-title { text-align: center; font-size: 30px; font-weight: 700; color: #f0b90b; margin: 8px 0 10px; letter-spacing: 0.5px; }
20
+ .page-subtitle { font-size: 14px; color: #8b949e; margin-bottom: 24px; text-align: center; }
21
+ .market-nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin: 0 0 24px; }
22
+ .market-nav-btn {
23
+ display: inline-block;
24
+ padding: 10px 22px;
25
+ background: #f0b90b;
26
+ color: #0d1117;
27
+ border-radius: 8px;
28
+ font-weight: 700;
29
+ font-size: 14px;
30
+ text-decoration: none;
31
+ transition: opacity 0.15s;
32
+ }
33
+ .market-nav-btn:hover { opacity: 0.85; }
34
+ .market-nav-btn.active { box-shadow: 0 0 0 2px #0d1117, 0 0 0 4px #ffffff; }
35
+ .placeholder {
36
+ background: #1e2329;
37
+ border: 2px solid #30363d;
38
+ border-radius: 12px;
39
+ padding: 40px 24px;
40
+ text-align: center;
41
+ color: #8b949e;
42
+ font-size: 14px;
43
+ }
44
+ .pos { color: #4ade80; }
45
+ .neg { color: #f87171; }
46
+ .mut { color: #8b949e; }
47
+ .muted { color: #8b949e; }
48
+ .btc-section { margin-bottom: 32px; }
49
+ .btc-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
50
+ .btc-card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 16px 18px; }
51
+ .btc-change { text-align: center; font-size: 14px; color: #e6edf3; margin-bottom: 8px; }
52
+ .btc-chart { width: 100%; }
53
+
54
+ .grid-section { margin-bottom: 32px; }
55
+ .grid-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
56
+ .table-wrap { overflow-x: auto; background: #1e2329; border: 2px solid #30363d; border-radius: 12px; }
57
+ .grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
58
+ .grid-table th { text-align: right; padding: 10px 12px; color: #8b949e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; white-space: nowrap; }
59
+ .grid-table th:first-child { text-align: left; }
60
+ .grid-table td { padding: 10px 12px; border-bottom: 1px solid #21262d; text-align: right; font-family: 'SF Mono', Monaco, monospace; white-space: nowrap; }
61
+ .grid-table td:first-child { text-align: left; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
62
+ .grid-table tr:last-child td { border-bottom: none; }
63
+ .grid-table tbody tr:hover { background: #161b22; }
64
+ .leader-row td { background: #161b22; }
65
+ .rec { font-size: 12px; font-weight: 700; white-space: nowrap; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
66
+ .r-spot { color: #fbbf24; }
67
+ .r-fut { color: #4ade80; }
68
+ .r-fut-caution { color: #f87171; }
69
+ .rising-status { text-align: center; font-size: 13px; color: #8b949e; margin-bottom: 12px; }
70
+ .rising-status .down { color: #f87171; }
71
+ .rising-status .up { color: #4ade80; }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <nav class="nav-bar">
76
+ <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
77
+ <div class="nav-links">
78
+ <a href="/scan/" class="nav-link">🔍 Scan</a>
79
+ <a href="/price/" class="nav-link">💵 ETH Price</a>
80
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
81
+ </div>
82
+ </nav>
83
+
84
+ <div class="page-content">
85
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Downward Market</span></div>
86
+
87
+ <div class="market-nav">
88
+ <a class="market-nav-btn" href="/upward">Upward Markets</a>
89
+ <a class="market-nav-btn" href="/sideways">Sideways Markets</a>
90
+ <a class="market-nav-btn active" href="/downward">Downward Markets</a>
91
+ </div>
92
+
93
+ <h1 class="section-title">Tools for Downward Markets</h1>
94
+ <p class="page-subtitle">📉 Downward Market — defensive and short setups when the market is dropping.</p>
95
+
96
+ <section class="btc-section">
97
+ <h2 class="btc-h2">BTC Spot Price · Last 7 Days</h2>
98
+ <div class="btc-card">
99
+ <div class="btc-change" data-btc-change>Loading…</div>
100
+ <div class="btc-chart" data-btc-chart></div>
101
+ </div>
102
+ </section>
103
+
104
+ <section class="grid-section">
105
+ <h2 class="grid-h2">🔺 Rising Coins (Relative Strength)</h2>
106
+ <div class="rising-status" id="rising-status">Loading…</div>
107
+ <div class="table-wrap">
108
+ <table class="grid-table">
109
+ <thead><tr><th>#</th><th>Symbol</th><th>1h %</th><th>Vol</th><th>x7d Vol</th><th>Funding Rate</th></tr></thead>
110
+ <tbody id="rising-tbody"><tr><td colspan="6" class="muted">Loading…</td></tr></tbody>
111
+ </table>
112
+ </div>
113
+ </section>
114
+
115
+ <!-- Active Futures Positions -->
116
+ <section class="grid-section">
117
+ <h2 class="grid-h2">🟢 Active Futures Positions</h2>
118
+ <div class="table-wrap">
119
+ <table class="grid-table">
120
+ <thead><tr>
121
+ <th class="psort" data-fkey="symbol" style="cursor:pointer;">Symbol <span class="farrow" data-fkey="symbol"></span></th>
122
+ <th class="psort center" data-fkey="lev" style="cursor:pointer;text-align:center;">Lev <span class="farrow" data-fkey="lev"></span></th>
123
+ <th class="psort" data-fkey="invested" style="cursor:pointer;">Invested <span class="farrow" data-fkey="invested"></span></th>
124
+ <th class="psort" data-fkey="funding" style="cursor:pointer;">Funding Profit <span class="farrow" data-fkey="funding"></span></th>
125
+ <th class="psort" data-fkey="realised" style="cursor:pointer;">Realized <span class="farrow" data-fkey="realised"></span></th>
126
+ <th class="psort" data-fkey="pnl" style="cursor:pointer;">Total P&amp;L <span class="farrow" data-fkey="pnl"></span></th>
127
+ <th class="psort" data-fkey="duration" style="cursor:pointer;">Duration <span class="farrow" data-fkey="duration"></span></th>
128
+ </tr></thead>
129
+ <tbody id="positions-tbody"><tr><td colspan="7" class="muted">Loading…</td></tr></tbody>
130
+ <tfoot id="positions-tfoot"></tfoot>
131
+ </table>
132
+ </div>
133
+ </section>
134
+ </div>
135
+
136
+ <script src="/css/nav.js"></script>
137
+ <script src="/static/btc-chart.js"></script>
138
+ <script>
139
+ function volFmt(v) {
140
+ if (v === null || v === undefined || isNaN(v)) return '—';
141
+ if (v >= 1e6) return '$' + (v / 1e6).toFixed(1) + 'M';
142
+ if (v >= 1e3) return '$' + (v / 1e3).toFixed(1) + 'K';
143
+ return '$' + v.toFixed(0);
144
+ }
145
+ function renderRising() {
146
+ fetch('/api/rising-coins').then(function (r) {
147
+ if (!r.ok) throw new Error('http');
148
+ return r.json();
149
+ }).then(function (d) {
150
+ var st = document.getElementById('rising-status');
151
+ if (!d || !d.rows) { st.innerHTML = 'No rising-coins data yet.'; return; }
152
+ st.innerHTML = 'BTC <b class="' + (d.btc_drawdown >= 1 ? 'down' : 'up') + '">−' + d.btc_drawdown + '%</b> off high · ' +
153
+ 'ETH <b class="' + (d.eth_drawdown >= 1 ? 'down' : 'up') + '">−' + d.eth_drawdown + '%</b> off high · ' +
154
+ (d.market_down ? 'Market <b class="down">IN DRAWDOWN</b>' : 'Market <b class="up">not in drawdown</b>');
155
+ var tb = document.getElementById('rising-tbody');
156
+ // Only show coins where owners are strictly PAID: rising (1h % > 0)
157
+ // and funding strictly negative (green). Zero/positive funding
158
+ // (owners pay or break even) and falling coins are filtered out.
159
+ var rows = (d.rows || []).filter(function (r) {
160
+ if (r.pct == null || Number(r.pct) <= 0) return false;
161
+ if (r.funding_rate == null || Number(r.funding_rate) >= 0) return false;
162
+ return true;
163
+ });
164
+ if (!rows.length) { tb.innerHTML = '<tr><td colspan="6" class="muted">No coins rising right now (falling or pay-to-hold coins filtered out).</td></tr>'; return; }
165
+ tb.innerHTML = rows.map(function (x) {
166
+ var pct = x.pct == null ? '—' : (x.pct >= 0 ? '+' : '') + x.pct.toFixed(2) + '%';
167
+ var pctCls = x.pct == null ? 'mut' : (x.pct > 0 ? 'pos' : (x.pct < 0 ? 'neg' : 'mut'));
168
+ return '<tr class="' + (x.leader ? 'leader-row' : '') + '">'
169
+ + '<td class="mut">' + x.rank + '</td>'
170
+ + '<td>' + x.symbol + '</td>'
171
+ + '<td class="' + pctCls + '">' + pct + '</td>'
172
+ + '<td class="mut">' + volFmt(x.vol) + '</td>'
173
+ + '<td>' + (x.ratio == null ? '—' : x.ratio.toFixed(1) + 'x') + '</td>'
174
+ + '<td>' + fundingCell(x.funding_rate) + '</td>'
175
+ + '</tr>';
176
+ }).join('');
177
+ function fundingCell(fr) {
178
+ if (fr == null) return '<span class="mut">—</span>';
179
+ // Negative funding = longs are PAID (green); positive = longs pay (red).
180
+ var col = fr < 0 ? '#4ade80' : (fr > 0 ? '#f87171' : '#e6edf3');
181
+ return '<span style="color:' + col + ';font-weight:700;">' + (fr >= 0 ? '+' : '') + Number(fr).toFixed(4) + '%</span>';
182
+ }
183
+ }).catch(function () {
184
+ document.getElementById('rising-tbody').innerHTML = '<tr><td colspan="6" class="muted">Could not load rising coins.</td></tr>';
185
+ });
186
+ }
187
+ renderRising();
188
+ setInterval(renderRising, 90000);
189
+
190
+ // Active Futures Positions
191
+ var POS_DATA = [];
192
+ var POS_SORT = { key: null, dir: -1 };
193
+ function posVal(k, p) {
194
+ if (k === 'symbol') return p.symbol || '';
195
+ if (k === 'lev') return Number(p.leverage || 1);
196
+ if (k === 'invested') return Number(p.invested || 0);
197
+ if (k === 'funding') return Number(p.funding_profit || 0);
198
+ if (k === 'realised') return Number(p.realised_pnl || 0);
199
+ if (k === 'pnl') return Number(p.pnl || 0);
200
+ if (k === 'duration') return p.opened_ms ? Date.now() - Number(p.opened_ms) : 0;
201
+ return 0;
202
+ }
203
+ function fmtDuration(ms) {
204
+ if (!ms || ms < 0 || isNaN(ms)) return '—';
205
+ var s = Math.floor(ms / 1000);
206
+ var d = Math.floor(s / 86400); s -= d * 86400;
207
+ var h = Math.floor(s / 3600); s -= h * 3600;
208
+ var m = Math.floor(s / 60);
209
+ if (d > 0) return d + 'd ' + h + 'h';
210
+ if (h > 0) return h + 'h ' + m + 'm';
211
+ if (m > 0) return m + 'm';
212
+ return s + 's';
213
+ }
214
+ function moneyCell(v, forceSign) {
215
+ var n = Number(v);
216
+ var col = n > 0 ? '#4ade80' : (n < 0 ? '#f87171' : '#e6edf3');
217
+ var s = forceSign ? (n > 0 ? '+' : '') : '';
218
+ return '<span style="color:' + col + ';font-weight:600;">' + s + '$' + Math.abs(n).toFixed(2) + '</span>';
219
+ }
220
+ function renderPositions() {
221
+ var tb = document.getElementById('positions-tbody');
222
+ if (!tb) return;
223
+ var rows = POS_DATA.slice();
224
+ if (POS_SORT.key) {
225
+ rows.sort(function (a, b) {
226
+ var va = posVal(POS_SORT.key, a), vb = posVal(POS_SORT.key, b);
227
+ var c = (typeof va === 'number' && typeof vb === 'number') ? va - vb
228
+ : String(va).toLowerCase() < String(vb).toLowerCase() ? -1 : 1;
229
+ return c * POS_SORT.dir;
230
+ });
231
+ }
232
+ if (!rows.length) {
233
+ tb.innerHTML = '<tr><td colspan="7" class="muted">No open futures positions.</td></tr>';
234
+ document.getElementById('positions-tfoot').innerHTML = '';
235
+ return;
236
+ }
237
+ tb.innerHTML = rows.map(function (p) {
238
+ return '<tr>'
239
+ + '<td>' + p.symbol + (p.side === 'Sell' ? ' <span style="color:#f87171;">(short)</span>' : '') + '</td>'
240
+ + '<td style="text-align:center;">' + (p.leverage || 1) + 'x</td>'
241
+ + '<td>$' + Number(p.invested || 0).toFixed(2) + '</td>'
242
+ + '<td>' + moneyCell(p.funding_profit, true) + '</td>'
243
+ + '<td>' + moneyCell(p.realised_pnl, true) + '</td>'
244
+ + '<td>' + moneyCell(p.pnl, true) + '</td>'
245
+ + '<td>' + fmtDuration(p.opened_ms ? Date.now() - Number(p.opened_ms) : 0) + '</td>'
246
+ + '</tr>';
247
+ }).join('');
248
+ var tInv = 0, tFund = 0, tPnl = 0;
249
+ POS_DATA.forEach(function (p) {
250
+ tInv += Number(p.invested || 0);
251
+ tFund += Number(p.funding_profit || 0);
252
+ tPnl += Number(p.pnl || 0);
253
+ });
254
+ document.getElementById('positions-tfoot').innerHTML =
255
+ '<tr><td class="muted">Total (' + POS_DATA.length + ')</td><td></td>'
256
+ + '<td style="font-weight:700;">$' + tInv.toFixed(2) + '</td>'
257
+ + '<td>' + moneyCell(tFund, true) + '</td>'
258
+ + '<td></td>'
259
+ + '<td>' + moneyCell(tPnl, true) + '</td>'
260
+ + '<td></td></tr>';
261
+ }
262
+ document.querySelectorAll('th.psort').forEach(function (th) {
263
+ th.addEventListener('click', function () {
264
+ var k = th.getAttribute('data-fkey');
265
+ if (POS_SORT.key === k) POS_SORT.dir = -POS_SORT.dir;
266
+ else { POS_SORT.key = k; POS_SORT.dir = k === 'symbol' ? 1 : -1; }
267
+ document.querySelectorAll('span.farrow').forEach(function (s) { s.textContent = ''; });
268
+ document.querySelector('span.farrow[data-fkey="' + k + '"]').textContent = POS_SORT.dir === 1 ? '▲' : '▼';
269
+ renderPositions();
270
+ });
271
+ });
272
+ function loadPositions() {
273
+ fetch('/api/futures-positions').then(function (r) { return r.json(); }).then(function (list) {
274
+ POS_DATA = (list && list.length) ? list : [];
275
+ renderPositions();
276
+ }).catch(function () {});
277
+ }
278
+ loadPositions();
279
+ setInterval(loadPositions, 90000);
280
+ </script>
281
+ <!--Start of Tawk.to Script-->
282
+ <script type="text/javascript">
283
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
284
+ (function(){
285
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
286
+ s1.async=true;
287
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
288
+ s1.charset='UTF-8';
289
+ s1.setAttribute('crossorigin','*');
290
+ s0.parentNode.insertBefore(s1,s0);
291
+ })();
292
+ </script>
293
+ <!--End of Tawk.to Script-->
294
+ </body>
295
+ </html>
static/favicon.svg CHANGED
static/financials/index.html ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Financials — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
9
+ <style>
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
11
+ .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
12
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
13
+ .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
14
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
15
+ .breadcrumbs .bc-current { color: #e6edf3; }
16
+ @media (max-width: 640px) { .breadcrumbs { display: none; } }
17
+
18
+ .perf-title { text-align: center; font-size: 26px; font-weight: 700; color: #f0b90b; margin: 8px 0 24px; letter-spacing: 0.5px; }
19
+ .pnl-card {
20
+ background: #1e2329;
21
+ border: 2px solid #30363d;
22
+ border-radius: 12px;
23
+ padding: 24px;
24
+ max-width: 560px;
25
+ margin: 0 auto;
26
+ }
27
+ .pnl-card-title { color: #f0b90b; font-size: 16px; font-weight: 700; text-align: center; margin-bottom: 4px; }
28
+ .pnl-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #21262d; font-size: 14px; }
29
+ .pnl-row-last { border-bottom: none; }
30
+ .pnl-label { color: #8b949e; }
31
+ .pnl-value { font-family: 'SF Mono', Monaco, monospace; color: #e6edf3; }
32
+ .pnl-value.positive { color: #4ade80; }
33
+ .pnl-value.negative { color: #f87171; }
34
+ .pnl-value.flat { color: #8b949e; }
35
+ </style>
36
+ </head>
37
+ <body>
38
+ <nav class="nav-bar">
39
+ <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
40
+ <div class="nav-links">
41
+ <a href="/scan/" class="nav-link">🔍 Scan</a>
42
+ <a href="/price/" class="nav-link">💵 ETH Price</a>
43
+ <a href="/financials/" class="nav-link active">📊 Financials</a>
44
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
45
+ </div>
46
+ </nav>
47
+
48
+ <div class="page-content">
49
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Financials</span></div>
50
+
51
+ <h1 class="perf-title">📊 Financials</h1>
52
+
53
+ <div class="pnl-card" style="max-width:760px;">
54
+ <div class="pnl-card-title">Equity Curve (Bybit Total)</div>
55
+ <div id="equity-chart" style="margin-top:8px;"></div>
56
+ <div id="equity-summary" class="hint" style="color:#8b949e;font-size:12px;text-align:center;margin-top:6px;"></div>
57
+ </div>
58
+
59
+ <div class="pnl-card" style="max-width:760px;">
60
+ <div class="pnl-card-title">Bybit Balances</div>
61
+ <div style="overflow-x:auto;">
62
+ <table style="width:100%;border-collapse:collapse;font-size:14px;">
63
+ <thead><tr>
64
+ <th style="text-align:left;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;"></th>
65
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">Current</th>
66
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">Yesterday</th>
67
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">7 Days</th>
68
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">30 Days</th>
69
+ </tr></thead>
70
+ <tbody>
71
+ <tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;font-weight:600;">Futures</span></td><td id="b-fut" style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">…</td><td id="d-fut-1" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-fut-7" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-fut-30" style="text-align:right;padding:.3rem .5rem;"></td></tr>
72
+ <tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;font-weight:600;">Grids</span></td><td id="b-grid" style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">…</td><td id="d-grid-1" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-grid-7" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-grid-30" style="text-align:right;padding:.3rem .5rem;"></td></tr>
73
+ <tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;font-weight:600;">Spot</span></td><td id="b-spot" style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">…</td><td id="d-spot-1" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-spot-7" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-spot-30" style="text-align:right;padding:.3rem .5rem;"></td></tr>
74
+ <tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;font-weight:600;">Available</span></td><td id="b-avail" style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">…</td><td id="d-avail-1" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-avail-7" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-avail-30" style="text-align:right;padding:.3rem .5rem;"></td></tr>
75
+ <tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;font-weight:600;">Equity</span></td><td id="b-total" style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">…</td><td id="d-total-1" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-total-7" style="text-align:right;padding:.3rem .5rem;"></td><td id="d-total-30" style="text-align:right;padding:.3rem .5rem;"></td></tr>
76
+ </tbody>
77
+ </table>
78
+ </div>
79
+ </div>
80
+
81
+ <div class="pnl-card" style="max-width:760px;">
82
+ <div class="pnl-card-title">Funding Fees</div>
83
+ <div style="overflow-x:auto;">
84
+ <table style="width:100%;border-collapse:collapse;font-size:14px;">
85
+ <thead><tr>
86
+ <th style="text-align:left;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;"></th>
87
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">7 Days</th>
88
+ <th style="text-align:right;font-weight:600;color:#8b949e;font-size:.8rem;padding:.25rem .5rem;">30 Days</th>
89
+ </tr></thead>
90
+ <tbody id="funding-tbody"><tr><td colspan="3" class="muted">Loading…</td></tr></tbody>
91
+ </table>
92
+ </div>
93
+ <div class="hint" id="funding-note" style="color:#8b949e;font-size:12px;text-align:center;margin-top:8px;"></div>
94
+ </div>
95
+
96
+ <div class="pnl-card">
97
+ <div class="pnl-card-title">Blind Monkeys Grid Returns</div>
98
+ <!-- Dartboard -->
99
+ <div style="display:flex;justify-content:center;margin:16px 0 20px 0;">
100
+ <svg id="dartboard" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98" width="200" height="200" <!-- dartboard-tunnel-applied --><!-- dartboard-tunnel-fix-applied -->aria-label="Win rate indicator"><style id="dartboard-tunnel-css">#dartboard #ring-outer,#dartboard #ring-middle,#dartboard #ring-inner,#dartboard #ring-outer-2,#dartboard > ellipse:nth-of-type(2),#dartboard > ellipse:nth-of-type(4) { transform-box: fill-box; transform-origin: center; animation: db-blink 2s infinite;}#dartboard #ring-outer { animation-delay: 0s; }#dartboard > ellipse:nth-of-type(2) { animation-delay: 0.3s; }#dartboard #ring-middle { animation-delay: 0.6s; }#dartboard > ellipse:nth-of-type(4) { animation-delay: 0.9s; }#dartboard #ring-inner { animation-delay: 1.2s; }@keyframes db-blink { 0% { opacity: 1; } 49% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; }}</style><defs><linearGradient id="a" x1="-99.04" y1="372.9" x2="-162.46" y2="372.9" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#e66969"/><stop offset="0.75" stop-color="#ffbaba"/><stop offset="1" stop-color="#fc7373"/></linearGradient><linearGradient id="b" x1="-99.04" y1="369.84" x2="-162.46" y2="369.84" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#f87a7a"/><stop offset="0.77" stop-color="#ffc9c9"/><stop offset="1" stop-color="#ff8080"/></linearGradient><clipPath id="c"><path d="M76.8,44.28l-23-.05-.47.47L78.1,59.44A28.75,28.75,0,0,0,76.8,44.28Z" style="fill:none"/></clipPath><radialGradient id="d" cx="52.2" cy="50.58" r="23.4" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2f3235"/><stop offset="1" stop-color="#2f3235" stop-opacity="0"/></radialGradient><linearGradient id="e" x1="10.11" y1="222.23" x2="18.02" y2="222.23" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#40bf6e"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="f" x1="14.48" y1="225.2" x2="28.04" y2="217.81" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#39ab62"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="g" x1="19.62" y1="238.21" x2="16.43" y2="238.21" gradientTransform="matrix(0, 1, -1, 0, 300.68, 17.51)" gradientUnits="userSpaceOnUse"><stop offset="0.21" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.89" stop-color="#4ade80"/></linearGradient><linearGradient id="h" x1="18.61" y1="223.72" x2="17.44" y2="223.72" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.03" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.95" stop-color="#4ade80"/></linearGradient></defs><path d="M27.48,25.68l-3.81,3.81C13.76,39.39,15.6,57.63,28,70s30.62,14.23,40.52,4.32l3.81-3.81Z" style="fill:url(#a)"/><path d="M28.1,25.05l-.9.9c-9.91,9.91-7.9,28,4.49,40.36s30.45,14.4,40.36,4.49l.9-.9Z" style="fill:url(#b)"/><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer" cx="49.9" cy="48.1" rx="25.36" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer-2" cx="49.9" cy="48.1" rx="25.37" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-18.23 49.85) rotate(-45)"><ellipse cx="51.06" cy="46.94" rx="20.45" ry="25.56" style="fill:#fff"/></g><g transform="translate(-17.4 50.2) rotate(-45)"><ellipse id="ring-middle" cx="51.89" cy="46.11" rx="15.82" ry="19.78" style="fill:#f0b90b"/></g><g transform="translate(-16.66 50.51) rotate(-45)"><ellipse cx="52.64" cy="45.36" rx="10.97" ry="13.72" style="fill:#fff"/></g><g transform="translate(-15.99 50.78) rotate(-45)"><ellipse id="ring-inner" cx="53.3" cy="44.7" rx="6.59" ry="8.23" style="fill:#4ade80"/></g><g style="clip-path:url(#c)"><circle cx="52.2" cy="50.58" r="23.4" style="opacity:0.5;fill:url(#d)"/></g><path d="M79,19l-3.66-6.6s-3.13.5-5.79,6.76a30.15,30.15,0,0,0-2.46,11.75Z" style="fill:url(#e)"/><path d="M79,19l6.6,3.66s-.5,3.13-6.76,5.79a30.15,30.15,0,0,1-11.75,2.46Z" style="fill:url(#f)"/><g transform="translate(-6.83 54.58) rotate(-45)"><ellipse cx="62.47" cy="35.53" rx="12.96" ry="1.59" style="fill:url(#g)"/></g><path d="M79.17,19.67c-6.69,6.68-12.3,11.92-12.53,11.69s5-5.84,11.69-12.53A3.72,3.72,0,0,1,79.17,19.67Z" style="fill:url(#h)"/><path d="M79.81,18.89,81,17.41a11.52,11.52,0,0,0,1-1.46,11.52,11.52,0,0,0-1.46,1l-1.48,1.23s-1.19-1.91-1.61-2.55c-.53-.8-2.17-3.23-2.17-3.23s1.1,2.66,1.51,3.52,1.52,2.93,1.52,2.93-1,1-1.41,1.47a18.45,18.45,0,0,0-1.54,2.26,18.45,18.45,0,0,0,2.26-1.54c.51-.45,1.47-1.41,1.47-1.41s2,1.11,2.71,1.44c.91.42,3.74,1.59,3.74,1.59S83.14,21,82.3,20.42C81.69,20,79.81,18.89,79.81,18.89Z" style="fill:#67e892"/></svg>
101
+ </div>
102
+
103
+ <!-- Benchmark vs. Grid returns -->
104
+ <div style="font-size:14px;">
105
+ <div class="pnl-row">
106
+ <span class="pnl-label">S&amp;P 500 Return Last 30 Days</span>
107
+ <span class="pnl-value" id="sp500-30d">—</span>
108
+ </div>
109
+ <div class="pnl-row">
110
+ <span class="pnl-label">Our Grid Bot Return Last 30 Days</span>
111
+ <span class="pnl-value" id="grid-30d">—</span>
112
+ </div>
113
+ <div class="pnl-row pnl-row-last">
114
+ <span class="pnl-label">Our Grid Bot Win Rate</span>
115
+ <span class="pnl-value" id="grid-winrate">—</span>
116
+ </div>
117
+ </div>
118
+
119
+ <div style="margin-top:12px;text-align:center;">
120
+ <a href="/dart-performance" style="color:#f0b90b;font-size:12px;font-weight:600;text-decoration:none;">Dart Performance Detail →</a>
121
+ </div>
122
+ </div>
123
+
124
+ <div class="pnl-card" style="margin-top:20px;">
125
+ <div class="pnl-card-title">Blind Monkeys Futures Performance</div>
126
+ <!-- Dartboard -->
127
+ <div style="display:flex;justify-content:center;margin:16px 0 20px 0;">
128
+ <svg id="dartboard-fut" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98" width="200" height="200" <!-- dartboard-tunnel-applied --><!-- dartboard-tunnel-fix-applied -->aria-label="Win rate indicator"><style id="dartboard-fut-tunnel-css">#dartboard-fut #ring-outer,#dartboard-fut #ring-middle,#dartboard-fut #ring-inner,#dartboard-fut #ring-outer-2,#dartboard-fut > ellipse:nth-of-type(2),#dartboard-fut > ellipse:nth-of-type(4) { transform-box: fill-box; transform-origin: center; animation: db-blink 2s infinite;}#dartboard-fut #ring-outer { animation-delay: 0s; }#dartboard-fut > ellipse:nth-of-type(2) { animation-delay: 0.3s; }#dartboard-fut #ring-middle { animation-delay: 0.6s; }#dartboard-fut > ellipse:nth-of-type(4) { animation-delay: 0.9s; }#dartboard-fut #ring-inner { animation-delay: 1.2s; }@keyframes db-blink { 0% { opacity: 1; } 49% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; }}</style><defs><linearGradient id="a" x1="-99.04" y1="372.9" x2="-162.46" y2="372.9" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#e66969"/><stop offset="0.75" stop-color="#ffbaba"/><stop offset="1" stop-color="#fc7373"/></linearGradient><linearGradient id="b" x1="-99.04" y1="369.84" x2="-162.46" y2="369.84" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#f87a7a"/><stop offset="0.77" stop-color="#ffc9c9"/><stop offset="1" stop-color="#ff8080"/></linearGradient><clipPath id="c"><path d="M76.8,44.28l-23-.05-.47.47L78.1,59.44A28.75,28.75,0,0,0,76.8,44.28Z" style="fill:none"/></clipPath><radialGradient id="d" cx="52.2" cy="50.58" r="23.4" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2f3235"/><stop offset="1" stop-color="#2f3235" stop-opacity="0"/></radialGradient><linearGradient id="e" x1="10.11" y1="222.23" x2="18.02" y2="222.23" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#40bf6e"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="f" x1="14.48" y1="225.2" x2="28.04" y2="217.81" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#39ab62"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="g" x1="19.62" y1="238.21" x2="16.43" y2="238.21" gradientTransform="matrix(0, 1, -1, 0, 300.68, 17.51)" gradientUnits="userSpaceOnUse"><stop offset="0.21" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.89" stop-color="#4ade80"/></linearGradient><linearGradient id="h" x1="18.61" y1="223.72" x2="17.44" y2="223.72" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.03" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.95" stop-color="#4ade80"/></linearGradient></defs><path d="M27.48,25.68l-3.81,3.81C13.76,39.39,15.6,57.63,28,70s30.62,14.23,40.52,4.32l3.81-3.81Z" style="fill:url(#a)"/><path d="M28.1,25.05l-.9.9c-9.91,9.91-7.9,28,4.49,40.36s30.45,14.4,40.36,4.49l.9-.9Z" style="fill:url(#b)"/><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer" cx="49.9" cy="48.1" rx="25.36" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer-2" cx="49.9" cy="48.1" rx="25.37" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-18.23 49.85) rotate(-45)"><ellipse cx="51.06" cy="46.94" rx="20.45" ry="25.56" style="fill:#fff"/></g><g transform="translate(-17.4 50.2) rotate(-45)"><ellipse id="ring-middle" cx="51.89" cy="46.11" rx="15.82" ry="19.78" style="fill:#f0b90b"/></g><g transform="translate(-16.66 50.51) rotate(-45)"><ellipse cx="52.64" cy="45.36" rx="10.97" ry="13.72" style="fill:#fff"/></g><g transform="translate(-15.99 50.78) rotate(-45)"><ellipse id="ring-inner" cx="53.3" cy="44.7" rx="6.59" ry="8.23" style="fill:#4ade80"/></g><g style="clip-path:url(#c)"><circle cx="52.2" cy="50.58" r="23.4" style="opacity:0.5;fill:url(#d)"/></g><path d="M79,19l-3.66-6.6s-3.13.5-5.79,6.76a30.15,30.15,0,0,0-2.46,11.75Z" style="fill:url(#e)"/><path d="M79,19l6.6,3.66s-.5,3.13-6.76,5.79a30.15,30.15,0,0,1-11.75,2.46Z" style="fill:url(#f)"/><g transform="translate(-6.83 54.58) rotate(-45)"><ellipse cx="62.47" cy="35.53" rx="12.96" ry="1.59" style="fill:url(#g)"/></g><path d="M79.17,19.67c-6.69,6.68-12.3,11.92-12.53,11.69s5-5.84,11.69-12.53A3.72,3.72,0,0,1,79.17,19.67Z" style="fill:url(#h)"/><path d="M79.81,18.89,81,17.41a11.52,11.52,0,0,0,1-1.46,11.52,11.52,0,0,0-1.46,1l-1.48,1.23s-1.19-1.91-1.61-2.55c-.53-.8-2.17-3.23-2.17-3.23s1.1,2.66,1.51,3.52,1.52,2.93,1.52,2.93-1,1-1.41,1.47a18.45,18.45,0,0,0-1.54,2.26,18.45,18.45,0,0,0,2.26-1.54c.51-.45,1.47-1.41,1.47-1.41s2,1.11,2.71,1.44c.91.42,3.74,1.59,3.74,1.59S83.14,21,82.3,20.42C81.69,20,79.81,18.89,79.81,18.89Z" style="fill:#67e892"/></svg>
129
+ </div>
130
+
131
+ <!-- Futures performance -->
132
+ <div style="font-size:14px;">
133
+ <div class="pnl-row">
134
+ <span class="pnl-label">S&amp;P 500 Return Last 30 Days</span>
135
+ <span class="pnl-value" id="fut-sp500">—</span>
136
+ </div>
137
+ <div class="pnl-row">
138
+ <span class="pnl-label">Our Futures Bot Return Last 30 Days</span>
139
+ <span class="pnl-value" id="fut-30d">—</span>
140
+ </div>
141
+ <div class="pnl-row pnl-row-last">
142
+ <span class="pnl-label">Our Futures Bot Win Rate</span>
143
+ <span class="pnl-value" id="fut-winrate">—</span>
144
+ </div>
145
+ </div>
146
+ </div>
147
+
148
+ </div>
149
+
150
+ <script>
151
+ function setT(id, t) { var e = document.getElementById(id); if (e) e.innerHTML = t; }
152
+ function dstr(off) {
153
+ var d = new Date(); d.setUTCDate(d.getUTCDate() - off);
154
+ return d.getUTCFullYear() + '-' + String(d.getUTCMonth() + 1).padStart(2, '0') + '-' + String(d.getUTCDate()).padStart(2, '0');
155
+ }
156
+ function snapEq(s) { return Number(s.fund_usdt || 0) + Number(s.unified_total || 0) + Number(s.investment_total || 0); }
157
+ function rowDelta(cur, snap, field) {
158
+ if (!snap) return null;
159
+ var sv = field === 'equity' ? snapEq(snap) : Number(snap[field] || 0);
160
+ return cur - sv;
161
+ }
162
+ function fmtD(v) {
163
+ if (v === null || v === undefined || isNaN(v)) return '<span style="color:#8b949e;">&mdash;</span>';
164
+ var c = v >= 0 ? '#4ade80' : '#f87171';
165
+ var s = v >= 0 ? '+' : '-';
166
+ return '<span style="color:' + c + ';font-weight:700;">' + s + '$' + Math.abs(v).toFixed(2) + '</span>';
167
+ }
168
+ var BM = { history: {} };
169
+ function setChanges(pre, cur, field) {
170
+ [1, 7, 30].forEach(function (off) {
171
+ setT('d-' + pre + '-' + off, fmtD(rowDelta(cur, BM.history[dstr(off)], field)));
172
+ });
173
+ }
174
+ function renderBalance() {
175
+ var fut = Number(BM.fut || 0), grid = Number(BM.invest || 0), spot = Number(BM.spot || 0),
176
+ avail = Number(BM.fund || 0), uni = Number(BM.uni || 0);
177
+ var eq = avail + uni + grid;
178
+ setT('b-fut', '$' + fut.toFixed(2));
179
+ setT('b-grid', '$' + grid.toFixed(2));
180
+ setT('b-spot', '$' + spot.toFixed(2));
181
+ setT('b-avail', '$' + avail.toFixed(2));
182
+ setT('b-total', '$' + eq.toFixed(2) + (BM.mode === 'DRY-RUN' ? ' (DRY-RUN)' : ''));
183
+ setChanges('fut', fut, 'futures_combo');
184
+ setChanges('grid', grid, 'investment_total');
185
+ setChanges('spot', spot, 'spot_total');
186
+ setChanges('avail', avail, 'fund_usdt');
187
+ setChanges('total', eq, 'equity');
188
+ }
189
+ function loadBalance() {
190
+ fetch('/api/bybit-balance').then(function (r) { return r.json(); }).then(function (b) {
191
+ BM.fut = Number(b.futures_combo || 0); BM.spot = Number(b.spot_total || 0);
192
+ BM.fund = Number(b.fund_usdt || 0); BM.uni = Number(b.unified_total || 0);
193
+ BM.invest = Number(b.investment_total || 0); BM.mode = b.mode;
194
+ renderBalance();
195
+ }).catch(function () {});
196
+ }
197
+ function renderEquityChart() {
198
+ var el = document.getElementById('equity-chart');
199
+ if (!el) return;
200
+ var fine = (BM.fine || []).map(function (p) {
201
+ return { ms: Number(p.ms), v: Number(p.equity) };
202
+ });
203
+ var minFineMs = fine.length ? Math.min.apply(null, fine.map(function (p) { return p.ms; })) : Infinity;
204
+ var pts = [];
205
+ Object.keys(BM.history || {}).sort().forEach(function (d) {
206
+ var ms = Date.parse(d + 'T12:00:00Z');
207
+ if (ms < minFineMs) pts.push({ ms: ms, v: snapEq(BM.history[d]) });
208
+ });
209
+ // Downsample the 15-minute points to one per 30 minutes.
210
+ var lastMs = -1e15;
211
+ fine.sort(function (a, b) { return a.ms - b.ms; }).forEach(function (p) {
212
+ if (p.ms - lastMs >= 30 * 60 * 1000) { pts.push(p); lastMs = p.ms; }
213
+ });
214
+ pts.sort(function (a, b) { return a.ms - b.ms; });
215
+ var msFirst = pts.length ? pts[0].ms : 0, msLast = pts.length ? pts[pts.length - 1].ms : 0;
216
+ if (pts.length < 2) {
217
+ el.innerHTML = '<div class="hint" style="color:#8b949e;text-align:center;padding:2rem 0;">Equity curve builds up as snapshots accumulate (needs 2+ points).</div>';
218
+ return;
219
+ }
220
+ var series = pts.map(function (p) {
221
+ var iso = new Date(p.ms).toISOString();
222
+ return [iso.slice(5, 10) + ' ' + iso.slice(11, 16), p.v];
223
+ });
224
+ var vals = series.map(function (s) { return s[1]; });
225
+ var min = Math.min.apply(null, vals), max = Math.max.apply(null, vals);
226
+ if (max - min < 1) { min -= 1; max += 1; }
227
+ var W = 720, H = 170, pad = 34;
228
+ var pts = series.map(function (s, i) {
229
+ var x = pad + (i / (series.length - 1)) * (W - 2 * pad);
230
+ var y = pad + (1 - (s[1] - min) / (max - min)) * (H - 2 * pad);
231
+ return [x, y, s[1], s[0]];
232
+ });
233
+ var line = pts.map(function (p) { return p[0].toFixed(1) + ',' + p[1].toFixed(1); }).join(' ');
234
+ var area = line + ' ' + (W - pad) + ',' + (H - 6) + ' ' + pad + ',' + (H - 6);
235
+ var svg = '<svg viewBox="0 0 ' + W + ' ' + H + '" style="width:100%;height:auto;" xmlns="http://www.w3.org/2000/svg">'
236
+ + '<defs><linearGradient id="eqgrad" x1="0" y1="0" x2="0" y2="1">'
237
+ + '<stop offset="0%" stop-color="#f0b90b" stop-opacity="0.18"/>'
238
+ + '<stop offset="100%" stop-color="#f0b90b" stop-opacity="0"/></linearGradient></defs>'
239
+ + '<line x1="' + pad + '" y1="' + (H - 6) + '" x2="' + (W - pad) + '" y2="' + (H - 6) + '" stroke="#21262d" stroke-width="1"/>'
240
+ + '<polygon points="' + area + '" fill="url(#eqgrad)"/>'
241
+ + '<polyline points="' + line + '" fill="none" stroke="#f0b90b" stroke-width="2.2"/>'
242
+ + '<circle cx="' + pts[pts.length - 1][0].toFixed(1) + '" cy="' + pts[pts.length - 1][1].toFixed(1) + '" r="3.4" fill="#f0b90b"/>'
243
+ + '<text x="' + pad + '" y="18" fill="#8b949e" font-size="11" font-family="monospace">$' + max.toFixed(2) + '</text>'
244
+ + '<text x="' + (W - pad) + '" y="18" text-anchor="end" fill="#8b949e" font-size="11" font-family="monospace">$' + min.toFixed(2) + '</text>'
245
+ + '<text x="' + pad + '" y="' + (H - 1) + '" fill="#8b949e" font-size="10" font-family="monospace">' + series[0][0].slice(5) + '</text>'
246
+ + '<text x="' + (W - pad) + '" y="' + (H - 1) + '" text-anchor="end" fill="#8b949e" font-size="10" font-family="monospace">' + series[series.length - 1][0].slice(5) + '</text>'
247
+ + '</svg>';
248
+ el.innerHTML = svg;
249
+ var first = vals[0], last = vals[vals.length - 1];
250
+ var chg = last - first;
251
+ var pct = first > 0 ? chg / first * 100 : 0;
252
+ var col = chg >= 0 ? '#4ade80' : '#f87171';
253
+ var summ = document.getElementById('equity-summary');
254
+ if (summ) {
255
+ var spanH = Math.round((msLast - msFirst) / 3600000);
256
+ summ.innerHTML = 'Last <b>$' + last.toFixed(2) + '</b> · change over ' + spanH + 'h: '
257
+ + '<b style="color:' + col + '">' + (chg >= 0 ? '+' : '') + '$' + chg.toFixed(2)
258
+ + ' (' + (pct >= 0 ? '+' : '') + pct.toFixed(2) + '%)</b> · points: ' + pts.length;
259
+ }
260
+ }
261
+
262
+ function loadBalanceHistory() {
263
+ fetch('https://scan.blind-monkeys.com/grid/equity-history').then(function (r) { return r.json(); }).then(function (f) {
264
+ BM.fine = f || []; renderEquityChart();
265
+ }).catch(function () {});
266
+ fetch('/api/balance-history').then(function (r) { return r.json(); }).then(function (h) {
267
+ BM.history = h || {}; renderBalance(); renderEquityChart();
268
+ }).catch(function () {});
269
+ }
270
+ loadBalance(); loadBalanceHistory();
271
+ setInterval(function () { loadBalance(); }, 60000);
272
+
273
+ function fmtMoney(v) {
274
+ if (v === null || v === undefined || isNaN(v)) return '<span style="color:#8b949e;">&mdash;</span>';
275
+ var c = v >= 0 ? '#4ade80' : '#f87171';
276
+ var s = v >= 0 ? '+' : '-';
277
+ return '<span style="color:' + c + ';font-weight:700;">' + s + '$' + Math.abs(v).toFixed(4) + '</span>';
278
+ }
279
+ function loadFunding() {
280
+ fetch('/api/funding-summary').then(function (r) { return r.json(); }).then(function (d) {
281
+ var tb = document.getElementById('funding-tbody');
282
+ if (!tb || !d || !d.d7) return;
283
+ var d7 = d.d7, d30 = d.d30 || {};
284
+ var rows = '';
285
+ rows += '<tr><td style="padding:.3rem .5rem;"><span style="color:#8b949e;font-weight:600;">Received</span></td>'
286
+ + '<td style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">+$' + (d7.received || 0).toFixed(4) + '</td>'
287
+ + '<td style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#4ade80;">+$' + (d30.received || 0).toFixed(4) + '</td></tr>';
288
+ rows += '<tr><td style="padding:.3rem .5rem;"><span style="color:#8b949e;font-weight:600;">Paid</span></td>'
289
+ + '<td style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#f87171;">-$' + (d7.paid || 0).toFixed(4) + '</td>'
290
+ + '<td style="text-align:right;padding:.3rem .5rem;font-weight:700;color:#f87171;">-$' + (d30.paid || 0).toFixed(4) + '</td></tr>';
291
+ rows += '<tr><td style="padding:.3rem .5rem;"><span style="color:#8b949e;font-weight:600;">Net</span></td>'
292
+ + '<td style="text-align:right;padding:.3rem .5rem;">' + fmtMoney(d7.net) + '</td>'
293
+ + '<td style="text-align:right;padding:.3rem .5rem;">' + fmtMoney(d30.net) + '</td></tr>';
294
+ var syms = Object.keys(d30.by_symbol || {});
295
+ if (syms.length) {
296
+ rows += '<tr><td colspan="3" style="padding:.2rem .5rem;color:#484f58;">&mdash; by symbol &mdash;</td></tr>';
297
+ syms.forEach(function (s) {
298
+ rows += '<tr><td style="padding:.3rem .5rem;white-space:nowrap;"><span style="color:#8b949e;">' + s + '</span></td>'
299
+ + '<td style="text-align:right;padding:.3rem .5rem;">' + fmtMoney((d7.by_symbol || {})[s]) + '</td>'
300
+ + '<td style="text-align:right;padding:.3rem .5rem;">' + fmtMoney(d30.by_symbol[s]) + '</td></tr>';
301
+ });
302
+ }
303
+ tb.innerHTML = rows;
304
+ var note = document.getElementById('funding-note');
305
+ if (note) note.textContent = 'Funding settles every 8 hours — negative rates pay longs (green), positive rates charge longs (red).';
306
+ }).catch(function () {});
307
+ }
308
+ loadFunding();
309
+
310
+ function setPct(id, pct) {
311
+ var el = document.getElementById(id);
312
+ if (!el) return;
313
+ el.textContent = (pct >= 0 ? '+' : '') + pct.toFixed(2) + '%';
314
+ el.classList.remove('positive', 'negative', 'flat');
315
+ el.classList.add(pct > 0 ? 'positive' : (pct < 0 ? 'negative' : 'flat'));
316
+ }
317
+ function loadPanelReturns() {
318
+ fetch('/api/sp500-30d').then(function(r){ return r.json(); }).then(function(d) {
319
+ if (d && d.status === 'ok') setPct('sp500-30d', parseFloat(d.return_pct) || 0);
320
+ }).catch(function(){});
321
+ fetch('/api/grid-returns').then(function(r){ return r.json(); }).then(function(d) {
322
+ if (d && d.status === 'ok') {
323
+ setPct('grid-30d', parseFloat(d.return_pct) || 0);
324
+ var wr = document.getElementById('grid-winrate');
325
+ if (wr) {
326
+ var rate = parseFloat(d.win_rate) || 0;
327
+ wr.textContent = rate.toFixed(1) + '% (' + (d.wins || 0) + '/' + (d.closed || 0) + ')';
328
+ wr.classList.remove('positive', 'negative', 'flat');
329
+ wr.classList.add(rate > 50 ? 'positive' : (rate < 50 ? 'negative' : 'flat'));
330
+ }
331
+ }
332
+ }).catch(function(){});
333
+ }
334
+ loadPanelReturns();
335
+ setInterval(loadPanelReturns, 3600000);
336
+ function loadFuturesReturns() {
337
+ fetch('/api/sp500-30d').then(function(r){ return r.json(); }).then(function(d) {
338
+ if (d && d.status === 'ok') setPct('fut-sp500', parseFloat(d.return_pct) || 0);
339
+ }).catch(function(){});
340
+ fetch('/api/bot-pnl').then(function(r){ return r.json(); }).then(function(d) {
341
+ if (d && d.status === 'ok') {
342
+ var margin = parseFloat(d.total_margin) || 0;
343
+ var pnl30 = parseFloat(d.pnl_30d);
344
+ if (margin > 0 && !isNaN(pnl30)) setPct('fut-30d', (pnl30 / margin) * 100);
345
+ }
346
+ }).catch(function(){});
347
+ fetch('/api/win-rate').then(function(r){ return r.json(); }).then(function(d) {
348
+ if (d && d.status === 'ok' && d.win_rate != null) {
349
+ var el = document.getElementById('fut-winrate');
350
+ if (el) {
351
+ var rate = parseFloat(d.win_rate) || 0;
352
+ el.textContent = rate.toFixed(1) + '% (' + (d.wins || 0) + '/' + (d.total_bots || 0) + ')';
353
+ el.classList.remove('positive', 'negative', 'flat');
354
+ el.classList.add(rate > 50 ? 'positive' : (rate < 50 ? 'negative' : 'flat'));
355
+ }
356
+ }
357
+ }).catch(function(){});
358
+ }
359
+ loadFuturesReturns();
360
+ setInterval(loadFuturesReturns, 3600000);
361
+
362
+ </script>
363
+ <script src="/css/nav.js"></script>
364
+ </body>
365
+ </html>
static/index.html CHANGED
@@ -477,5 +477,18 @@
477
  #hsAlertB',anner .hs-dismiss:hover { background:#f0b90b; color:#0b0e11; }
478
  </style>
479
  <script src="/static/alerts.js?v=1"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  </body>
481
  </html>
 
477
  #hsAlertB',anner .hs-dismiss:hover { background:#f0b90b; color:#0b0e11; }
478
  </style>
479
  <script src="/static/alerts.js?v=1"></script>
480
+ <!--Start of Tawk.to Script-->
481
+ <script type="text/javascript">
482
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
483
+ (function(){
484
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
485
+ s1.async=true;
486
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
487
+ s1.charset='UTF-8';
488
+ s1.setAttribute('crossorigin','*');
489
+ s0.parentNode.insertBefore(s1,s0);
490
+ })();
491
+ </script>
492
+ <!--End of Tawk.to Script-->
493
  </body>
494
  </html>
static/performance/index.html ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Performance — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
9
+ <style>
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
11
+ .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
12
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
13
+ .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
14
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
15
+ .breadcrumbs .bc-current { color: #e6edf3; }
16
+ @media (max-width: 640px) { .breadcrumbs { display: none; } }
17
+
18
+ .perf-title { text-align: center; font-size: 26px; font-weight: 700; color: #f0b90b; margin: 8px 0 24px; letter-spacing: 0.5px; }
19
+ .pnl-card {
20
+ background: #1e2329;
21
+ border: 2px solid #30363d;
22
+ border-radius: 12px;
23
+ padding: 24px;
24
+ max-width: 560px;
25
+ margin: 0 auto;
26
+ }
27
+ .pnl-card-title { color: #f0b90b; font-size: 16px; font-weight: 700; text-align: center; margin-bottom: 4px; }
28
+ .pnl-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #21262d; font-size: 14px; }
29
+ .pnl-row-last { border-bottom: none; }
30
+ .pnl-label { color: #8b949e; }
31
+ .pnl-value { font-family: 'SF Mono', Monaco, monospace; color: #e6edf3; }
32
+ .pnl-value.positive { color: #4ade80; }
33
+ .pnl-value.negative { color: #f87171; }
34
+ .pnl-value.flat { color: #8b949e; }
35
+ </style>
36
+ </head>
37
+ <body>
38
+ <nav class="nav-bar">
39
+ <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
40
+ <div class="nav-links">
41
+ <a href="/scan/" class="nav-link">🔍 Scan</a>
42
+ <a href="/price/" class="nav-link">💵 ETH Price</a>
43
+ <a href="/performance/" class="nav-link active">📊 Performance</a>
44
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
45
+ </div>
46
+ </nav>
47
+
48
+ <div class="page-content">
49
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Performance</span></div>
50
+
51
+ <h1 class="perf-title">📊 Performance</h1>
52
+
53
+ <div class="pnl-card">
54
+ <div class="pnl-card-title">Blind Monkeys Grid Returns</div>
55
+ <!-- Dartboard -->
56
+ <div style="display:flex;justify-content:center;margin:16px 0 20px 0;">
57
+ <svg id="dartboard" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98" width="200" height="200" <!-- dartboard-tunnel-applied --><!-- dartboard-tunnel-fix-applied -->aria-label="Win rate indicator"><style id="dartboard-tunnel-css">#dartboard #ring-outer,#dartboard #ring-middle,#dartboard #ring-inner,#dartboard #ring-outer-2,#dartboard > ellipse:nth-of-type(2),#dartboard > ellipse:nth-of-type(4) { transform-box: fill-box; transform-origin: center; animation: db-blink 2s infinite;}#dartboard #ring-outer { animation-delay: 0s; }#dartboard > ellipse:nth-of-type(2) { animation-delay: 0.3s; }#dartboard #ring-middle { animation-delay: 0.6s; }#dartboard > ellipse:nth-of-type(4) { animation-delay: 0.9s; }#dartboard #ring-inner { animation-delay: 1.2s; }@keyframes db-blink { 0% { opacity: 1; } 49% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; }}</style><defs><linearGradient id="a" x1="-99.04" y1="372.9" x2="-162.46" y2="372.9" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#e66969"/><stop offset="0.75" stop-color="#ffbaba"/><stop offset="1" stop-color="#fc7373"/></linearGradient><linearGradient id="b" x1="-99.04" y1="369.84" x2="-162.46" y2="369.84" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#f87a7a"/><stop offset="0.77" stop-color="#ffc9c9"/><stop offset="1" stop-color="#ff8080"/></linearGradient><clipPath id="c"><path d="M76.8,44.28l-23-.05-.47.47L78.1,59.44A28.75,28.75,0,0,0,76.8,44.28Z" style="fill:none"/></clipPath><radialGradient id="d" cx="52.2" cy="50.58" r="23.4" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2f3235"/><stop offset="1" stop-color="#2f3235" stop-opacity="0"/></radialGradient><linearGradient id="e" x1="10.11" y1="222.23" x2="18.02" y2="222.23" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#40bf6e"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="f" x1="14.48" y1="225.2" x2="28.04" y2="217.81" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#39ab62"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="g" x1="19.62" y1="238.21" x2="16.43" y2="238.21" gradientTransform="matrix(0, 1, -1, 0, 300.68, 17.51)" gradientUnits="userSpaceOnUse"><stop offset="0.21" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.89" stop-color="#4ade80"/></linearGradient><linearGradient id="h" x1="18.61" y1="223.72" x2="17.44" y2="223.72" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.03" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.95" stop-color="#4ade80"/></linearGradient></defs><path d="M27.48,25.68l-3.81,3.81C13.76,39.39,15.6,57.63,28,70s30.62,14.23,40.52,4.32l3.81-3.81Z" style="fill:url(#a)"/><path d="M28.1,25.05l-.9.9c-9.91,9.91-7.9,28,4.49,40.36s30.45,14.4,40.36,4.49l.9-.9Z" style="fill:url(#b)"/><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer" cx="49.9" cy="48.1" rx="25.36" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer-2" cx="49.9" cy="48.1" rx="25.37" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-18.23 49.85) rotate(-45)"><ellipse cx="51.06" cy="46.94" rx="20.45" ry="25.56" style="fill:#fff"/></g><g transform="translate(-17.4 50.2) rotate(-45)"><ellipse id="ring-middle" cx="51.89" cy="46.11" rx="15.82" ry="19.78" style="fill:#f0b90b"/></g><g transform="translate(-16.66 50.51) rotate(-45)"><ellipse cx="52.64" cy="45.36" rx="10.97" ry="13.72" style="fill:#fff"/></g><g transform="translate(-15.99 50.78) rotate(-45)"><ellipse id="ring-inner" cx="53.3" cy="44.7" rx="6.59" ry="8.23" style="fill:#4ade80"/></g><g style="clip-path:url(#c)"><circle cx="52.2" cy="50.58" r="23.4" style="opacity:0.5;fill:url(#d)"/></g><path d="M79,19l-3.66-6.6s-3.13.5-5.79,6.76a30.15,30.15,0,0,0-2.46,11.75Z" style="fill:url(#e)"/><path d="M79,19l6.6,3.66s-.5,3.13-6.76,5.79a30.15,30.15,0,0,1-11.75,2.46Z" style="fill:url(#f)"/><g transform="translate(-6.83 54.58) rotate(-45)"><ellipse cx="62.47" cy="35.53" rx="12.96" ry="1.59" style="fill:url(#g)"/></g><path d="M79.17,19.67c-6.69,6.68-12.3,11.92-12.53,11.69s5-5.84,11.69-12.53A3.72,3.72,0,0,1,79.17,19.67Z" style="fill:url(#h)"/><path d="M79.81,18.89,81,17.41a11.52,11.52,0,0,0,1-1.46,11.52,11.52,0,0,0-1.46,1l-1.48,1.23s-1.19-1.91-1.61-2.55c-.53-.8-2.17-3.23-2.17-3.23s1.1,2.66,1.51,3.52,1.52,2.93,1.52,2.93-1,1-1.41,1.47a18.45,18.45,0,0,0-1.54,2.26,18.45,18.45,0,0,0,2.26-1.54c.51-.45,1.47-1.41,1.47-1.41s2,1.11,2.71,1.44c.91.42,3.74,1.59,3.74,1.59S83.14,21,82.3,20.42C81.69,20,79.81,18.89,79.81,18.89Z" style="fill:#67e892"/></svg>
58
+ </div>
59
+
60
+ <!-- Benchmark vs. Grid returns -->
61
+ <div style="font-size:14px;">
62
+ <div class="pnl-row">
63
+ <span class="pnl-label">S&amp;P 500 Return Last 30 Days</span>
64
+ <span class="pnl-value" id="sp500-30d">—</span>
65
+ </div>
66
+ <div class="pnl-row">
67
+ <span class="pnl-label">Our Grid Bot Return Last 30 Days</span>
68
+ <span class="pnl-value" id="grid-30d">—</span>
69
+ </div>
70
+ <div class="pnl-row pnl-row-last">
71
+ <span class="pnl-label">Our Grid Bot Win Rate</span>
72
+ <span class="pnl-value" id="grid-winrate">—</span>
73
+ </div>
74
+ </div>
75
+
76
+ <div style="margin-top:12px;text-align:center;">
77
+ <a href="/dart-performance" style="color:#f0b90b;font-size:12px;font-weight:600;text-decoration:none;">Dart Performance Detail →</a>
78
+ </div>
79
+ </div>
80
+
81
+ <div class="pnl-card" style="margin-top:20px;">
82
+ <div class="pnl-card-title">Blind Monkeys Futures Performance</div>
83
+ <!-- Dartboard -->
84
+ <div style="display:flex;justify-content:center;margin:16px 0 20px 0;">
85
+ <svg id="dartboard-fut" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98" width="200" height="200" <!-- dartboard-tunnel-applied --><!-- dartboard-tunnel-fix-applied -->aria-label="Win rate indicator"><style id="dartboard-fut-tunnel-css">#dartboard-fut #ring-outer,#dartboard-fut #ring-middle,#dartboard-fut #ring-inner,#dartboard-fut #ring-outer-2,#dartboard-fut > ellipse:nth-of-type(2),#dartboard-fut > ellipse:nth-of-type(4) { transform-box: fill-box; transform-origin: center; animation: db-blink 2s infinite;}#dartboard-fut #ring-outer { animation-delay: 0s; }#dartboard-fut > ellipse:nth-of-type(2) { animation-delay: 0.3s; }#dartboard-fut #ring-middle { animation-delay: 0.6s; }#dartboard-fut > ellipse:nth-of-type(4) { animation-delay: 0.9s; }#dartboard-fut #ring-inner { animation-delay: 1.2s; }@keyframes db-blink { 0% { opacity: 1; } 49% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; }}</style><defs><linearGradient id="a" x1="-99.04" y1="372.9" x2="-162.46" y2="372.9" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#e66969"/><stop offset="0.75" stop-color="#ffbaba"/><stop offset="1" stop-color="#fc7373"/></linearGradient><linearGradient id="b" x1="-99.04" y1="369.84" x2="-162.46" y2="369.84" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#f87a7a"/><stop offset="0.77" stop-color="#ffc9c9"/><stop offset="1" stop-color="#ff8080"/></linearGradient><clipPath id="c"><path d="M76.8,44.28l-23-.05-.47.47L78.1,59.44A28.75,28.75,0,0,0,76.8,44.28Z" style="fill:none"/></clipPath><radialGradient id="d" cx="52.2" cy="50.58" r="23.4" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2f3235"/><stop offset="1" stop-color="#2f3235" stop-opacity="0"/></radialGradient><linearGradient id="e" x1="10.11" y1="222.23" x2="18.02" y2="222.23" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#40bf6e"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="f" x1="14.48" y1="225.2" x2="28.04" y2="217.81" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#39ab62"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="g" x1="19.62" y1="238.21" x2="16.43" y2="238.21" gradientTransform="matrix(0, 1, -1, 0, 300.68, 17.51)" gradientUnits="userSpaceOnUse"><stop offset="0.21" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.89" stop-color="#4ade80"/></linearGradient><linearGradient id="h" x1="18.61" y1="223.72" x2="17.44" y2="223.72" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.03" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.95" stop-color="#4ade80"/></linearGradient></defs><path d="M27.48,25.68l-3.81,3.81C13.76,39.39,15.6,57.63,28,70s30.62,14.23,40.52,4.32l3.81-3.81Z" style="fill:url(#a)"/><path d="M28.1,25.05l-.9.9c-9.91,9.91-7.9,28,4.49,40.36s30.45,14.4,40.36,4.49l.9-.9Z" style="fill:url(#b)"/><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer" cx="49.9" cy="48.1" rx="25.36" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id="ring-outer-2" cx="49.9" cy="48.1" rx="25.37" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-18.23 49.85) rotate(-45)"><ellipse cx="51.06" cy="46.94" rx="20.45" ry="25.56" style="fill:#fff"/></g><g transform="translate(-17.4 50.2) rotate(-45)"><ellipse id="ring-middle" cx="51.89" cy="46.11" rx="15.82" ry="19.78" style="fill:#f0b90b"/></g><g transform="translate(-16.66 50.51) rotate(-45)"><ellipse cx="52.64" cy="45.36" rx="10.97" ry="13.72" style="fill:#fff"/></g><g transform="translate(-15.99 50.78) rotate(-45)"><ellipse id="ring-inner" cx="53.3" cy="44.7" rx="6.59" ry="8.23" style="fill:#4ade80"/></g><g style="clip-path:url(#c)"><circle cx="52.2" cy="50.58" r="23.4" style="opacity:0.5;fill:url(#d)"/></g><path d="M79,19l-3.66-6.6s-3.13.5-5.79,6.76a30.15,30.15,0,0,0-2.46,11.75Z" style="fill:url(#e)"/><path d="M79,19l6.6,3.66s-.5,3.13-6.76,5.79a30.15,30.15,0,0,1-11.75,2.46Z" style="fill:url(#f)"/><g transform="translate(-6.83 54.58) rotate(-45)"><ellipse cx="62.47" cy="35.53" rx="12.96" ry="1.59" style="fill:url(#g)"/></g><path d="M79.17,19.67c-6.69,6.68-12.3,11.92-12.53,11.69s5-5.84,11.69-12.53A3.72,3.72,0,0,1,79.17,19.67Z" style="fill:url(#h)"/><path d="M79.81,18.89,81,17.41a11.52,11.52,0,0,0,1-1.46,11.52,11.52,0,0,0-1.46,1l-1.48,1.23s-1.19-1.91-1.61-2.55c-.53-.8-2.17-3.23-2.17-3.23s1.1,2.66,1.51,3.52,1.52,2.93,1.52,2.93-1,1-1.41,1.47a18.45,18.45,0,0,0-1.54,2.26,18.45,18.45,0,0,0,2.26-1.54c.51-.45,1.47-1.41,1.47-1.41s2,1.11,2.71,1.44c.91.42,3.74,1.59,3.74,1.59S83.14,21,82.3,20.42C81.69,20,79.81,18.89,79.81,18.89Z" style="fill:#67e892"/></svg>
86
+ </div>
87
+
88
+ <!-- Futures performance -->
89
+ <div style="font-size:14px;">
90
+ <div class="pnl-row">
91
+ <span class="pnl-label">S&amp;P 500 Return Last 30 Days</span>
92
+ <span class="pnl-value" id="fut-sp500">—</span>
93
+ </div>
94
+ <div class="pnl-row">
95
+ <span class="pnl-label">Our Futures Bot Return Last 30 Days</span>
96
+ <span class="pnl-value" id="fut-30d">—</span>
97
+ </div>
98
+ <div class="pnl-row pnl-row-last">
99
+ <span class="pnl-label">Our Futures Bot Win Rate</span>
100
+ <span class="pnl-value" id="fut-winrate">—</span>
101
+ </div>
102
+ </div>
103
+ </div>
104
+
105
+ </div>
106
+
107
+ <script>
108
+ function setPct(id, pct) {
109
+ var el = document.getElementById(id);
110
+ if (!el) return;
111
+ el.textContent = (pct >= 0 ? '+' : '') + pct.toFixed(2) + '%';
112
+ el.classList.remove('positive', 'negative', 'flat');
113
+ el.classList.add(pct > 0 ? 'positive' : (pct < 0 ? 'negative' : 'flat'));
114
+ }
115
+ function loadPanelReturns() {
116
+ fetch('/api/sp500-30d').then(function(r){ return r.json(); }).then(function(d) {
117
+ if (d && d.status === 'ok') setPct('sp500-30d', parseFloat(d.return_pct) || 0);
118
+ }).catch(function(){});
119
+ fetch('/api/grid-returns').then(function(r){ return r.json(); }).then(function(d) {
120
+ if (d && d.status === 'ok') {
121
+ setPct('grid-30d', parseFloat(d.return_pct) || 0);
122
+ var wr = document.getElementById('grid-winrate');
123
+ if (wr) {
124
+ var rate = parseFloat(d.win_rate) || 0;
125
+ wr.textContent = rate.toFixed(1) + '% (' + (d.wins || 0) + '/' + (d.closed || 0) + ')';
126
+ wr.classList.remove('positive', 'negative', 'flat');
127
+ wr.classList.add(rate > 50 ? 'positive' : (rate < 50 ? 'negative' : 'flat'));
128
+ }
129
+ }
130
+ }).catch(function(){});
131
+ }
132
+ loadPanelReturns();
133
+ setInterval(loadPanelReturns, 3600000);
134
+ function loadFuturesReturns() {
135
+ fetch('/api/sp500-30d').then(function(r){ return r.json(); }).then(function(d) {
136
+ if (d && d.status === 'ok') setPct('fut-sp500', parseFloat(d.return_pct) || 0);
137
+ }).catch(function(){});
138
+ fetch('/api/bot-pnl').then(function(r){ return r.json(); }).then(function(d) {
139
+ if (d && d.status === 'ok') {
140
+ var margin = parseFloat(d.total_margin) || 0;
141
+ var pnl30 = parseFloat(d.pnl_30d);
142
+ if (margin > 0 && !isNaN(pnl30)) setPct('fut-30d', (pnl30 / margin) * 100);
143
+ }
144
+ }).catch(function(){});
145
+ fetch('/api/win-rate').then(function(r){ return r.json(); }).then(function(d) {
146
+ if (d && d.status === 'ok' && d.win_rate != null) {
147
+ var el = document.getElementById('fut-winrate');
148
+ if (el) {
149
+ var rate = parseFloat(d.win_rate) || 0;
150
+ el.textContent = rate.toFixed(1) + '% (' + (d.wins || 0) + '/' + (d.total_bots || 0) + ')';
151
+ el.classList.remove('positive', 'negative', 'flat');
152
+ el.classList.add(rate > 50 ? 'positive' : (rate < 50 ? 'negative' : 'flat'));
153
+ }
154
+ }
155
+ }).catch(function(){});
156
+ }
157
+ loadFuturesReturns();
158
+ setInterval(loadFuturesReturns, 3600000);
159
+
160
+ </script>
161
+ <script src="/css/nav.js"></script>
162
+ </body>
163
+ </html>
static/portfolio/index.html CHANGED
@@ -329,5 +329,18 @@
329
  setInterval(loadPortfolio, 30000);
330
  </script>
331
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  </body>
333
  </html>
 
329
  setInterval(loadPortfolio, 30000);
330
  </script>
331
  <script src="/css/nav.js"></script>
332
+ <!--Start of Tawk.to Script-->
333
+ <script type="text/javascript">
334
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
335
+ (function(){
336
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
337
+ s1.async=true;
338
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
339
+ s1.charset='UTF-8';
340
+ s1.setAttribute('crossorigin','*');
341
+ s0.parentNode.insertBefore(s1,s0);
342
+ })();
343
+ </script>
344
+ <!--End of Tawk.to Script-->
345
  </body>
346
  </html>
static/positions/index.html CHANGED
@@ -122,5 +122,18 @@
122
  load();
123
  </script>
124
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  </body>
126
  </html>
 
122
  load();
123
  </script>
124
  <script src="/css/nav.js"></script>
125
+ <!--Start of Tawk.to Script-->
126
+ <script type="text/javascript">
127
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
128
+ (function(){
129
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
130
+ s1.async=true;
131
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
132
+ s1.charset='UTF-8';
133
+ s1.setAttribute('crossorigin','*');
134
+ s0.parentNode.insertBefore(s1,s0);
135
+ })();
136
+ </script>
137
+ <!--End of Tawk.to Script-->
138
  </body>
139
  </html>
static/price/index.html CHANGED
@@ -57,6 +57,19 @@
57
  setInterval(load, 30000);
58
  </script>
59
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  </body>
61
  </html>
62
 
 
57
  setInterval(load, 30000);
58
  </script>
59
  <script src="/css/nav.js"></script>
60
+ <!--Start of Tawk.to Script-->
61
+ <script type="text/javascript">
62
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
63
+ (function(){
64
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
65
+ s1.async=true;
66
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
67
+ s1.charset='UTF-8';
68
+ s1.setAttribute('crossorigin','*');
69
+ s0.parentNode.insertBefore(s1,s0);
70
+ })();
71
+ </script>
72
+ <!--End of Tawk.to Script-->
73
  </body>
74
  </html>
75
 
static/scan-widget.css ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Self-contained coin-scan widget (Conservative / Risk-Taker). */
2
+
3
+ .scan-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
4
+ .scan-embed { margin-bottom: 32px; }
5
+
6
+ .scan-line { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-bottom: 16px; }
7
+ .scan-field { display: flex; flex-direction: column; gap: 6px; }
8
+ .scan-field label {
9
+ font-size: 11px; color: #f0b90b; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
10
+ }
11
+ .scan-field input, .scan-field select {
12
+ background: #0d1117; border: 2px solid #30363d; border-radius: 8px; color: #e6edf3;
13
+ font-size: 16px; padding: 12px 14px; font-family: inherit; box-sizing: border-box;
14
+ }
15
+ .scan-field input { width: 150px; font-family: 'SF Mono', Monaco, monospace; }
16
+ .scan-field select { width: 15ch; }
17
+ .scan-field input:focus, .scan-field select:focus { outline: none; border-color: #f0b90b; }
18
+
19
+ .scan-tabs { display: flex; gap: 6px; }
20
+ .scan-tab {
21
+ padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer;
22
+ background: #0d1117; border: 1px solid #30363d; color: #8b949e; font-family: inherit;
23
+ }
24
+ .scan-tab.active { background: #3a2a1a; border-color: #f0b90b; color: #f0b90b; }
25
+ .scan-tab.risk.active { background: #3a1a1a; border-color: #f87171; color: #f87171; }
26
+
27
+ .scan-progress {
28
+ display: flex; align-items: center; gap: 12px; padding: 16px;
29
+ background: #1e2329; border: 2px solid #f0b90b; border-radius: 12px; margin-bottom: 16px;
30
+ }
31
+ .scan-spinner {
32
+ width: 20px; height: 20px; border: 3px solid #30363d; border-top-color: #f0b90b;
33
+ border-radius: 50%; animation: swspin 0.8s linear infinite;
34
+ }
35
+ @keyframes swspin { to { transform: rotate(360deg); } }
36
+
37
+ #sw-results { margin-top: 16px; color: #8b949e; }
38
+ #sw-results table {
39
+ width: 100%; border-collapse: collapse; background: #1e2329;
40
+ border-radius: 12px; overflow: hidden; font-size: 13px;
41
+ }
42
+ #sw-results th {
43
+ text-align: right; padding: 10px; color: #8b949e; font-size: 11px;
44
+ text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; white-space: nowrap;
45
+ }
46
+ #sw-results th:first-child { text-align: left; }
47
+ #sw-results td {
48
+ padding: 10px; border-bottom: 1px solid #21262d; text-align: right;
49
+ font-family: 'SF Mono', Monaco, monospace; white-space: nowrap;
50
+ }
51
+ #sw-results td:first-child { text-align: left; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
52
+ #sw-results tr:last-child td { border-bottom: none; }
53
+ #sw-results tbody tr:hover { background: #161b22; }
54
+
55
+ .sw-hdr {
56
+ background: #1e2329; border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
57
+ border-left: 4px solid #f0b90b; font-weight: 600; color: #f0b90b; font-size: 15px;
58
+ }
59
+ .sw-hdr .sw-meta { font-family: 'SF Mono', Monaco, monospace; font-size: 13px; color: #8b949e; font-weight: 400; margin-top: 4px; }
60
+
61
+ .pill { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; white-space: nowrap; }
62
+ .pill-green { background: #1a3a1a; color: #4ade80; border: 1px solid #4ade80; }
63
+ .pill-orange { background: #3a2a1a; color: #f0b90b; border: 1px solid #f0b90b; }
64
+ .pill-red { background: #3a1a1a; color: #f87171; border: 1px solid #f87171; }
65
+ .signal-yes { color: #4ade80; font-weight: 700; }
66
+ .signal-no { color: #f87171; font-weight: 700; }
67
+ .blocker-list { font-size: 11px; color: #f87171; margin-top: 4px; line-height: 1.5; }
static/scan-widget.js ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Self-contained coin-scan widget (Conservative / Risk-Taker).
2
+ // Renders into the #sw-* elements provided by the host page.
3
+ (function () {
4
+ 'use strict';
5
+
6
+ var MODE = 'conservative';
7
+ var ATR = 2;
8
+
9
+ function num(v) { return parseFloat(v) || 0; }
10
+
11
+ function zPill(z) {
12
+ if (z < -1) return '<span class="pill pill-green">' + z.toFixed(2) + '</span>';
13
+ if (z > 1) return '<span class="pill pill-red">' + z.toFixed(2) + '</span>';
14
+ return '<span class="pill pill-orange">' + z.toFixed(2) + '</span>';
15
+ }
16
+ function momPill(m) {
17
+ if (m > 10) return '<span class="pill pill-green">' + m.toFixed(2) + '%</span>';
18
+ if (m < -5) return '<span class="pill pill-red">' + m.toFixed(2) + '%</span>';
19
+ return '<span class="pill pill-orange">' + m.toFixed(2) + '%</span>';
20
+ }
21
+ function volPill(v) {
22
+ if (v < 3) return '<span class="pill pill-green">' + v.toFixed(2) + '%</span>';
23
+ if (v > 8) return '<span class="pill pill-red">' + v.toFixed(2) + '%</span>';
24
+ return '<span class="pill pill-orange">' + v.toFixed(2) + '%</span>';
25
+ }
26
+ function rsiPill(r) {
27
+ if (r < 30) return '<span class="pill pill-green">' + r.toFixed(2) + '</span>';
28
+ if (r > 70) return '<span class="pill pill-red">' + r.toFixed(2) + '</span>';
29
+ return '<span class="pill pill-orange">' + r.toFixed(2) + '</span>';
30
+ }
31
+ function compPill(s) {
32
+ if (s > 10) return '<span class="pill pill-green">' + s.toFixed(2) + '</span>';
33
+ if (s < 0) return '<span class="pill pill-red">' + s.toFixed(2) + '</span>';
34
+ return '<span class="pill pill-orange">' + s.toFixed(2) + '</span>';
35
+ }
36
+ function signalCell(c) {
37
+ if (c.buy_signal) return '<span class="signal-yes">✅ BUY</span>';
38
+ var blockers = [];
39
+ if (!(num(c.zscore) < -1)) blockers.push('Z≥-1');
40
+ if (!(num(c.momentum) > 5)) blockers.push('Mom≤5');
41
+ if (!(num(c.volatility) < 8)) blockers.push('Vol≥8');
42
+ if (!(num(c.rsi) < 70)) blockers.push('RSI≥70');
43
+ return '<span class="signal-no">❌</span><div class="blocker-list">' + blockers.join(', ') + '</div>';
44
+ }
45
+
46
+ function setMode(mode) {
47
+ MODE = mode;
48
+ document.querySelectorAll('#sw-tabs .scan-tab').forEach(function (t) {
49
+ t.classList.toggle('active', t.getAttribute('data-mode') === mode);
50
+ });
51
+ var btn = document.getElementById('sw-run');
52
+ if (btn) btn.textContent = mode === 'risk' ? '🎲 Run Risk Scan' : '🛡️ Run Conservative Scan';
53
+ }
54
+
55
+ function renderResults(coins, count, elapsed) {
56
+ var out = document.getElementById('sw-results');
57
+ if (!coins || !coins.length) { out.innerHTML = 'No results found.'; return; }
58
+
59
+ var h = '<div class="sw-hdr">📊 Scan Results — Coin Scan and Analysis'
60
+ + '<div class="sw-meta">' + count + ' of 100 coins scanned in ' + elapsed + ' seconds</div></div>';
61
+ h += '<table><thead><tr>';
62
+ h += '<th>Coin</th>';
63
+ h += '<th>Price</th>';
64
+ h += '<th>TP (' + ATR + '×)</th>';
65
+ h += '<th>SL (' + ATR + '×)</th>';
66
+ h += '<th>Z-Score</th><th>Momentum</th><th>Volatility</th><th>RSI</th><th>Score</th><th>Signal</th>';
67
+ h += '</tr></thead><tbody>';
68
+
69
+ coins.forEach(function (c) {
70
+ var tpField = ATR === 3 ? 'tp_3x' : 'tp_2x';
71
+ var slField = ATR === 3 ? 'sl_3x' : 'sl_2x';
72
+ var price = num(c.price);
73
+ var atr = num(c.atr);
74
+ var tp = (c[tpField] !== undefined && c[tpField] !== null) ? num(c[tpField]) : price + ATR * atr;
75
+ var sl = (c[slField] !== undefined && c[slField] !== null) ? num(c[slField]) : price - ATR * atr;
76
+
77
+ h += '<tr>'
78
+ + '<td><strong>' + c.symbol + '</strong></td>'
79
+ + '<td>$' + price.toFixed(6) + '</td>'
80
+ + '<td style="color:#4ade80;">$' + tp.toFixed(6) + '</td>'
81
+ + '<td style="color:#f87171;">$' + sl.toFixed(6) + '</td>'
82
+ + '<td>' + zPill(num(c.zscore)) + '</td>'
83
+ + '<td>' + momPill(num(c.momentum)) + '</td>'
84
+ + '<td>' + volPill(num(c.volatility)) + '</td>'
85
+ + '<td>' + rsiPill(num(c.rsi)) + '</td>'
86
+ + '<td>' + compPill(num(c.composite_score)) + '</td>'
87
+ + '<td>' + signalCell(c) + '</td>'
88
+ + '</tr>';
89
+ });
90
+
91
+ h += '</tbody></table>';
92
+ out.innerHTML = h;
93
+ }
94
+
95
+ function run() {
96
+ var btn = document.getElementById('sw-run');
97
+ var prog = document.getElementById('sw-progress');
98
+ var statusEl = document.getElementById('sw-status');
99
+ var timerEl = document.getElementById('sw-timer');
100
+ var out = document.getElementById('sw-results');
101
+ if (!btn || !prog) return;
102
+
103
+ var start = Date.now();
104
+ btn.disabled = true;
105
+ btn.textContent = '⏳ Scanning...';
106
+ prog.style.display = 'flex';
107
+ out.innerHTML = '';
108
+ statusEl.textContent = 'Scanning coins in the spot market...';
109
+ timerEl.textContent = '00:00';
110
+
111
+ var timer = setInterval(function () {
112
+ var s = Math.floor((Date.now() - start) / 1000);
113
+ var m = String(Math.floor(s / 60)).padStart(2, '0');
114
+ var ss = String(s % 60).padStart(2, '0');
115
+ timerEl.textContent = m + ':' + ss;
116
+ if (s < 15) statusEl.textContent = 'Fetching coin list from registry...';
117
+ else if (s < 30) statusEl.textContent = 'Fetching 20-day price history...';
118
+ else statusEl.textContent = 'Calculating Z-scores, momentum, and RSI...';
119
+ }, 500);
120
+
121
+ fetch('/api/scan?mode=' + MODE)
122
+ .then(function (r) {
123
+ if (r.status === 429) {
124
+ return r.json().then(function (err) { throw new Error(err.message || 'Please wait before scanning again.'); });
125
+ }
126
+ return r.json();
127
+ })
128
+ .then(function (d) {
129
+ var coins = d.results || [];
130
+ if (typeof d.results === 'object' && !Array.isArray(d.results)) coins = d.results.results || [];
131
+ var count = d.total_scanned || coins.length;
132
+ var elapsed = Math.floor((Date.now() - start) / 1000);
133
+ clearInterval(timer);
134
+ prog.style.display = 'none';
135
+ renderResults(coins, count, elapsed);
136
+ })
137
+ .catch(function (e) {
138
+ clearInterval(timer);
139
+ prog.style.display = 'none';
140
+ out.innerHTML = 'Error: ' + e.message;
141
+ })
142
+ .finally(function () {
143
+ btn.disabled = false;
144
+ setMode(MODE);
145
+ });
146
+ }
147
+
148
+ function init() {
149
+ setMode('conservative');
150
+ var btn = document.getElementById('sw-run');
151
+ if (btn) btn.addEventListener('click', run);
152
+ document.querySelectorAll('#sw-tabs .scan-tab').forEach(function (t) {
153
+ t.addEventListener('click', function () { setMode(t.getAttribute('data-mode')); });
154
+ });
155
+ var atrSel = document.getElementById('sw-atr');
156
+ if (atrSel) atrSel.addEventListener('change', function () { ATR = parseInt(this.value, 10) || 2; });
157
+ var inv = document.getElementById('sw-investment');
158
+ if (inv && !inv.value) inv.value = '$10,000';
159
+ }
160
+
161
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
162
+ else init();
163
+ })();
static/scan/index.html CHANGED
@@ -1,1492 +1,198 @@
1
  <!doctype html>
2
  <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Scan — Blind Monkeys</title>
7
  <link rel="stylesheet" href="/css/nav.css">
8
- <link rel="stylesheet" href="/static/help.css">
9
  <style>
10
- .order-panel { background: #1e2329; border: 2px solid #f0b90b; border-radius: 12px; padding: 20px; margin-top: 20px; display: none; }
11
- .order-panel.visible { display: block; }
12
- .order-panel h3 { color: #f0b90b; margin-bottom: 16px; }
13
- .slider-container { margin-bottom: 20px; }
14
- .slider-label { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
15
- .slider-label strong { color: #f0b90b; }
16
- input[type=range] { width: 100%; height: 8px; background: #0d1117; border-radius: 4px; outline: none; -webkit-appearance: none; cursor: pointer; }
17
- input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; background: #f0b90b; border-radius: 50%; cursor: pointer; border: 3px solid #0d1117; box-shadow: 0 0 0 2px #f0b90b; }
18
- .slider-marks { display: flex; justify-content: space-between; padding: 0 10px; margin-top: 8px; font-size: 12px; color: #8b949e; }
19
- .slider-marks span.active { color: #f0b90b; font-weight: 700; }
20
- .input-group { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
21
- .input-field { flex: 1; min-width: 150px; }
22
- .input-field label { display: block; font-size: 13px; color: #8b949e; margin-bottom: 6px; }
23
- .input-field input { width: 100%; padding: 10px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; color: #e6edf3; font-size: 16px; font-family: inherit; }
24
- .input-field input:focus { outline: none; border-color: #f0b90b; }
25
- .summary { background: #0d1117; padding: 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
26
- .summary-row { display: flex; justify-content: space-between; padding: 4px 0; }
27
- .buy-btn { width: 100%; padding: 16px; background: #f0b90b; color: #0d1117; border: none; border-radius: 8px; font-size: 16px; font-weight: 700; cursor: pointer; font-family: inherit; }
28
- .buy-btn:hover:not(:disabled) { opacity: 0.9; }
29
- .buy-btn:disabled { opacity: 0.5; cursor: not-allowed; }
30
- input[type=checkbox] { width: 20px; height: 20px; cursor: pointer; accent-color: #f0b90b; }
31
- .selected-row { background: #1a2332 !important; }
32
- .warning { background: #3a2a1a; border: 1px solid #f0b90b; color: #f0b90b; padding: 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
33
- .max-badge { display: inline-block; padding: 4px 10px; background: #30363d; border-radius: 4px; font-size: 11px; color: #8b949e; margin-left: 10px; }
34
- .atr-toggle { display: flex; align-items: center; cursor: pointer; gap: 8px; padding: 12px; background: #0d1117; border-radius: 8px; margin-bottom: 16px; }
35
- .atr-toggle input { width: 18px; height: 18px; }
36
- .atr-toggle span { font-size: 14px; font-weight: 500; }
37
- .atr-detail { font-size: 12px; color: #8b949e; margin-left: 26px; margin-top: 4px; }
38
- .scan-spinner {
39
- width: 20px;
40
- height: 20px;
41
- border: 3px solid #30363d;
42
- border-top-color: #f0b90b;
43
- border-radius: 50%;
44
- animation: spin 0.8s linear infinite;
45
- }
46
- @keyframes spin {
47
- to { transform: rotate(360deg); }
48
- }
49
- /* Colored pills */
50
- .pill {
51
- display: inline-block;
52
- padding: 3px 10px;
53
- border-radius: 12px;
54
- font-size: 12px;
55
- font-weight: 700;
56
- white-space: nowrap;
57
- }
58
- .pill-green { background: #1a3a1a; color: #4ade80; border: 1px solid #4ade80; }
59
- .pill-orange { background: #3a2a1a; color: #f0b90b; border: 1px solid #f0b90b; }
60
- .pill-red { background: #3a1a1a; color: #f87171; border: 1px solid #f87171; }
61
- .signal-yes { color: #4ade80; font-weight: 700; font-size: 14px; }
62
- .signal-no { color: #f87171; font-weight: 700; font-size: 14px; }
63
- .blocker-list {
64
- font-size: 11px;
65
- color: #f87171;
66
- margin-top: 4px;
67
- line-height: 1.5;
68
- }
69
- /* ---------- Market Regime Panel (Phase 2) ---------- */
70
- .regime-panel {
71
- display: grid;
72
- grid-template-columns: 2fr 1fr 1fr;
73
- gap: 16px;
74
- margin-bottom: 20px;
75
- }
76
- @media (max-width: 900px) {
77
- .regime-panel { grid-template-columns: 1fr; }
78
- }
79
- .regime-card {
80
- background: #1e2329;
81
- border: 2px solid #30363d;
82
- border-radius: 12px;
83
- padding: 16px 18px;
84
- display: flex;
85
- flex-direction: column;
86
- min-height: 130px;
87
- }
88
- @keyframes flashUp { 0%{background-color:rgba(74,222,128,0.45);} 100%{background-color:transparent;} }
89
- @keyframes flashDown { 0%{background-color:rgba(248,113,113,0.45);} 100%{background-color:transparent;} }
90
- .flash-up { animation: flashUp 0.9s ease-out; }
91
- .flash-down { animation: flashDown 0.9s ease-out; }
92
- @keyframes ringFlash {
93
- 0% { filter: brightness(1.9); }
94
- 40% { filter: brightness(1.9); }
95
- 41% { filter: brightness(0.55); }
96
- 100% { filter: brightness(0.55); }
97
- }
98
- .ring-flash {
99
- animation: ringFlash 5s infinite;
100
- }
101
- #ring-outer, #ring-middle, #ring-inner {
102
- transition: filter 0.2s ease;
103
- }
104
- .pnl-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #21262d; }
105
- .pnl-row-last { border-bottom: none; }
106
- .pnl-label { color: #8b949e; }
107
- .pnl-value { font-family: 'SF Mono', Monaco, monospace; color: #e6edf3; }
108
- .pnl-value.positive { color: #4ade80; }
109
- .pnl-value.negative { color: #f87171; }
110
- .pnl-value.flat { color: #8b949e; }
111
- .market-card {
112
- background: #1e2329;
113
- border: 2px solid #30363d;
114
- border-radius: 12px;
115
- padding: 16px 18px;
116
- margin-bottom: 20px;
117
- }
118
- .market-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
119
- .market-row { display: grid; grid-template-columns: 50px 1fr 60px 60px 60px 50px 60px 70px 110px 14px; gap: 8px; align-items: center; }
120
- .market-ts { font-size: 11px; color: #8b949e; margin-top: 10px; }
121
- .market-hdr {
122
- display: grid;
123
- grid-template-columns: 50px 1fr 60px 60px 60px 50px 60px 70px 110px 14px;
124
- gap: 8px; font-size: 12px; color: #f0b90b;
125
- letter-spacing: 0.5px; margin-bottom: 8px; text-transform: uppercase;
126
- font-weight: 700; align-items: center;
127
- }
128
- .market-hdr .hdr-coin { min-width: 50px; }
129
- .market-hdr .hdr-price { flex: 1; text-align: right; }
130
- .market-hdr .hdr-chg { min-width: 100px; text-align: right; }
131
- .market-hdr .hdr-sp { width: 14px; }
132
- .market-add-row { display: flex; gap: 6px; margin-top: 10px; }
133
- .market-add-row input {
134
- flex: 1; padding: 8px 10px; background: #0d1117;
135
- border: 1px solid #30363d; border-radius: 6px;
136
- color: #e6edf3; font-size: 13px; text-transform: uppercase;
137
- }
138
- .market-add-row button {
139
- padding: 8px 14px; background: #0d1117; color: #f0b90b;
140
- border: 1px solid #f0b90b; border-radius: 6px;
141
- font-size: 13px; font-weight: 600; cursor: pointer;
142
- }
143
- .regime-card-title {
144
- font-size: 11px;
145
- font-weight: 700;
146
- letter-spacing: 1px;
147
- text-transform: uppercase;
148
- color: #f0b90b;
149
- margin-bottom: 8px;
150
- }
151
- .regime-card-value {
152
- font-size: 28px;
153
- font-weight: 700;
154
- font-family: 'SF Mono', Monaco, monospace;
155
- color: #e6edf3;
156
- line-height: 1.1;
157
- }
158
- .regime-card-sub {
159
- font-size: 12px;
160
- color: #8b949e;
161
- margin-top: 4px;
162
- }
163
- .regime-card.regime-loading .regime-card-value { color: #8b949e; }
164
- .regime-gauge {
165
- width: 100%;
166
- max-width: 170px;
167
- height: auto;
168
- display: block;
169
- margin: 4px auto 2px;
170
- }
171
- #regime-fng-needle, #regime-vix-needle {
172
- transition: transform 0.7s cubic-bezier(0.22, 1, 0.55, 1);
173
- }
174
- .regime-fng-greed { color: #4ade80 !important; }
175
- .regime-fng-neutral { color: #f0b90b !important; }
176
- .regime-fng-fear { color: #f87171 !important; }
177
- .regime-sparkline {
178
- margin-top: auto;
179
- width: 100%;
180
- height: 44px;
181
- display: block;
182
- }
183
-
184
- /* ---------- Phase 3: Investment input + ATR multiplier ---------- */
185
- .investment-bar {
186
- display: flex;
187
- gap: 16px;
188
- margin: 16px 0 20px;
189
- flex-wrap: wrap;
190
- }
191
- .investment-field {
192
- flex: 1;
193
- min-width: 200px;
194
- }
195
- .investment-bar > .investment-field:first-child label {
196
- color: #f0b90b;
197
- }
198
- #investment-input {
199
- min-width: 160px;
200
- }
201
- .investment-field label {
202
- display: block;
203
- font-size: 12px;
204
- color: #8b949e;
205
- margin-bottom: 6px;
206
- font-weight: 600;
207
- letter-spacing: 0.5px;
208
- text-transform: uppercase;
209
- }
210
- .investment-field input,
211
- .investment-field select {
212
- width: 100%;
213
- padding: 12px 14px;
214
- background: #0d1117;
215
- border: 2px solid #30363d;
216
- border-radius: 8px;
217
- color: #e6edf3;
218
- font-size: 16px;
219
- font-family: 'SF Mono', Monaco, monospace;
220
- box-sizing: border-box;
221
- }
222
- .investment-field input:focus,
223
- .investment-field select:focus {
224
- outline: none;
225
- border-color: #f0b90b;
226
- }
227
-
228
- .scan-tabs {
229
- display: flex;
230
- gap: 8px;
231
- margin: 16px 0 4px;
232
- flex-wrap: wrap;
233
- }
234
- .scan-tab {
235
- padding: 10px 20px;
236
- border-radius: 10px;
237
- font-size: 14px;
238
- font-weight: 700;
239
- cursor: pointer;
240
- background: #1e2329;
241
- border: 2px solid #30363d;
242
- color: #8b949e;
243
- font-family: inherit;
244
- }
245
- .scan-tab:hover { border-color: #f0b90b; }
246
- .scan-tab.active {
247
- background: #3a2a1a;
248
- border-color: #f0b90b;
249
- color: #f0b90b;
250
- }
251
- .scan-tab.risk.active {
252
- background: #3a1a1a;
253
- border-color: #f87171;
254
- color: #f87171;
255
- }
256
- .scan-tab-desc { font-size: 12px; color: #8b949e; margin-bottom: 12px; }
257
- #market-ts { display: none !important; }
258
- .market-data-wrap { align-items: flex-start; }
259
- .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
260
- .breadcrumbs a { color: #8b949e; text-decoration: none; }
261
- .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
262
- .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
263
- .breadcrumbs .bc-current { color: #e6edf3; }
264
- @media (max-width: 640px) { .breadcrumbs { display: none; } }
265
  </style>
266
- <script defer src="https://edgemetry.dean-2b4.workers.dev/em.js" data-domain="blind-monkeys.com"></script>
267
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
268
-
269
- <style id="modeTooltipCSS">
270
- .scan-tab-wrap { display: inline-flex; align-items: center; gap: 4px; }
271
- .mode-info {
272
- display: inline-flex;
273
- align-items: center;
274
- justify-content: center;
275
- width: 22px;
276
- height: 22px;
277
- border-radius: 50%;
278
- cursor: help;
279
- position: relative;
280
- opacity: 0.7;
281
- transition: opacity 0.15s, transform 0.15s;
282
- }
283
- .mode-info:hover { opacity: 1; transform: scale(1.1); }
284
- .mode-info img { width: 18px; height: 18px; display: block; }
285
- .mode-info .mode-tip {
286
- position: absolute;
287
- bottom: calc(100% + 10px);
288
- left: 50%;
289
- transform: translateX(-50%);
290
- background: #1e2329;
291
- border: 1px solid #f0b90b;
292
- border-radius: 8px;
293
- padding: 10px 14px;
294
- font-size: 12px;
295
- line-height: 1.5;
296
- color: #e6edf3;
297
- width: 280px;
298
- text-align: left;
299
- box-shadow: 0 6px 18px rgba(0,0,0,0.5);
300
- opacity: 0;
301
- pointer-events: none;
302
- transition: opacity 0.15s;
303
- z-index: 1000;
304
- font-weight: 400;
305
- }
306
- .mode-info .mode-tip::after {
307
- content: '';
308
- position: absolute;
309
- top: 100%;
310
- left: 50%;
311
- transform: translateX(-50%);
312
- border: 6px solid transparent;
313
- border-top-color: #f0b90b;
314
- }
315
- .mode-info:hover .mode-tip { opacity: 1; }
316
- </style>
317
  </head>
318
  <body>
319
  <nav class="nav-bar">
320
  <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
321
  <div class="nav-links">
322
- <a href="/scan/" class="nav-link active">🔍 Scan</a>
323
- <a href="/price/" class="nav-link">💵 ETH Price</a>
324
- <a href="/settings/" class="nav-link">⚙️ Settings</a>
325
  </div>
326
  </nav>
327
 
328
  <div class="page-content">
329
- <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Scan</span></div>
330
- <!-- Market Regime Panel (Phase 2) -->
331
- <div class="regime-panel" id="regime-panel">
332
- <div class="regime-card regime-loading" id="regime-treasury">
333
- <div class="regime-card-title" data-help="treasury">10Y Treasury Yield</div>
334
- <div class="regime-card-value" id="regime-treasury-value">—</div>
335
- <div class="regime-card-sub" id="regime-treasury-sub">Loading FRED DGS10…</div>
336
- <svg class="regime-sparkline" id="regime-treasury-spark" viewBox="0 0 400 44" preserveAspectRatio="none"></svg>
337
- </div>
338
- <div class="regime-card regime-loading" id="regime-fng">
339
- <div class="regime-card-title" data-help="feargreed">Fear &amp; Greed</div>
340
- <svg class="regime-gauge" viewBox="0 0 200 118">
341
- <defs>
342
- <linearGradient id="gauge-grad-fng" x1="0" y1="0" x2="1" y2="0">
343
- <stop offset="0%" stop-color="#4ade80"/>
344
- <stop offset="50%" stop-color="#f0b90b"/>
345
- <stop offset="100%" stop-color="#f87171"/>
346
- </linearGradient>
347
- </defs>
348
- <path d="M 20 100 A 80 80 0 0 1 180 100" stroke="#30363d" stroke-width="14" fill="none" stroke-linecap="round"/>
349
- <path d="M 20 100 A 80 80 0 0 1 180 100" stroke="url(#gauge-grad-fng)" stroke-width="14" fill="none" stroke-linecap="round" opacity="0.4"/>
350
- <line id="regime-fng-needle" x1="100" y1="100" x2="100" y2="30" stroke="#e6edf3" stroke-width="3" stroke-linecap="round"/>
351
- <circle cx="100" cy="100" r="6" fill="#e6edf3"/>
352
- <text x="20" y="114" fill="#8b949e" font-size="10" text-anchor="middle">0</text>
353
- <text x="100" y="114" fill="#8b949e" font-size="10" text-anchor="middle">50</text>
354
- <text x="180" y="114" fill="#8b949e" font-size="10" text-anchor="middle">100</text>
355
- </svg>
356
- <div class="regime-card-value" id="regime-fng-value">—</div>
357
- <div class="regime-card-sub" id="regime-fng-sub">Loading alternative.me…</div>
358
- </div>
359
- <div class="regime-card regime-loading" id="regime-vix">
360
- <div class="regime-card-title" data-help="vix">VIX</div>
361
- <svg class="regime-gauge" viewBox="0 0 200 118">
362
- <defs>
363
- <linearGradient id="gauge-grad-vix" x1="0" y1="0" x2="1" y2="0">
364
- <stop offset="0%" stop-color="#4ade80"/>
365
- <stop offset="50%" stop-color="#f0b90b"/>
366
- <stop offset="100%" stop-color="#f87171"/>
367
- </linearGradient>
368
- </defs>
369
- <path d="M 20 100 A 80 80 0 0 1 180 100" stroke="#30363d" stroke-width="14" fill="none" stroke-linecap="round"/>
370
- <path d="M 20 100 A 80 80 0 0 1 180 100" stroke="url(#gauge-grad-vix)" stroke-width="14" fill="none" stroke-linecap="round" opacity="0.4"/>
371
- <line id="regime-vix-needle" x1="100" y1="100" x2="100" y2="30" stroke="#e6edf3" stroke-width="3" stroke-linecap="round"/>
372
- <circle cx="100" cy="100" r="6" fill="#e6edf3"/>
373
- <text x="20" y="114" fill="#8b949e" font-size="10" text-anchor="middle">0</text>
374
- <text x="100" y="114" fill="#8b949e" font-size="10" text-anchor="middle">50</text>
375
- <text x="180" y="114" fill="#8b949e" font-size="10" text-anchor="middle">100</text>
376
- </svg>
377
- <div class="regime-card-value" id="regime-vix-value">—</div>
378
- <div class="regime-card-sub" id="regime-vix-sub">Loading FRED VIXCLS…</div>
379
- </div>
380
- </div>
381
-
382
- <!-- Live Market Data (shared module) -->
383
- <div class="market-data-wrap" style="display:flex;gap:20px;flex-wrap:wrap;margin-bottom:20px;">
384
- <div class="market-card" style="flex:1 1 auto;min-width:600px;margin-bottom:0;">
385
- <div class="regime-card-title">Market Data</div>
386
- <div class="market-hdr">
387
- <span>Coin</span>
388
- <span style="text-align:right;">Price</span>
389
- <span style="text-align:right;">24h</span>
390
- <span style="text-align:right;">1w</span>
391
- <span style="text-align:right;">1m</span>
392
- <span style="text-align:right;" data-help="rsi">RSI</span>
393
- <span style="text-align:right;" data-help="zscore">Z-Score</span>
394
- <span style="text-align:right;" data-help="basis">Basis %</span>
395
- <span style="text-align:right;" data-help="signal">Signal</span>
396
- <span></span>
397
- </div>
398
- <div class="market-list" id="market-list"></div>
399
- <div class="market-add-row">
400
- <input id="market-add-input" type="text" placeholder="Add symbol (e.g. DOGE)" maxlength="10">
401
- <button id="market-add-btn">Add</button>
402
- </div>
403
- <div class="market-ts" id="market-ts">Loading…</div>
404
  </div>
405
 
406
- <div class="pnl-card" style="flex:0 0 320px;max-width:100%;background:#1e2329;border:2px solid #30363d;border-radius:12px;padding:16px 18px;">
407
- <div class="regime-card-title">Blind Monkey's Profit and Loss</div>
 
 
 
 
408
 
409
- <!-- Dartboard -->
410
- <div style="display:flex;justify-content:center;margin:16px 0 12px 0;">
411
- <!-- dartboard-hero-swap --><svg id="dartboard" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 98" width="200" height="200" <!-- dartboard-tunnel-applied --><!-- dartboard-tunnel-fix-applied -->aria-label="Win rate indicator"><style id="dartboard-tunnel-css">#dartboard #ring-outer,#dartboard #ring-middle,#dartboard #ring-inner,#dartboard > ellipse:nth-of-type(2),#dartboard > ellipse:nth-of-type(4) { transform-box: fill-box; transform-origin: center; animation: db-tunnel 3s linear infinite;}#dartboard #ring-outer { animation-delay: 0s; }#dartboard > ellipse:nth-of-type(2) { animation-delay: 0.3s; }#dartboard #ring-middle { animation-delay: 0.6s; }#dartboard > ellipse:nth-of-type(4) { animation-delay: 0.9s; }#dartboard #ring-inner { animation-delay: 1.2s; }@keyframes db-tunnel { 0% { transform: scale(1.00); opacity: 1; } 70% { transform: scale(0.40); opacity: 0.15; } 100% { transform: scale(0.10); opacity: 0; }}</style><defs><linearGradient id="a" x1="-99.04" y1="372.9" x2="-162.46" y2="372.9" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#e66969"/><stop offset="0.75" stop-color="#ffbaba"/><stop offset="1" stop-color="#fc7373"/></linearGradient><linearGradient id="b" x1="-99.04" y1="369.84" x2="-162.46" y2="369.84" gradientTransform="translate(395.07 -112.17) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.36" stop-color="#f87a7a"/><stop offset="0.77" stop-color="#ffc9c9"/><stop offset="1" stop-color="#ff8080"/></linearGradient><clipPath id="c"><path d="M76.8,44.28l-23-.05-.47.47L78.1,59.44A28.75,28.75,0,0,0,76.8,44.28Z" style="fill:none"/></clipPath><radialGradient id="d" cx="52.2" cy="50.58" r="23.4" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2f3235"/><stop offset="1" stop-color="#2f3235" stop-opacity="0"/></radialGradient><linearGradient id="e" x1="10.11" y1="222.23" x2="18.02" y2="222.23" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#40bf6e"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="f" x1="14.48" y1="225.2" x2="28.04" y2="217.81" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#39ab62"/><stop offset="1" stop-color="#4ade80"/></linearGradient><linearGradient id="g" x1="19.62" y1="238.21" x2="16.43" y2="238.21" gradientTransform="matrix(0, 1, -1, 0, 300.68, 17.51)" gradientUnits="userSpaceOnUse"><stop offset="0.21" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.89" stop-color="#4ade80"/></linearGradient><linearGradient id="h" x1="18.61" y1="223.72" x2="17.44" y2="223.72" gradientTransform="translate(218.16 -145.65) rotate(45)" gradientUnits="userSpaceOnUse"><stop offset="0.03" stop-color="#3eb86a"/><stop offset="0.63" stop-color="#67e694"/><stop offset="0.95" stop-color="#4ade80"/></linearGradient></defs><path d="M27.48,25.68l-3.81,3.81C13.76,39.39,15.6,57.63,28,70s30.62,14.23,40.52,4.32l3.81-3.81Z" style="fill:url(#a)"/><path d="M28.1,25.05l-.9.9c-9.91,9.91-7.9,28,4.49,40.36s30.45,14.4,40.36,4.49l.9-.9Z" style="fill:url(#b)"/><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse id=""ring-outer" cx="49.9" cy="48.1" rx="25.36" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-19.4 49.37) rotate(-45)"><ellipse cx="49.9" cy="48.1" rx="25.37" ry="31.71" style="fill:#f87171"/></g><g transform="translate(-18.23 49.85) rotate(-45)"><ellipse cx="51.06" cy="46.94" rx="20.45" ry="25.56" style="fill:#fff"/></g><g transform="translate(-17.4 50.2) rotate(-45)"><ellipse id=""ring-middle" cx="51.89" cy="46.11" rx="15.82" ry="19.78" style="fill:#f0b90b"/></g><g transform="translate(-16.66 50.51) rotate(-45)"><ellipse cx="52.64" cy="45.36" rx="10.97" ry="13.72" style="fill:#fff"/></g><g transform="translate(-15.99 50.78) rotate(-45)"><ellipse id=""ring-inner" cx="53.3" cy="44.7" rx="6.59" ry="8.23" style="fill:#4ade80"/></g><g style="clip-path:url(#c)"><circle cx="52.2" cy="50.58" r="23.4" style="opacity:0.5;fill:url(#d)"/></g><path d="M79,19l-3.66-6.6s-3.13.5-5.79,6.76a30.15,30.15,0,0,0-2.46,11.75Z" style="fill:url(#e)"/><path d="M79,19l6.6,3.66s-.5,3.13-6.76,5.79a30.15,30.15,0,0,1-11.75,2.46Z" style="fill:url(#f)"/><g transform="translate(-6.83 54.58) rotate(-45)"><ellipse cx="62.47" cy="35.53" rx="12.96" ry="1.59" style="fill:url(#g)"/></g><path d="M79.17,19.67c-6.69,6.68-12.3,11.92-12.53,11.69s5-5.84,11.69-12.53A3.72,3.72,0,0,1,79.17,19.67Z" style="fill:url(#h)"/><path d="M79.81,18.89,81,17.41a11.52,11.52,0,0,0,1-1.46,11.52,11.52,0,0,0-1.46,1l-1.48,1.23s-1.19-1.91-1.61-2.55c-.53-.8-2.17-3.23-2.17-3.23s1.1,2.66,1.51,3.52,1.52,2.93,1.52,2.93-1,1-1.41,1.47a18.45,18.45,0,0,0-1.54,2.26,18.45,18.45,0,0,0,2.26-1.54c.51-.45,1.47-1.41,1.47-1.41s2,1.11,2.71,1.44c.91.42,3.74,1.59,3.74,1.59S83.14,21,82.3,20.42C81.69,20,79.81,18.89,79.81,18.89Z" style="fill:#67e892"/></svg>
 
 
 
 
 
 
412
  </div>
413
-
414
- <!-- Win rate label -->
415
- <div style="text-align:center;font-size:11px;color:#8b949e;margin-bottom:14px;">
416
- Win Rate: <span id="win-rate-value" style="color:#e6edf3;font-weight:600;">—</span>
 
 
 
 
 
417
  </div>
418
-
419
- <!-- P/L rows -->
420
- <div style="font-size:13px;">
421
- <div class="pnl-row">
422
- <span class="pnl-label">Current Bot</span>
423
- <span class="pnl-value" id="pnl-current">—</span>
424
- </div>
425
- <div class="pnl-row">
426
- <span class="pnl-label">24 Hour P&amp;L</span>
427
- <span class="pnl-value" id="pnl-24h">—</span>
428
- </div>
429
- <div class="pnl-row">
430
- <span class="pnl-label">Last 7 Days P&amp;L</span>
431
- <span class="pnl-value" id="pnl-7d">—</span>
432
- </div>
433
- <div class="pnl-row">
434
- <span class="pnl-label">Last 30 Days P&amp;L</span>
435
- <span class="pnl-value" id="pnl-30d">—</span>
436
- </div>
437
- <div class="pnl-row pnl-row-last">
438
- <span class="pnl-label">YTD P&amp;L</span>
439
- <span class="pnl-value" id="pnl-ytd">—</span>
440
- </div>
441
- <div style="margin-top:14px;font-size:11px;color:#484f58;text-align:center;" id="pnl-updated">
442
- Awaiting Bybit API connection
443
- </div>
444
- <div style="margin-top:8px;text-align:center;">
445
- <a href="/dart-performance" style="color:#f0b90b;font-size:12px;font-weight:600;text-decoration:none;">Dart Performance Detail →</a>
446
- </div>
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
- </div>
456
- </div>
457
-
458
- </div>
459
-
460
- <!-- Market Regime Banner -->
461
- <div id="regime-banner" style="display: none; border-radius: 12px; padding: 16px 20px; margin-bottom: 20px; border: 2px solid #30363d; background: #1e2329;">
462
- <div style="display: flex; align-items: center; gap: 12px;">
463
- <div id="regime-icon" style="font-size: 32px;">⏳</div>
464
- <div style="flex: 1;">
465
- <div id="regime-status" style="font-size: 16px; font-weight: 700; color: #e6edf3; margin-bottom: 4px;">Checking market...</div>
466
- <div id="regime-message" style="font-size: 13px; color: #8b949e;"></div>
467
- <div id="regime-stats" style="font-size: 12px; color: #8b949e; margin-top: 6px;"></div>
468
  </div>
469
- </div>
470
  </div>
 
471
 
472
- <h1 class="page-title">🔍 Scan Parameters</h1>
473
-
474
- <div style="display:flex;flex-wrap:wrap;gap:16px;align-items:flex-end;margin-bottom:20px;">
475
- <div style="display:flex;flex-direction:column;gap:6px;">
476
- <label style="font-size:11px;color:#f0b90b;font-weight:700;letter-spacing:0.5px;text-transform:uppercase;" data-help="invest">&#128176; Planned Invest</label>
477
- <input type="text" id="investment-input" placeholder="$10,000" autocomplete="off" inputmode="numeric" style="width:140px;padding:12px 14px;background:#0d1117;border:2px solid #30363d;border-radius:8px;color:#e6edf3;font-size:16px;font-family:'SF Mono',Monaco,monospace;box-sizing:border-box;">
478
- </div>
479
- <div style="display:flex;flex-direction:column;gap:6px;">
480
- <label style="font-size:11px;color:#f0b90b;font-weight:700;letter-spacing:0.5px;text-transform:uppercase;" data-help="atr">&#128202; ATR Multiplier</label>
481
- <select id="atr-multiplier" style="width:15ch;padding:12px 14px;background:#0d1117;border:2px solid #30363d;border-radius:8px;color:#e6edf3;font-size:16px;box-sizing:border-box;">
482
- <option value="2" selected>2&#215; (default)</option>
483
- <option value="3">3&#215;</option>
484
- </select>
485
- </div>
486
- <div class="scan-tabs" style="margin:0;">
487
- <button class="scan-tab active" data-mode="conservative" onclick="setScanMode('conservative')">🛡️ Conservative</button><span class="mode-info" aria-label="What is Conservative?"><img src="/static/favicon.svg" alt="info"><span class="mode-tip"><strong style="color:#f0b90b;">🛡️ Conservative</strong><br>Mildly oversold coins (z-score &lt; &minus;1) with modest momentum (&gt; 5), low volatility (&lt; 8), RSI &lt; 70. Safer setups, fewer results. Best for calm markets.</span></span>
488
- <button class="scan-tab risk" data-mode="risk" onclick="setScanMode('risk')">🎲 Risk Taker</button><span class="mode-info" aria-label="What is Risk-Taker?"><img src="/static/favicon.svg" alt="info"><span class="mode-tip"><strong style="color:#f0b90b;">🎲 Risk-Taker</strong><br>Deeply oversold coins (z-score &lt; &minus;1.5) with strong momentum (&gt; 10), higher volatility tolerated (&lt; 25), RSI &lt; 60. More aggressive, more results. Best for choppy markets with violent rebounds.</span></span>
489
- </div>
490
- <button class="btn btn-primary" id="run-btn" style="margin:0;">🔄 Run Scan</button>
491
- <a class="btn btn-primary" href="https://scan.blind-monkeys.com/" style="margin:0;text-decoration:none;">🔺 Rising Coins</a>
492
- </div>
493
-
494
- <!-- Scan Progress Panel -->
495
- <div id="scan-progress" style="display: none; margin-top: 20px; padding: 24px; background: #1e2329; border-radius: 12px; border: 2px solid #f0b90b;">
496
- <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 16px;">
497
- <div class="scan-spinner"></div>
498
- <div style="font-size: 16px; font-weight: 600; color: #f0b90b;" id="scan-title">Scanning coins...</div>
499
- </div>
500
-
501
- <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 16px;">
502
- <span style="font-size: 32px;">⏱️</span>
503
- <span id="scan-timer" style="font-size: 32px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; color: #e6edf3;">00:00</span>
504
- <span style="font-size: 12px; color: #8b949e; margin-left: 8px;">elapsed</span>
505
- <span id="scan-counter" style="font-size: 32px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; color: #8b949e; margin-left: 24px;">0 / 100</span>
506
- </div>
507
-
508
- <div style="margin-bottom: 12px;">
509
- <div style="background: #0d1117; height: 8px; border-radius: 4px; overflow: hidden;">
510
- <div id="scan-progress-bar" style="background: linear-gradient(90deg, #4ade80, #f0b90b); height: 100%; width: 0%; transition: width 0.3s;"></div>
511
- </div>
512
  </div>
513
-
514
- <div id="scan-status" style="font-size: 13px; color: #8b949e;">Initializing scan...</div>
515
  </div>
 
 
516
 
517
- <div id="results" style="margin-top: 20px; padding: 20px; color: #8b949e;">
518
- Click "Run Scan" to begin...
519
- </div>
520
-
521
-
522
- </div>
523
-
524
  <script>
525
- var MAX_COINS = 10;
526
- var scannedCoins = [];
527
- var selectedCoins = new Set();
528
- var availableUsdt = 0;
529
- var PUBLIC_MODE = false;
530
- var SCANNED_COUNT = 0;
531
-
532
- // ---------- Colored pill helpers ----------
533
- function zPill(z) {
534
- if (z < -1) return '<span class="pill pill-green">' + z.toFixed(2) + '</span>';
535
- if (z > 1) return '<span class="pill pill-red">' + z.toFixed(2) + '</span>';
536
- return '<span class="pill pill-orange">' + z.toFixed(2) + '</span>';
537
- }
538
- function momPill(m) {
539
- if (m > 10) return '<span class="pill pill-green">' + m.toFixed(2) + '%</span>';
540
- if (m < -5) return '<span class="pill pill-red">' + m.toFixed(2) + '%</span>';
541
- return '<span class="pill pill-orange">' + m.toFixed(2) + '%</span>';
542
- }
543
- function volPill(v) {
544
- if (v < 3) return '<span class="pill pill-green">' + v.toFixed(2) + '%</span>';
545
- if (v > 8) return '<span class="pill pill-red">' + v.toFixed(2) + '%</span>';
546
- return '<span class="pill pill-orange">' + v.toFixed(2) + '%</span>';
547
- }
548
- function rsiPill(r) {
549
- if (r < 30) return '<span class="pill pill-green">' + r.toFixed(2) + '</span>';
550
- if (r > 70) return '<span class="pill pill-red">' + r.toFixed(2) + '</span>';
551
- return '<span class="pill pill-orange">' + r.toFixed(2) + '</span>';
552
- }
553
- function compositePill(s) {
554
- if (s > 10) return '<span class="pill pill-green">' + s.toFixed(2) + '</span>';
555
- if (s < 0) return '<span class="pill pill-red">' + s.toFixed(2) + '</span>';
556
- return '<span class="pill pill-orange">' + s.toFixed(2) + '</span>';
557
- }
558
- function buySignalCell(c) {
559
- if (c.buy_signal) {
560
- return '<span class="signal-yes">✅ BUY</span>';
561
- }
562
- var blockers = [];
563
- if (!(c.zscore < -1)) blockers.push('Z≥-1');
564
- if (!(c.momentum > 5)) blockers.push('Mom≤5');
565
- if (!(c.volatility < 8)) blockers.push('Vol≥8');
566
- if (!(c.rsi < 70)) blockers.push('RSI≥70');
567
- return '<span class="signal-no">❌</span>' +
568
- '<div class="blocker-list">' + blockers.join(', ') + '</div>';
569
- }
570
- // ----------------------------------------
571
- function loadUsdtBalance() {
572
- fetch('/api/bingx/balance')
573
- .then(function(r) { return r.json(); })
574
- .then(function(d) {
575
- var balances = d.balances || [];
576
- for (var i = 0; i < balances.length; i++) {
577
- if (balances[i].asset === 'USDT') {
578
- availableUsdt = parseFloat(balances[i].free) || 0;
579
- break;
580
- }
581
- }
582
- var el = document.getElementById('usdt-available');
583
- if (el) el.textContent = '$' + availableUsdt.toFixed(2);
584
- updateOrderSummary();
585
- })
586
- .catch(function(e) {
587
- var el = document.getElementById('usdt-available');
588
- if (el) el.textContent = 'Error';
589
- });
590
- }
591
- // ---------- Render results ----------
592
- window.SORT_COL = null;
593
- window.SORT_DIR = 'asc';
594
-
595
- function _sortArrow(col) {
596
- if (window.SORT_COL !== col) {
597
- return ' <span style="color:#f0b90b;opacity:0.55;font-size:14px;font-weight:900;letter-spacing:1px;">&#8645;</span>';
598
- }
599
- var arrow = window.SORT_DIR === 'asc' ? '&#9650;' : '&#9660;';
600
- return ' <span style="color:#f0b90b;font-size:16px;font-weight:900;letter-spacing:1px;">' + arrow + '</span>';
601
- }
602
-
603
- window.sortResults = function(col) {
604
- if (window.SORT_COL === col) {
605
- window.SORT_DIR = (window.SORT_DIR === 'asc') ? 'desc' : 'asc';
606
- } else {
607
- window.SORT_COL = col;
608
- window.SORT_DIR = 'asc';
609
- }
610
- var src = window.LAST_SCANNED_COINS || (typeof scannedCoins !== 'undefined' ? scannedCoins : null);
611
- if (src) renderResults(src);
612
- };
613
-
614
- var _livePriceTimer = null;
615
-
616
- function stopLivePricePoll() {
617
- if (_livePriceTimer) { clearInterval(_livePriceTimer); _livePriceTimer = null; }
618
- }
619
-
620
- function _doLivePricePoll() {
621
- var rows = document.querySelectorAll('#results tbody tr[data-symbol]');
622
- if (!rows.length) return;
623
- var symbols = [];
624
- rows.forEach(function(r) {
625
- var sym = r.getAttribute('data-symbol');
626
- if (sym && symbols.indexOf(sym) === -1) symbols.push(sym);
627
- });
628
- if (!symbols.length) return;
629
-
630
- var chunks = [];
631
- for (var i = 0; i < symbols.length; i += 15) {
632
- chunks.push(symbols.slice(i, i + 15));
633
- }
634
-
635
- Promise.all(chunks.map(function(chunk) {
636
- return fetch('/api/price/batch?symbols=' + encodeURIComponent(chunk.join(',')))
637
- .then(function(r) { return r.json(); })
638
- .catch(function() { return null; });
639
- })).then(function(results) {
640
- var merged = {};
641
- results.forEach(function(resp) {
642
- if (resp && resp.status === 'ok' && resp.data) {
643
- Object.keys(resp.data).forEach(function(k) { merged[k] = resp.data[k]; });
644
- }
645
- });
646
- if (!Object.keys(merged).length) return;
647
-
648
- var mult = window.ATR_MULTIPLIER || 2;
649
- rows.forEach(function(row) {
650
- var sym = row.getAttribute('data-symbol');
651
- var cid = row.getAttribute('data-coin-id');
652
- var atr = parseFloat(row.getAttribute('data-atr')) || 0;
653
- var info = merged[sym];
654
- if (!info || info.price == null) return;
655
-
656
- var priceEl = document.getElementById('liveprice-' + cid);
657
- var tpEl = document.getElementById('livetp-' + cid);
658
- var slEl = document.getElementById('livesl-' + cid);
659
- if (!priceEl) return;
660
-
661
- var oldPx = parseFloat(priceEl.textContent.replace(/[$,]/g, ''));
662
- var newPx = info.price;
663
-
664
- priceEl.textContent = '$' + newPx.toFixed(6);
665
- if (tpEl) tpEl.textContent = '$' + (newPx + mult * atr).toFixed(6);
666
- if (slEl) slEl.textContent = '$' + (newPx - mult * atr).toFixed(6);
667
-
668
- if (!isNaN(oldPx) && Math.abs(oldPx - newPx) > 1e-12) {
669
- var cls = newPx > oldPx ? 'flash-up' : 'flash-down';
670
- priceEl.classList.remove('flash-up', 'flash-down');
671
- void priceEl.offsetWidth;
672
- priceEl.classList.add(cls);
673
- setTimeout(function() { priceEl.classList.remove('flash-up', 'flash-down'); }, 950);
674
- }
675
- });
676
- });
677
- }
678
-
679
- function startLivePricePoll() {
680
- stopLivePricePoll();
681
- setTimeout(_doLivePricePoll, 4000);
682
- _livePriceTimer = setInterval(function() {
683
- if (document.hidden) return;
684
- _doLivePricePoll();
685
- }, 30000);
686
- }
687
-
688
- document.addEventListener('visibilitychange', function() {
689
- if (!document.hidden && _livePriceTimer) _doLivePricePoll();
690
- });
691
-
692
- function renderResults(coins) {
693
- stopLivePricePoll();
694
- window.LAST_SCANNED_COINS = coins;
695
- if (window.SORT_COL && coins && coins.length) {
696
- var _dir = window.SORT_DIR || 'asc';
697
- coins = coins.slice().sort(function(a, b) {
698
- if (window.SORT_COL === 'symbol') {
699
- var av = String(a.symbol || '').toLowerCase();
700
- var bv = String(b.symbol || '').toLowerCase();
701
- return _dir === 'asc' ? av.localeCompare(bv) : bv.localeCompare(av);
702
- } else {
703
- var ap = parseFloat(a.price) || 0;
704
- var bp = parseFloat(b.price) || 0;
705
- return _dir === 'asc' ? ap - bp : bp - ap;
706
- }
707
- });
708
- }
709
- var out = document.getElementById('results');
710
- if (!coins || coins.length === 0) { out.textContent = 'No results found.'; return; }
711
-
712
- var finalElapsed = window.SCAN_ELAPSED || 0;
713
- var em = Math.floor(finalElapsed / 60).toString().padStart(2, '0');
714
- var es = (finalElapsed % 60).toString().padStart(2, '0');
715
- var elapsedStr = em + ':' + es;
716
- var countStr = SCANNED_COUNT + ' of 100 coins scanned in ' + elapsedStr + ' seconds';
717
-
718
- var headerHtml = '<div style="background:#1e2329;border-radius:12px;padding:16px;margin-bottom:16px;border-left:4px solid #f0b90b;display:flex;align-items:center;gap:24px;flex-wrap:wrap;">';
719
- headerHtml += '<div style="color:#f0b90b;font-weight:600;font-size:15px;">📊 Scan Results — Coin Scan and Analysis</div>';
720
- headerHtml += '<div style="font-family:\'SF Mono\', Monaco, monospace;font-size:14px;color:#8b949e;">' + countStr + '</div>';
721
- headerHtml += '</div>';
722
-
723
- var html = headerHtml;
724
- html += '<table style="width:100%;border-collapse:collapse;background:#1e2329;border-radius:12px;overflow:hidden;">';
725
- html += '<thead><tr style="border-bottom:1px solid #30363d;">';
726
- html += '<th style="text-align:center;padding:10px;color:#8b949e;">☑</th>';
727
- html += '<th onclick="sortResults(\'symbol\')" style="text-align:left;padding:10px;color:#8b949e;cursor:pointer;user-select:none;">Coin' + _sortArrow('symbol') + '</th>';
728
-
729
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Invest ($)</th>';
730
- html += '<th onclick="sortResults(\'price\')" style="text-align:right;padding:10px;color:#8b949e;cursor:pointer;user-select:none;">Price' + _sortArrow('price') + '</th>';
731
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">TP (' + (window.ATR_MULTIPLIER || 2) + '&#215;)</th>';
732
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">SL (' + (window.ATR_MULTIPLIER || 2) + '&#215;)</th>';
733
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Z-Score</th>';
734
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Momentum</th>';
735
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Volatility</th>';
736
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">RSI</th>';
737
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Score</th>';
738
- html += '<th style="text-align:right;padding:10px;color:#8b949e;">Signal</th>';
739
- html += '</tr></thead><tbody>';
740
-
741
- coins.forEach(function(c) {
742
- var _isSelected = (typeof selectedCoins !== 'undefined' && selectedCoins.has(c.coin_id));
743
- html += '<tr' + (_isSelected ? ' class="selected-row"' : '') + ' data-symbol="' + (c.symbol || '') + '" data-coin-id="' + (c.coin_id || '') + '" data-atr="' + (parseFloat(c.atr) || 0) + '" style="border-bottom:1px solid #21262d;">';
744
- html += '<td style="text-align:center;padding:10px;">';
745
- html += '<input type="checkbox" data-coin-id="' + c.coin_id + '"' + (_isSelected ? ' checked' : '') + ' onchange="toggleCoin(\'' + c.coin_id + '\', this)">';
746
- html += '</td>';
747
- html += '<td style="padding:10px;"><strong>' + c.symbol + '</strong></td>';
748
- html += '<td id="invest-' + c.coin_id + '" style="text-align:right;padding:10px;color:#8b949e;font-family:monospace;font-size:13px;">—</td>';
749
- html += '<td id="liveprice-' + c.coin_id + '" style="text-align:right;padding:10px;">$' + parseFloat(c.price).toFixed(6) + '</td>';
750
- var _atrMult = window.ATR_MULTIPLIER || 2;
751
- var _tpField = _atrMult === 3 ? 'tp_3x' : 'tp_2x';
752
- var _slField = _atrMult === 3 ? 'sl_3x' : 'sl_2x';
753
- var _price = parseFloat(c.price) || 0;
754
- var _atr = parseFloat(c.atr) || 0;
755
- var _tp = (c[_tpField] !== undefined && c[_tpField] !== null) ? parseFloat(c[_tpField]) : _price + (_atrMult * _atr);
756
- var _sl = (c[_slField] !== undefined && c[_slField] !== null) ? parseFloat(c[_slField]) : _price - (_atrMult * _atr);
757
- html += '<td id="livetp-' + c.coin_id + '" style="text-align:right;padding:10px;color:#4ade80;font-family:monospace;font-size:13px;">$' + _tp.toFixed(6) + '</td>';
758
- html += '<td id="livesl-' + c.coin_id + '" style="text-align:right;padding:10px;color:#f87171;font-family:monospace;font-size:13px;">$' + _sl.toFixed(6) + '</td>';
759
- html += '<td style="text-align:right;padding:10px;">' + zPill(parseFloat(c.zscore)) + '</td>';
760
- html += '<td style="text-align:right;padding:10px;">' + momPill(parseFloat(c.momentum)) + '</td>';
761
- html += '<td style="text-align:right;padding:10px;">' + volPill(parseFloat(c.volatility)) + '</td>';
762
- html += '<td style="text-align:right;padding:10px;">' + rsiPill(parseFloat(c.rsi)) + '</td>';
763
- html += '<td style="text-align:right;padding:10px;">' + compositePill(parseFloat(c.composite_score)) + '</td>';
764
- html += '<td style="text-align:right;padding:10px;">' + buySignalCell(c) + '</td>';
765
- html += '</tr>';
766
  });
767
-
768
- html += '</tbody></table>';
769
- html += '<div id="save-order-wrap" style="margin-top: 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;">';
770
- html += '<button class="btn" id="save-order-btn" disabled style="background: #1e2329; color: #f0b90b; border: 2px solid #f0b90b; padding: 12px 22px; border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer;">💾 Save Coin Selection(s) for Entry into Your Exchange</button>';
771
- html += '<span id="save-order-status" style="font-size: 13px; color: #8b949e;"></span>';
772
- html += '</div>';
773
- out.innerHTML = html;
774
- startLivePricePoll();
775
- if (typeof updateInvestColumn === 'function') { updateInvestColumn(); }
776
  }
777
-
778
- // ---------- Diagnostic report ----------
779
- function renderDiagnostics(coins) {
780
- if (!coins || coins.length === 0) return '';
781
-
782
- var analyzed = coins.map(function(c) {
783
- var z = parseFloat(c.zscore);
784
- var m = parseFloat(c.momentum);
785
- var v = parseFloat(c.volatility);
786
- var r = parseFloat(c.rsi);
787
- var fails = [];
788
- if (!(z < -1)) fails.push('Z');
789
- if (!(m > 5)) fails.push('Mom');
790
- if (!(v < 8)) fails.push('Vol');
791
- if (!(r < 70)) fails.push('RSI');
792
- return { coin: c, z: z, m: m, v: v, r: r, fails: fails };
793
- });
794
-
795
- // Sort alphabetically by symbol
796
- analyzed.sort(function(a, b) {
797
- return a.coin.symbol.localeCompare(b.coin.symbol);
798
- });
799
-
800
- function cell(val, pass, suffix) {
801
- var emoji = pass ? '✅' : '❌';
802
- return val.toFixed(2) + (suffix || '') + ' ' + emoji;
803
- }
804
-
805
- var html = '';
806
- html += '<div style="background:#1e2329;border-radius:12px;padding:20px;margin-top:20px;margin-bottom:16px;border-left:4px solid #4ade80;">';
807
- html += '<div style="color:#4ade80;font-weight:600;font-size:15px;margin-bottom:8px;">📊 Scan Results</div>';
808
- html += '<div style="font-family:\'SF Mono\', Monaco, monospace;font-size:14px;color:#8b949e;margin-bottom:16px;">' + coins.length + ' coins scanned · sorted A–Z</div>';
809
-
810
- html += '<table style="width:100%;border-collapse:collapse;">';
811
- html += '<thead><tr style="border-bottom:1px solid #30363d;">';
812
- html += '<th style="text-align:left;padding:8px;color:#8b949e;font-size:12px;">Coin</th>';
813
- html += '<th style="text-align:right;padding:8px;color:#8b949e;font-size:12px;">Z</th>';
814
- html += '<th style="text-align:right;padding:8px;color:#8b949e;font-size:12px;">Mom</th>';
815
- html += '<th style="text-align:right;padding:8px;color:#8b949e;font-size:12px;">Vol</th>';
816
- html += '<th style="text-align:right;padding:8px;color:#8b949e;font-size:12px;">RSI</th>';
817
- html += '<th style="text-align:left;padding:8px;color:#8b949e;font-size:12px;">Which Criteria Fail</th>';
818
- html += '</tr></thead><tbody>';
819
-
820
- analyzed.forEach(function(a) {
821
- var failText;
822
- if (a.fails.length === 0) {
823
- failText = '—';
824
- } else if (a.fails.length === 1) {
825
- failText = 'Only ' + a.fails[0] + ' fails';
826
- } else {
827
- failText = a.fails.join(', ') + ' (' + a.fails.length + ' fail)';
828
- }
829
- html += '<tr style="border-bottom:1px solid #21262d;">';
830
- html += '<td style="padding:8px;font-size:13px;"><strong>' + a.coin.symbol + '</strong></td>';
831
- html += '<td style="text-align:right;padding:8px;font-size:13px;">' + cell(a.z, a.z < -1) + '</td>';
832
- html += '<td style="text-align:right;padding:8px;font-size:13px;">' + cell(a.m, a.m > 5, '%') + '</td>';
833
- html += '<td style="text-align:right;padding:8px;font-size:13px;">' + cell(a.v, a.v < 8, '%') + '</td>';
834
- html += '<td style="text-align:right;padding:8px;font-size:13px;">' + cell(a.r, a.r < 70) + '</td>';
835
- html += '<td style="padding:8px;font-size:12px;color:#8b949e;">' + failText + '</td>';
836
- html += '</tr>';
837
- });
838
-
839
- html += '</tbody></table>';
840
- html += '<div style="color:#8b949e;font-size:12px;margin-top:12px;padding-top:12px;border-top:1px solid #30363d;">Criteria: Z &lt; -1 · Mom &gt; 5% · Vol &lt; 8% · RSI &lt; 70</div>';
841
- html += '</div>';
842
- return html;
843
- }
844
-
845
- function toggleCoin(coinId, checkbox) {
846
- if (checkbox.checked) {
847
- if (selectedCoins.size >= MAX_COINS) {
848
- checkbox.checked = false;
849
- alert('Maximum ' + MAX_COINS + ' coins allowed. Uncheck a coin first.');
850
- return;
851
- }
852
- selectedCoins.add(coinId);
853
- } else {
854
- selectedCoins.delete(coinId);
855
- }
856
- var row = checkbox.closest('tr');
857
- if (checkbox.checked) { row.classList.add('selected-row'); }
858
- else { row.classList.remove('selected-row'); }
859
- updateOrderSummary();
860
- if (typeof updateInvestColumn === 'function') { updateInvestColumn(); }
861
- if (typeof updateSaveOrderBtn === 'function') { updateSaveOrderBtn(); }
862
- }
863
- window.toggleCoin = toggleCoin;
864
-
865
- function formatMoney(n) {
866
- var parts = Math.abs(n).toFixed(2).split('.');
867
- return (n < 0 ? '-' : '') + parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') + '.' + parts[1];
868
- }
869
-
870
- function updateInvestColumn() {
871
- var coins = window.LAST_SCANNED_COINS || [];
872
- var total = window.INVESTMENT || 0;
873
- var targetIds = [];
874
-
875
- if (typeof selectedCoins !== 'undefined' && selectedCoins && selectedCoins.size) {
876
- targetIds = Array.from(selectedCoins);
877
- }
878
-
879
- var per = targetIds.length > 0 ? total / targetIds.length : 0;
880
-
881
- coins.forEach(function(c) {
882
- var cell = document.getElementById('invest-' + c.coin_id);
883
- if (!cell) return;
884
- if (targetIds.indexOf(c.coin_id) === -1 || per <= 0) {
885
- cell.textContent = '\u2014';
886
- cell.style.color = '#8b949e';
887
- } else {
888
- cell.textContent = formatMoney(per);
889
- cell.style.color = '#f0b90b';
890
- }
891
- });
892
- }
893
- window.updateInvestColumn = updateInvestColumn;
894
-
895
- function updateOrderSummary() {
896
- var count = selectedCoins.size;
897
- var _countEl = document.getElementById('selected-count');
898
- if (_countEl) _countEl.textContent = count;
899
-
900
- var allocationEl = document.getElementById('allocation-slider');
901
- var usdtToDeployEl = document.getElementById('usdt-to-deploy');
902
- var usdtPerCoinEl = document.getElementById('usdt-per-coin');
903
- var buyBtn = document.getElementById('buy-btn');
904
- var orderPanel = document.getElementById('order-panel');
905
-
906
- if (!allocationEl || !buyBtn || !orderPanel) return;
907
-
908
- var allocation = parseInt(allocationEl.value);
909
- var usdtToDeploy = availableUsdt * (allocation / 100);
910
-
911
- if (count > 0 && usdtToDeploy > 0) {
912
- var perCoin = usdtToDeploy / count;
913
- if (usdtToDeployEl) usdtToDeployEl.textContent = '$' + usdtToDeploy.toFixed(2);
914
- if (usdtPerCoinEl) usdtPerCoinEl.textContent = '$' + perCoin.toFixed(2) + ' (equal)';
915
- buyBtn.disabled = false;
916
- buyBtn.textContent = '⚡ Buy ' + count + ' Coin' + (count > 1 ? 's' : '') + ' (' + allocation + '% USDT)';
917
- orderPanel.classList.add('visible');
918
  } else {
919
- if (usdtToDeployEl) usdtToDeployEl.textContent = '-';
920
- if (usdtPerCoinEl) usdtPerCoinEl.textContent = '-';
921
- buyBtn.disabled = true;
922
- if (count === 0) orderPanel.classList.remove('visible');
923
- }
924
- }
925
-
926
-
927
- fetch('/api/bingx/status')
928
- .then(function(r) { return r.json(); })
929
- .then(function(d) {
930
- PUBLIC_MODE = d.public_mode === true;
931
- if (PUBLIC_MODE) {
932
- var _subEl = document.getElementById('subtitle'); if (_subEl) _subEl.textContent =
933
- 'Scanning coins with high liquidity in the spot market — recommending the best buying opportunities';
934
- document.getElementById('order-panel').style.display = 'none';
935
- }
936
- })
937
- .catch(function() { PUBLIC_MODE = false; });
938
-
939
- // ---------- Market regime ----------
940
- async function loadMarketRegime() {
941
- var banner = document.getElementById('regime-banner');
942
- var iconEl = document.getElementById('regime-icon');
943
- var statusEl = document.getElementById('regime-status');
944
- var msgEl = document.getElementById('regime-message');
945
- var statsEl = document.getElementById('regime-stats');
946
-
947
- try {
948
- var res = await fetch('/api/market-regime');
949
- var d = await res.json();
950
-
951
- if (d.error) { banner.style.display = 'none'; return; }
952
-
953
- banner.style.display = 'block';
954
- iconEl.textContent = d.icon;
955
- statusEl.textContent = d.status === 'buy_zone' ? '🟢 BUY ZONE' :
956
- d.status === 'watch' ? '🟡 WATCH' :
957
- '🔴 WAIT';
958
- statusEl.style.color = d.status === 'buy_zone' ? '#4ade80' :
959
- d.status === 'watch' ? '#f0b90b' :
960
- '#f87171';
961
- msgEl.textContent = d.message;
962
- statsEl.textContent = 'ETH: $' + d.eth_current.toLocaleString() +
963
- ' | 24h High: $' + d.eth_high_24h.toLocaleString() +
964
- ' | ' + (d.drop_pct >= 0 ? '+' : '') + d.drop_pct.toFixed(2) + '% from high';
965
-
966
- banner.style.borderColor = d.status === 'buy_zone' ? '#4ade80' :
967
- d.status === 'watch' ? '#f0b90b' :
968
- '#f87171';
969
- } catch (err) {
970
- banner.style.display = 'none';
971
- }
972
- }
973
-
974
- // ---------- Run scan ----------
975
- document.getElementById('run-btn').onclick = function() {
976
- var btn = this;
977
- var out = document.getElementById('results');
978
- var progressPanel = document.getElementById('scan-progress');
979
- var timerEl = document.getElementById('scan-timer');
980
- var progressBar = document.getElementById('scan-progress-bar');
981
- var statusEl = document.getElementById('scan-status');
982
- var scanTitle = document.getElementById('scan-title');
983
-
984
- btn.disabled = true;
985
- btn.textContent = '⏳ Scanning...';
986
-
987
- progressPanel.style.display = 'block';
988
- out.style.display = 'none';
989
- progressPanel.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
990
-
991
- scanTitle.textContent = 'Scanning coins in the spot market at Binance...';
992
-
993
- var startTime = Date.now();
994
- var timerInterval = setInterval(function() {
995
- var elapsed = Math.floor((Date.now() - startTime) / 1000);
996
- var mins = Math.floor(elapsed / 60).toString().padStart(2, '0');
997
- var secs = (elapsed % 60).toString().padStart(2, '0');
998
- timerEl.textContent = mins + ':' + secs;
999
-
1000
- var counterEl = document.getElementById('scan-counter');
1001
- if (counterEl) {
1002
- var count = Math.min(100, Math.floor(elapsed / 1.5) + 1);
1003
- counterEl.textContent = count + ' / 100';
1004
- }
1005
-
1006
- if (elapsed < 30) {
1007
- timerEl.style.color = '#4ade80';
1008
- } else if (elapsed < 90) {
1009
- timerEl.style.color = '#f0b90b';
1010
- } else {
1011
- timerEl.style.color = '#f87171';
1012
- }
1013
-
1014
- var progress = Math.min(95, (elapsed / 45) * 100);
1015
- progressBar.style.width = progress + '%';
1016
-
1017
- if (elapsed < 5) {
1018
- statusEl.textContent = 'Fetching coin list from registry...';
1019
- } else if (elapsed < 15) {
1020
- statusEl.textContent = 'Checking liquidity and availability at Binance...';
1021
- } else if (elapsed < 30) {
1022
- statusEl.textContent = 'Fetching 20-day price history from Binance...';
1023
- } else if (elapsed < 45) {
1024
- statusEl.textContent = 'Calculating Z-scores, momentum, and RSI...';
1025
- } else {
1026
- statusEl.textContent = 'Ranking coins by composite score...';
1027
- }
1028
- }, 100);
1029
-
1030
- if (typeof edgemetry === 'function') edgemetry('scan_run');
1031
-
1032
- fetch('/api/scan?mode=' + (window.SCAN_MODE || 'conservative'))
1033
- .then(function(r) {
1034
- if (r.status === 429) {
1035
- return r.json().then(function(err) {
1036
- throw new Error(err.message || 'Please wait before scanning again.');
1037
- });
1038
- }
1039
- return r.json();
1040
- })
1041
- .then(function(d) {
1042
- scannedCoins = d.results || [];
1043
- if (typeof d.results === 'object' && !Array.isArray(d.results)) {
1044
- scannedCoins = d.results.results || [];
1045
- }
1046
- SCANNED_COUNT = d.total_scanned || scannedCoins.length;
1047
- window.SCAN_ELAPSED = Math.floor((Date.now() - startTime) / 1000);
1048
- clearInterval(timerInterval);
1049
- progressPanel.style.display = 'none';
1050
- out.style.display = 'block';
1051
- renderResults(scannedCoins);
1052
- if (!PUBLIC_MODE) {
1053
- loadUsdtBalance();
1054
- }
1055
- })
1056
- .catch(function(e) {
1057
- clearInterval(timerInterval);
1058
- progressPanel.style.display = 'none';
1059
- out.style.display = 'block';
1060
- out.textContent = 'Error: ' + e.message;
1061
- })
1062
- .finally(function() {
1063
- btn.disabled = false;
1064
- btn.textContent = '🔄 Run Scan';
1065
- });
1066
- };
1067
-
1068
- // ---------- Market Regime Panel (Phase 2) ----------
1069
- function _sparklinePath(points, w, h) {
1070
- if (!points || points.length < 2) return '';
1071
- var vals = points.map(function(p){ return p[1]; });
1072
- var min = Math.min.apply(null, vals);
1073
- var max = Math.max.apply(null, vals);
1074
- var range = max - min || 0.001;
1075
- var stepX = w / (points.length - 1);
1076
- var pad = 3;
1077
- var usableH = h - pad * 2;
1078
- var d = '';
1079
- for (var i = 0; i < points.length; i++) {
1080
- var x = i * stepX;
1081
- var y = pad + (1 - (points[i][1] - min) / range) * usableH;
1082
- d += (i === 0 ? 'M' : 'L') + x.toFixed(1) + ',' + y.toFixed(1);
1083
- }
1084
- return d;
1085
- }
1086
-
1087
- function _fngClass(v) {
1088
- if (v >= 55) return 'regime-fng-greed';
1089
- if (v >= 45) return 'regime-fng-neutral';
1090
- return 'regime-fng-fear';
1091
- }
1092
-
1093
- function _vixLabel(v) {
1094
- if (v == null) return '';
1095
- if (v < 15) return 'Low volatility — calm markets';
1096
- if (v < 20) return 'Normal range';
1097
- if (v < 30) return 'Elevated — caution';
1098
- return 'Panic — high fear';
1099
- }
1100
-
1101
- function setGauge(needleId, value) {
1102
- var angle = (Math.max(0, Math.min(100, value)) - 50) * 1.8;
1103
- var el = document.getElementById(needleId);
1104
- if (el) el.setAttribute('transform', 'rotate(' + angle.toFixed(2) + ' 100 100)');
1105
- }
1106
-
1107
- function loadRegimePanel() {
1108
- fetch('/api/regime-panel')
1109
- .then(function(r){ return r.json(); })
1110
- .then(function(d){
1111
- // --- Treasury ---
1112
- var t = d.treasury;
1113
- var tVal = document.getElementById('regime-treasury-value');
1114
- var tSub = document.getElementById('regime-treasury-sub');
1115
- var tSvg = document.getElementById('regime-treasury-spark');
1116
- if (t && t.series && t.series.length) {
1117
- // trim to last ~365 observations (1 year)
1118
- var series = t.series.slice(-365);
1119
- tVal.textContent = t.current.toFixed(2) + '%';
1120
- tSub.textContent = 'as of ' + t.date + ' · ' + series.length + 'd';
1121
- var path = _sparklinePath(series, 400, 44);
1122
- var lastX = 400;
1123
- var vals = series.map(function(p){ return p[1]; });
1124
- var min = Math.min.apply(null, vals);
1125
- var max = Math.max.apply(null, vals);
1126
- var range = max - min || 0.001;
1127
- var lastY = 3 + (1 - (series[series.length-1][1] - min) / range) * (44 - 6);
1128
- tSvg.innerHTML =
1129
- '<path d="' + path + '" fill="none" stroke="#f0b90b" stroke-width="1.5" vector-effect="non-scaling-stroke"/>' +
1130
- '<circle cx="' + lastX + '" cy="' + lastY.toFixed(1) + '" r="3" fill="#f0b90b"/>';
1131
- } else {
1132
- tVal.textContent = 'n/a';
1133
- tSub.textContent = 'FRED unavailable';
1134
- }
1135
- document.getElementById('regime-treasury').classList.remove('regime-loading');
1136
-
1137
- // --- Fear & Greed ---
1138
- var f = d.fear_greed;
1139
- var fVal = document.getElementById('regime-fng-value');
1140
- var fSub = document.getElementById('regime-fng-sub');
1141
- if (f) {
1142
- fVal.textContent = f.value;
1143
- fVal.className = 'regime-card-value ' + _fngClass(f.value);
1144
- fSub.textContent = f.classification;
1145
- setGauge('regime-fng-needle', f.value);
1146
- } else {
1147
- fVal.textContent = 'n/a';
1148
- fSub.textContent = 'alternative.me unavailable';
1149
- }
1150
- document.getElementById('regime-fng').classList.remove('regime-loading');
1151
-
1152
- // --- VIX ---
1153
- var v = d.vix;
1154
- var vVal = document.getElementById('regime-vix-value');
1155
- var vSub = document.getElementById('regime-vix-sub');
1156
- if (v) {
1157
- vVal.textContent = v.value.toFixed(2);
1158
- setGauge('regime-vix-needle', v.value);
1159
- vSub.textContent = _vixLabel(v.value) + ' · ' + v.date;
1160
- } else {
1161
- vVal.textContent = 'n/a';
1162
- vSub.textContent = 'FRED unavailable';
1163
- }
1164
- document.getElementById('regime-vix').classList.remove('regime-loading');
1165
- })
1166
- .catch(function(e){
1167
- console.warn('regime panel failed:', e);
1168
- ['regime-treasury','regime-fng','regime-vix'].forEach(function(id){
1169
- var el = document.getElementById(id);
1170
- el.classList.remove('regime-loading');
1171
- var val = el.querySelector('.regime-card-value');
1172
- if (val) val.textContent = 'n/a';
1173
- });
1174
- });
1175
- }
1176
-
1177
- document.addEventListener('DOMContentLoaded', loadRegimePanel);
1178
- document.addEventListener('DOMContentLoaded', function() {
1179
- // Default investment: $10,000
1180
- var _invInput = document.getElementById('investment-input');
1181
- if (_invInput && !_invInput.value) {
1182
- _invInput.value = '$10,000';
1183
- window.INVESTMENT = 10000;
1184
- } setScanMode('conservative'); });
1185
- // ---------- Scan Mode (conservative | risk) ----------
1186
- window.SCAN_MODE = 'conservative';
1187
- window.SCAN_MODE_DESCS = {
1188
- conservative: '🛡️ Top 20 by market cap · tight stops (Z<-1, Mom>5, Vol<8, RSI<70)',
1189
- risk: '🎲 Lower liquidity & high volatility · wider stops (Z<-1.5, Mom>10, Vol<25, RSI<60)'
1190
- };
1191
-
1192
- function setScanMode(mode) {
1193
- window.SCAN_MODE = mode;
1194
- document.querySelectorAll('.scan-tab').forEach(function(t) {
1195
- t.classList.toggle('active', t.dataset.mode === mode);
1196
- });
1197
- var desc = null; /* scan-mode-desc removed */
1198
- if (desc) desc.textContent = window.SCAN_MODE_DESCS[mode] || '';
1199
- var btn = document.getElementById('run-btn');
1200
- if (btn) btn.textContent = mode === 'risk' ? '🎲 Run Risk Scan' : '🛡️ Run Conservative Scan';
1201
- }
1202
- window.setScanMode = setScanMode;
1203
-
1204
- // ---------- Save Order (Profile) ----------
1205
- window.LOGGED_IN = null;
1206
- window.USER_ROLE = null;
1207
-
1208
- fetch('/api/whoami')
1209
- .then(function(r){ return r.json(); })
1210
- .then(function(d){
1211
- window.LOGGED_IN = !!d.logged_in;
1212
- window.USER_ROLE = d.role || null;
1213
- })
1214
- .catch(function(){ window.LOGGED_IN = false; });
1215
-
1216
- window.saveOrderToProfile = function() {
1217
- if (window.LOGGED_IN === false) {
1218
- var statusEl = document.getElementById('save-order-status');
1219
- if (statusEl) statusEl.innerHTML = 'Create a free account to save your coin selections. <a href="/register" style="color:#f0b90b;font-weight:600;text-decoration:none;">Register \u2192</a>';
1220
- return;
1221
- }
1222
- var inv = window.INVESTMENT || 0;
1223
- var mult = window.ATR_MULTIPLIER || 2;
1224
- var coins = window.LAST_SCANNED_COINS || [];
1225
-
1226
- if (inv <= 0) { return; }
1227
- if (typeof selectedCoins === 'undefined' || !selectedCoins || selectedCoins.size === 0) { return; }
1228
-
1229
- var selected = [];
1230
- coins.forEach(function(c) {
1231
- if (selectedCoins.has(c.coin_id)) {
1232
- var tpField = mult === 3 ? 'tp_3x' : 'tp_2x';
1233
- var slField = mult === 3 ? 'sl_3x' : 'sl_2x';
1234
- var price = parseFloat(c.price) || 0;
1235
- var atr = parseFloat(c.atr) || 0;
1236
- var tp = (c[tpField] !== undefined && c[tpField] !== null) ? parseFloat(c[tpField]) : price + (mult * atr);
1237
- var sl = (c[slField] !== undefined && c[slField] !== null) ? parseFloat(c[slField]) : price - (mult * atr);
1238
- selected.push({
1239
- symbol: c.symbol,
1240
- coin_id: c.coin_id,
1241
- invest: inv / selectedCoins.size,
1242
- entry: price,
1243
- tp: tp,
1244
- sl: sl,
1245
- atr: atr
1246
- });
1247
- }
1248
- });
1249
-
1250
- if (selected.length === 0) { return; }
1251
-
1252
- var statusEl = document.getElementById('save-order-status');
1253
- if (statusEl) statusEl.textContent = 'Saving...';
1254
-
1255
- fetch('/api/orders/save', {
1256
- method: 'POST',
1257
- headers: {'Content-Type': 'application/json'},
1258
- body: JSON.stringify({
1259
- investment: inv,
1260
- atr_multiplier: mult,
1261
- scan_mode: (window.SCAN_MODE || 'conservative'),
1262
- coins: selected
1263
- })
1264
- })
1265
- .then(function(r){ return r.json(); })
1266
- .then(function(d){
1267
- if (d.error) {
1268
- if (statusEl) statusEl.textContent = 'Error: ' + d.error;
1269
- return;
1270
- }
1271
- if (typeof edgemetry === 'function') edgemetry('save_selection');
1272
- if (statusEl) {
1273
- statusEl.innerHTML = 'Saved as <strong style="color:#e6edf3;">' + d.name + '</strong>';
1274
- var vp = document.createElement('a');
1275
- vp.href = '/profile/';
1276
- vp.textContent = '\ud83d\udc64 View Profile';
1277
- vp.style.cssText = 'display:inline-block;background:#f0b90b;color:#0d1117;font-weight:700;padding:10px 18px;border-radius:8px;text-decoration:none;margin-left:12px;font-size:13px;';
1278
- statusEl.appendChild(vp);
1279
- }
1280
- })
1281
- .catch(function(e){
1282
- if (statusEl) statusEl.textContent = 'Save failed: ' + e.message;
1283
- });
1284
- };
1285
-
1286
- function updateSaveOrderBtn() {
1287
- var btn = document.getElementById('save-order-btn');
1288
- if (!btn) return;
1289
- var inv = window.INVESTMENT || 0;
1290
- var hasSel = (typeof selectedCoins !== 'undefined' && selectedCoins && selectedCoins.size > 0);
1291
- var ok = (inv > 0 && hasSel);
1292
- btn.disabled = !ok;
1293
- btn.style.opacity = ok ? '1' : '0.5';
1294
- btn.style.cursor = ok ? 'pointer' : 'not-allowed';
1295
- }
1296
- window.updateSaveOrderBtn = updateSaveOrderBtn;
1297
-
1298
- document.addEventListener('click', function(e) {
1299
- var t = e.target;
1300
- if (t && t.id === 'save-order-btn' && !t.disabled) {
1301
- window.saveOrderToProfile();
1302
  }
 
 
1303
  });
1304
-
1305
- // ---------- Phase 3: Investment input + ATR multiplier ----------
1306
- window.INVESTMENT = 0;
1307
- window.ATR_MULTIPLIER = 2;
1308
-
1309
- function formatWithCommas(n) {
1310
- if (n === '' || n === null || n === undefined) return '';
1311
- return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
1312
- }
1313
-
1314
- function updateTpSlColumns() {
1315
- if (window.LAST_SCANNED_COINS && window.LAST_SCANNED_COINS.length) {
1316
- renderResults(window.LAST_SCANNED_COINS);
1317
- }
1318
- }
1319
-
1320
- document.addEventListener('DOMContentLoaded', function() {
1321
- var invInput = document.getElementById('investment-input');
1322
- var multSel = document.getElementById('atr-multiplier');
1323
-
1324
- if (invInput) {
1325
- invInput.addEventListener('input', function() {
1326
- var raw = this.value.replace(/[^0-9]/g, '');
1327
- if (raw === '') {
1328
- this.value = '';
1329
- window.INVESTMENT = 0;
1330
- if (typeof updateInvestColumn === 'function') { updateInvestColumn(); }
1331
- return;
1332
- }
1333
- window.INVESTMENT = parseInt(raw, 10);
1334
- this.value = '$' + formatWithCommas(raw);
1335
- if (typeof updateInvestColumn === 'function') { updateInvestColumn(); }
1336
- if (typeof updateSaveOrderBtn === 'function') { updateSaveOrderBtn(); }
1337
- });
1338
- }
1339
-
1340
- if (multSel) {
1341
- multSel.addEventListener('change', function() {
1342
- window.ATR_MULTIPLIER = parseInt(this.value, 10) || 2;
1343
- updateTpSlColumns();
1344
- });
1345
- }
1346
- });
1347
- </script>
1348
- <script src="/static/help.js"></script>
1349
- <script src="/static/market-panel.js"></script>
1350
- <script src="/css/nav.js"></script>
1351
- <script>
1352
- document.addEventListener('DOMContentLoaded', function() {
1353
- try {
1354
- var ref = document.referrer || '';
1355
- if (ref.indexOf('/login') !== -1 && sessionStorage.getItem('et_login') !== '1') {
1356
- if (typeof edgemetry === 'function') edgemetry('login');
1357
- sessionStorage.setItem('et_login', '1');
1358
- }
1359
- } catch(e) {}
1360
- });
1361
- </script>
1362
- <script>
1363
- document.addEventListener('DOMContentLoaded', function() {
1364
- try {
1365
- var ref = document.referrer || '';
1366
- if (ref.indexOf('/login') !== -1 && sessionStorage.getItem('et_login') !== '1') {
1367
- if (typeof edgemetry === 'function') edgemetry('login');
1368
- sessionStorage.setItem('et_login', '1');
1369
- }
1370
- } catch(e) {}
1371
- });
1372
- </script>
1373
- <script>
1374
- (function() {
1375
- function fmtUSD(v) {
1376
- if (v === null || v === undefined || v === '') return '—';
1377
- var n = parseFloat(v);
1378
- if (isNaN(n)) return '—';
1379
- var sign = n >= 0 ? '+' : '-';
1380
- return sign + '$' + Math.abs(n).toFixed(2);
1381
- }
1382
- function setVal(id, text, sign) {
1383
- var el = document.getElementById(id);
1384
- if (!el) return;
1385
- el.textContent = text;
1386
- el.classList.remove('positive', 'negative', 'flat');
1387
- if (sign > 0) el.classList.add('positive');
1388
- else if (sign < 0) el.classList.add('negative');
1389
- else el.classList.add('flat');
1390
- }
1391
- function setWinRate(rate, totalBots) {
1392
- var el = document.getElementById('win-rate-value');
1393
- if (!el) return;
1394
- if (rate === null || rate === undefined) {
1395
- el.textContent = '—';
1396
- return;
1397
- }
1398
- el.textContent = rate.toFixed(1) + '%' + (totalBots ? ' (' + totalBots + ' bots)' : '');
1399
- }
1400
- });
1401
- }
1402
- function loadBotPnl() {
1403
- fetch('/api/bot-pnl').then(function(r){ return r.json(); }).then(function(d) {
1404
- if (!d || d.status !== 'ok') {
1405
- document.getElementById('pnl-updated').textContent = 'No bot data available';
1406
- return;
1407
- }
1408
- var cur = parseFloat(d.current_pnl || 0);
1409
- var curPct = parseFloat(d.current_pnl_per || 0) * 100;
1410
- var curText = fmtUSD(cur);
1411
- if (d.current_pnl_per) curText += ' (' + (curPct >= 0 ? '+' : '') + curPct.toFixed(2) + '%)';
1412
- setVal('pnl-current', curText, cur);
1413
-
1414
- var hasHist = (d.snapshot_count || 0) > 1;
1415
- if (hasHist) {
1416
- setVal('pnl-24h', fmtUSD(d.pnl_24h), parseFloat(d.pnl_24h || 0));
1417
- setVal('pnl-7d', fmtUSD(d.pnl_7d), parseFloat(d.pnl_7d || 0));
1418
- setVal('pnl-30d', fmtUSD(d.pnl_30d), parseFloat(d.pnl_30d || 0));
1419
- setVal('pnl-ytd', fmtUSD(d.pnl_ytd), parseFloat(d.pnl_ytd || 0));
1420
- }
1421
-
1422
- if (d.updated_at) {
1423
- var secAgo = Math.floor(Date.now() / 1000) - d.updated_at;
1424
- var txt = secAgo < 60 ? 'Updated just now' :
1425
- secAgo < 3600 ? 'Updated ' + Math.floor(secAgo/60) + 'm ago' :
1426
- 'Updated ' + Math.floor(secAgo/3600) + 'h ago';
1427
- document.getElementById('pnl-updated').textContent = txt;
1428
- }
1429
- }).catch(function(){});
1430
- }
1431
- function loadWinRate() {
1432
- fetch('/api/win-rate').then(function(r){ return r.json(); }).then(function(d) {
1433
- if (!d || d.status !== 'ok') {
1434
- setWinRate(null);
1435
- return;
1436
- }
1437
- setWinRate(d.win_rate, d.total_bots);
1438
- }).catch(function(){
1439
- setWinRate(null);
1440
- });
1441
- }
1442
- loadBotPnl();
1443
- loadWinRate();
1444
- setInterval(loadBotPnl, 60000);
1445
- setInterval(loadWinRate, 60000);
1446
- })();
1447
- </script>
1448
- <style>
1449
- .yt-section { width: 90vw; max-width: 1600px; margin: 40px auto 60px; }
1450
- .yt-title { color: #f0b90b; font-size: 22px; font-weight: 700; margin: 0 0 20px; }
1451
- .yt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 300px)); gap: 20px; }
1452
- .yt-item { background: #1e2329; border: 1px solid #30363d; border-radius: 12px; overflow: hidden; }
1453
- .yt-embed { position: relative; width: 100%; aspect-ratio: 9/16; background: #000; }
1454
- .yt-embed iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
1455
- .yt-caption { padding: 12px 16px; font-size: 14px; color: #e6edf3; line-height: 1.4; }
1456
- @media (max-width: 640px) { .yt-section { width: 95vw; } }
1457
- </style>
1458
-
1459
-
1460
-
1461
-
1462
- <section class="yt-section">
1463
- <div class="yt-head">
1464
- <h2 class="yt-title">📺 Recent Videos</h2>
1465
- <div id="ytAdminBar" style="display:none;">
1466
- <input id="ytInput" type="url" maxlength="200" placeholder="Paste YouTube URL">
1467
- <button id="ytAddBtn" class="yt-btn" type="button">Add video</button>
1468
- </div>
1469
- </div>
1470
- <div class="yt-grid" id="ytGrid"></div>
1471
- </section>
1472
- <style>
1473
- .yt-head { display:flex; align-items:center; gap:20px; flex-wrap:wrap; margin-bottom:20px; }
1474
- .yt-head .yt-title { margin:0; }
1475
- #ytAdminBar { display:flex; gap:8px; align-items:center; }
1476
- #ytInput { width:30ch; padding:8px 12px; border-radius:8px; border:1px solid #30363d; background:#1e2329; color:#e6edf3; font-size:14px; }
1477
- #ytInput:focus { outline:none; border-color:#f0b90b; }
1478
- .yt-btn { background:#f0b90b; color:#0b0e11; border:0; border-radius:8px; padding:8px 16px; font-weight:700; cursor:pointer; font-size:14px; }
1479
- .yt-btn:hover { background:#d9a70a; }
1480
- .yt-btn:disabled { opacity:0.6; cursor:not-allowed; }
1481
- .yt-empty { color:#8b949e; font-style:italic; padding:12px 0; }
1482
- </style>
1483
- <script src="/videos.js"></script>
1484
- <style>
1485
- #hsAlertBanner { position:sticky; top:0; z-index:1000; background:#3d1f00; border-bottom:2px solid #f0b90b; padding:10px 16px; display:none; }
1486
- #hsAlertBanner .hs-alert-item { display:flex; justify-content:space-between; align-items:center; color:#f0b90b; font-size:14px; padding:4px 0; max-width:1600px; margin:0 auto; }
1487
- #hsAlertBanner .hs-dismiss { background:transparent; border:1px solid #f0b90b; fetch color:#f0b90b; border-radius:6px;('/ width:26pxapi; height:26px; cursor:pointer;/al font-size:14px;erts line-height:1; }
1488
- #hsAlertB',anner .hs-dismiss:hover { background:#f0b90b; color:#0b0e11; }
1489
- </style>
1490
- <script src="/static/alerts.js?v=1"></script>
1491
  </body>
1492
  </html>
 
1
  <!doctype html>
2
  <html lang="en">
3
  <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Blind Monkeys</title>
7
  <link rel="stylesheet" href="/css/nav.css">
 
8
  <style>
9
+ * { box-sizing: border-box; }
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
11
+ .page-content { max-width: 1000px; margin: 0 auto; padding: 32px 20px 20px; }
12
+ h1 { font-size: 26px; margin: 0 0 4px; }
13
+ .sub { color: #8b949e; font-size: 14px; margin-bottom: 20px; }
14
+
15
+ .now { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; margin-bottom: 20px; text-align: center; }
16
+ .now .lbl { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #8b949e; margin-bottom: 8px; }
17
+ .now .val { font-size: 30px; font-weight: 700; }
18
+ .now .hint { font-size: 13px; color: #8b949e; margin-top: 8px; }
19
+
20
+ .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 28px; }
21
+ .stat { background: #1e2329; border: 1px solid #30363d; border-radius: 10px; padding: 14px 16px; }
22
+ .stat .t { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #f0b90b; margin-bottom: 6px; }
23
+ .stat .v { font-size: 20px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; }
24
+ .stat .d { font-size: 11px; color: #8b949e; margin-top: 4px; }
25
+
26
+ .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 40px; }
27
+ .card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 22px; text-decoration: none; color: #e6edf3; display: flex; flex-direction: column; transition: transform .15s ease, box-shadow .15s ease; position: relative; }
28
+ .card:hover { transform: translateY(-2px); }
29
+ .up.live { border-color: #4ade80; box-shadow: 0 0 18px rgba(74,222,128,.25); }
30
+ .side.live { border-color: #f0b90b; box-shadow: 0 0 18px rgba(240,185,11,.25); }
31
+ .down.live { border-color: #f87171; box-shadow: 0 0 18px rgba(248,113,113,.25); }
32
+ .ico { font-size: 32px; line-height: 1; margin-bottom: 12px; }
33
+ .t { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
34
+ .up .t { color: #4ade80; } .side .t { color: #f0b90b; } .down .t { color: #f87171; }
35
+ .desc { font-size: 13px; color: #8b949e; line-height: 1.5; margin-bottom: 12px; }
36
+ .strategy { font-size: 12px; line-height: 1.7; }
37
+ .strategy b { color: #e6edf3; }
38
+ .badge { position: absolute; top: 14px; right: 14px; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; padding: 4px 10px; border-radius: 6px; display: none; }
39
+ .card.live .badge { display: inline-block; }
40
+ .up .badge { background: rgba(74,222,128,.15); color: #4ade80; border: 1px solid #4ade80; }
41
+ .side .badge { background: rgba(240,185,11,.15); color: #f0b90b; border: 1px solid #f0b90b; }
42
+ .down .badge { background: rgba(248,113,113,.15); color: #f87171; border: 1px solid #f87171; }
43
+
44
+ /* ---------- Videos ---------- */
45
+ .yt-section { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px 40px; }
46
+ .yt-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
47
+ .yt-title { color: #f0b90b; font-size: 22px; font-weight: 700; margin: 0; }
48
+ .yt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
49
+ .yt-card { background: #1e2329; border: 1px solid #30363d; border-radius: 10px; overflow: hidden; }
50
+ .yt-card iframe { width: 100%; aspect-ratio: 16/9; border: 0; display: block; }
51
+ #ytAdminBar { display: flex; gap: 8px; align-items: center; }
52
+ #ytInput { padding: 8px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; color: #e6edf3; font-size: 13px; width: 320px; max-width: 70vw; }
53
+ #ytInput:focus { outline:none; border-color:#f0b90b; }
54
+ .yt-btn { background:#f0b90b; color:#0b0e11; border:0; border-radius:8px; padding:8px 16px; font-weight:700; cursor:pointer; font-size:14px; }
55
+ .yt-btn:hover { background:#d9a70a; }
56
+ .yt-btn:disabled { opacity:0.6; cursor:not-allowed; }
57
+ .yt-empty { color:#8b949e; font-style:italic; padding:12px 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  </style>
 
59
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  </head>
61
  <body>
62
  <nav class="nav-bar">
63
  <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
64
  <div class="nav-links">
65
+ <a href="/financials/" class="nav-link">📊 Financials</a>
66
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
 
67
  </div>
68
  </nav>
69
 
70
  <div class="page-content">
71
+ <div class="breadcrumbs"><span class="bc-current">Home</span></div>
72
+ <h1>🌍 Market Regimes</h1>
73
+ <p class="sub">Live market direction and the strategy that fits each regime.</p>
74
+
75
+ <div class="now">
76
+ <div class="lbl">Current Regime</div>
77
+ <div class="val" id="now-regime">Detecting…</div>
78
+ <div class="hint" id="now-hint">Based on ETH and BTC 24-hour price action.</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  </div>
80
 
81
+ <div class="stats">
82
+ <div class="stat"><div class="t">ETH off 24h High</div><div class="v" id="v-eth">—</div><div class="d">24h drawdown</div></div>
83
+ <div class="stat"><div class="t">Fear &amp; Greed</div><div class="v" id="v-fng">—</div><div class="d" id="d-fng">sentiment</div></div>
84
+ <div class="stat"><div class="t">VIX</div><div class="v" id="v-vix">—</div><div class="d">volatility</div></div>
85
+ <div class="stat"><div class="t">10Y Treasury</div><div class="v" id="v-tsyy">—</div><div class="d">macro</div></div>
86
+ </div>
87
 
88
+ <div class="cards">
89
+ <a class="card up" id="card-up" href="/upward">
90
+ <span class="badge">Active Now</span>
91
+ <div class="ico">📈</div>
92
+ <div class="t">Upward Markets</div>
93
+ <div class="desc">Prices trending up with sustained momentum. Breakouts hold; dips get bought quickly.</div>
94
+ <div class="strategy">
95
+ <b>What runs here:</b> trend-following entries, momentum signals, let-winners-run bias.<br>
96
+ <b>Watch:</b> overheating — rising ADX and stretched RSI can mark exhaustion.
97
  </div>
98
+ </a>
99
+ <a class="card side" id="card-side" href="/sideways">
100
+ <span class="badge">Active Now</span>
101
+ <div class="ico">↔️</div>
102
+ <div class="t">Sideways Markets</div>
103
+ <div class="desc">Range-bound price action — oscillation inside a band, low net drift.</div>
104
+ <div class="strategy">
105
+ <b>What runs here:</b> <b style="color:#f0b90b;">grid bots</b> — every oscillation is harvested profit. Our core strategy.<br>
106
+ <b>Watch:</b> bounces inside the ±3% band and low ADX (no trend).
107
  </div>
108
+ </a>
109
+ <a class="card down" id="card-down" href="/downward">
110
+ <span class="badge">Active Now</span>
111
+ <div class="ico">📉</div>
112
+ <div class="t">Downward Markets</div>
113
+ <div class="desc">BTC/ETH declining from highs — most coins follow, grids go quiet.</div>
114
+ <div class="strategy">
115
+ <b>What runs here:</b> <b style="color:#4ade80;">combo futures on Rising Coins</b> — coins rising against a falling market show relative strength.<br>
116
+ <b>Watch:</b> coins defying the drawdown with volume and open-interest growth.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  </div>
118
+ </a>
119
  </div>
120
+ </div>
121
 
122
+ <section class="yt-section">
123
+ <div class="yt-head">
124
+ <h2 class="yt-title">📺 Recent Videos</h2>
125
+ <div id="ytAdminBar" style="display:none;">
126
+ <input id="ytInput" type="url" maxlength="200" placeholder="Paste YouTube URL">
127
+ <button id="ytAddBtn" class="yt-btn" type="button">Add video</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  </div>
 
 
129
  </div>
130
+ <div class="yt-grid" id="ytGrid"></div>
131
+ </section>
132
 
133
+ <script src="/css/nav.js"></script>
134
+ <script src="/videos.js"></script>
135
+ <script src="/static/alerts.js?v=1"></script>
 
 
 
 
136
  <script>
137
+ function setRegime(kind, label, hint) {
138
+ var el = document.getElementById('now-regime');
139
+ el.textContent = label;
140
+ el.style.color = kind === 'up' ? '#4ade80' : (kind === 'down' ? '#f87171' : '#f0b90b');
141
+ var h = document.getElementById('now-hint');
142
+ if (h) h.textContent = hint;
143
+ ['up', 'side', 'down'].forEach(function (k) {
144
+ document.getElementById('card-' + k).classList.toggle('live', k === kind);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  });
 
 
 
 
 
 
 
 
 
146
  }
147
+ fetch('/api/market-regime').then(function (r) { return r.json(); }).then(function (d) {
148
+ var drop = Number(d.drop_pct || d.drop_percentage || 0);
149
+ var el = document.getElementById('v-eth');
150
+ el.textContent = drop.toFixed(2) + '%';
151
+ el.style.color = drop >= 2 ? '#f87171' : (drop <= 0.5 ? '#4ade80' : '#f0b90b');
152
+ if (drop >= 2) {
153
+ setRegime('down', '📉 Downward', 'ETH is ' + drop.toFixed(2) + '% off its 24h high — Rising Coin futures are the active strategy.');
154
+ } else if (drop < 0.5) {
155
+ setRegime('side', '↔️ Sideways', 'ETH is ' + drop.toFixed(2) + '% off its 24h high — oscillation regime, grid bots are harvesting.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  } else {
157
+ setRegime('up', '📈 Upward', 'ETH holding near its 24h high — momentum regime.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
+ }).catch(function () {
160
+ setRegime('side', '↔️ Sideways (assumed)', 'Could not read live regime data.');
161
  });
162
+ fetch('/api/regime-panel').then(function (r) { return r.json(); }).then(function (p) {
163
+ var f = p.fear_greed || {};
164
+ if (f && f.value !== undefined) {
165
+ var v = Number(f.value);
166
+ var el = document.getElementById('v-fng');
167
+ el.textContent = v;
168
+ el.style.color = v >= 55 ? '#4ade80' : (v <= 45 ? '#f87171' : '#f0b90b');
169
+ document.getElementById('d-fng').textContent = (f.classification || 'sentiment');
170
+ }
171
+ var vx = p.vix || {};
172
+ if (vx && vx.value !== undefined) {
173
+ var vv = Number(vx.value);
174
+ var elv = document.getElementById('v-vix');
175
+ elv.textContent = vv.toFixed(2);
176
+ elv.style.color = vv >= 25 ? '#f87171' : (vv <= 18 ? '#4ade80' : '#f0b90b');
177
+ }
178
+ var tr = p.treasury || {};
179
+ if (tr && tr.current !== undefined) {
180
+ document.getElementById('v-tsyy').textContent = Number(tr.current).toFixed(2) + '%';
181
+ }
182
+ }).catch(function () {});
183
+ </script>
184
+ <!--Start of Tawk.to Script-->
185
+ <script type="text/javascript">
186
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
187
+ (function(){
188
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
189
+ s1.async=true;
190
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
191
+ s1.charset='UTF-8';
192
+ s1.setAttribute('crossorigin','*');
193
+ s0.parentNode.insertBefore(s1,s0);
194
+ })();
195
+ </script>
196
+ <!--End of Tawk.to Script-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  </body>
198
  </html>
static/scan/short/index.html CHANGED
@@ -487,5 +487,18 @@
487
  }
488
  </script>
489
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  </body>
491
  </html>
 
487
  }
488
  </script>
489
  <script src="/css/nav.js"></script>
490
+ <!--Start of Tawk.to Script-->
491
+ <script type="text/javascript">
492
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
493
+ (function(){
494
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
495
+ s1.async=true;
496
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
497
+ s1.charset='UTF-8';
498
+ s1.setAttribute('crossorigin','*');
499
+ s0.parentNode.insertBefore(s1,s0);
500
+ })();
501
+ </script>
502
+ <!--End of Tawk.to Script-->
503
  </body>
504
  </html>
static/settings/index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Scan Settings — Blind Monkeys</title>
7
  <style>
8
  * { box-sizing: border-box; margin: 0; padding: 0; }
9
  body {
@@ -185,6 +185,17 @@
185
  border-color: #f0b90b;
186
  color: #f0b90b;
187
  }
 
 
 
 
 
 
 
 
 
 
 
188
  .spinner {
189
  display: inline-block;
190
  width: 14px;
@@ -217,75 +228,154 @@
217
  </nav>
218
 
219
  <div class="container">
220
- <h1>⚙️ Scan Settings</h1>
221
- <p class="subtitle">Configure dynamic coin selection criteria — changes apply immediately</p>
222
 
223
  <div class="status" id="status"></div>
 
224
 
225
  <div class="card">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  <div class="field">
227
- <label for="min_market_cap">Minimum Market Cap (USD)</label>
228
- <input type="number" id="min_market_cap" min="0" step="1000000">
229
- <div class="hint">Coins below this market cap will be excluded</div>
230
- <div class="presets">
231
- <button class="preset-btn" data-field="min_market_cap" data-value="1000000">$1M</button>
232
- <button class="preset-btn" data-field="min_market_cap" data-value="10000000">$10M</button>
233
- <button class="preset-btn" data-field="min_market_cap" data-value="100000000">$100M</button>
234
- <button class="preset-btn" data-field="min_market_cap" data-value="1000000000">$1B</button>
235
- </div>
236
  </div>
237
 
238
  <div class="field">
239
- <label for="min_volume">Minimum 24h Volume (USD)</label>
240
- <input type="number" id="min_volume" min="0" step="100000">
241
- <div class="hint">Coins below this trading volume will be excluded</div>
242
- <div class="presets">
243
- <button class="preset-btn" data-field="min_volume" data-value="100000">$100K</button>
244
- <button class="preset-btn" data-field="min_volume" data-value="1000000">$1M</button>
245
- <button class="preset-btn" data-field="min_volume" data-value="10000000">$10M</button>
246
- <button class="preset-btn" data-field="min_volume" data-value="100000000">$100M</button>
247
- </div>
248
  </div>
249
 
250
  <div class="field">
251
- <label for="max_coins">Maximum Number of Coins</label>
252
- <input type="number" id="max_coins" min="10" max="500" step="10">
253
- <div class="hint">Limits how many coins are fetched and scanned</div>
254
- <div class="presets">
255
- <button class="preset-btn" data-field="max_coins" data-value="25">25</button>
256
- <button class="preset-btn" data-field="max_coins" data-value="50">50</button>
257
- <button class="preset-btn" data-field="max_coins" data-value="100">100</button>
258
- <button class="preset-btn" data-field="max_coins" data-value="200">200</button>
259
- <button class="preset-btn" data-field="max_coins" data-value="500">500</button>
260
- </div>
261
  </div>
262
 
263
  <div class="field">
264
- <label for="cache_ttl">Cache Refresh Interval (hours)</label>
265
- <input type="number" id="cache_ttl" min="1" max="168" step="1">
266
- <div class="hint">How often the coin list is refreshed from CoinGecko</div>
267
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  </div>
269
 
270
- <div class="buttons">
271
- <button class="btn-primary" id="save-btn">💾 Save Settings</button>
272
- <button class="btn-secondary" id="refresh-btn">🔄 Refresh Coin List</button>
273
- <button class="btn-danger" id="reset-btn">↺ Reset Defaults</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  </div>
275
 
276
- <div class="info">
277
- <div class="info-row">
278
- <span><strong>📊 Coins in registry:</strong></span>
279
- <span id="coin-count">-</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  </div>
281
- <div class="info-row">
282
- <span><strong>💾 Settings file:</strong></span>
283
- <span>settings.json</span>
 
 
284
  </div>
285
- <div class="info-row">
286
- <span><strong>🗄️ Coin cache:</strong></span>
287
- <span>coins_cache.json</span>
 
 
288
  </div>
 
 
 
 
 
289
  </div>
290
 
291
  <div class="nav-links">
@@ -307,125 +397,215 @@
307
  }, 5000);
308
  }
309
 
310
- async function loadSettings() {
311
- try {
312
- const res = await fetch(`${API_BASE}/api/settings`);
313
- const settings = await res.json();
314
- document.getElementById('min_market_cap').value = settings.scan_min_market_cap;
315
- document.getElementById('min_volume').value = settings.scan_min_volume;
316
- document.getElementById('max_coins').value = settings.scan_max_coins;
317
- document.getElementById('cache_ttl').value = settings.coin_cache_ttl_hours;
318
- } catch (err) {
319
- showStatus('❌ Failed to load settings: ' + err.message, 'error');
320
- }
321
- }
322
 
323
- async function loadCoinCount() {
324
  try {
325
- const res = await fetch(`${API_BASE}/api/coins`);
326
- const data = await res.json();
327
- document.getElementById('coin-count').textContent = data.count;
 
 
 
 
 
 
 
 
328
  } catch (err) {
329
- document.getElementById('coin-count').textContent = 'Error';
330
  }
331
  }
332
 
333
- // Preset buttons
334
- document.querySelectorAll('.preset-btn').forEach(btn => {
335
- btn.addEventListener('click', () => {
336
- const field = btn.dataset.field;
337
- const value = btn.dataset.value;
338
- const inputId = field === 'min_market_cap' ? 'min_market_cap' :
339
- field === 'min_volume' ? 'min_volume' :
340
- field === 'max_coins' ? 'max_coins' : null;
341
- if (inputId) {
342
- document.getElementById(inputId).value = value;
343
- }
344
- });
345
- });
346
-
347
- // Save
348
- document.getElementById('save-btn').addEventListener('click', async () => {
349
- const btn = document.getElementById('save-btn');
350
  const original = btn.innerHTML;
351
  btn.disabled = true;
352
  btn.innerHTML = '<span class="spinner"></span>Saving...';
353
 
354
- const settings = {
355
- scan_min_market_cap: parseInt(document.getElementById('min_market_cap').value),
356
- scan_min_volume: parseInt(document.getElementById('min_volume').value),
357
- scan_max_coins: parseInt(document.getElementById('max_coins').value),
358
- coin_cache_ttl_hours: parseInt(document.getElementById('cache_ttl').value)
 
 
 
 
 
359
  };
360
 
361
  try {
362
- const res = await fetch(`${API_BASE}/api/settings`, {
363
  method: 'POST',
364
  headers: { 'Content-Type': 'application/json' },
365
- body: JSON.stringify(settings)
366
  });
367
- const data = await res.json();
368
- if (data.status === 'updated') {
369
- showStatus('✅ Settings saved! Coin cache cleared — next scan will use new criteria.', 'success');
370
- loadCoinCount();
371
  } else {
372
- showStatus('❌ Failed to save settings', 'error');
 
373
  }
374
  } catch (err) {
375
- showStatus('❌ Error: ' + err.message, 'error');
 
376
  } finally {
377
  btn.disabled = false;
378
  btn.innerHTML = original;
379
  }
380
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
 
382
- // Refresh coin list
383
- document.getElementById('refresh-btn').addEventListener('click', async () => {
384
- const btn = document.getElementById('refresh-btn');
385
  const original = btn.innerHTML;
386
  btn.disabled = true;
387
- btn.innerHTML = '<span class="spinner"></span>Fetching...';
 
 
 
 
 
 
 
 
388
 
389
  try {
390
- const res = await fetch(`${API_BASE}/api/coins/refresh`, { method: 'POST' });
391
- const data = await res.json();
392
- showStatus(`✅ Refreshed! ${data.count} coins loaded.`, 'success');
393
- document.getElementById('coin-count').textContent = data.count;
 
 
 
 
 
 
 
 
394
  } catch (err) {
395
- showStatus('❌ Error: ' + err.message, 'error');
 
396
  } finally {
397
  btn.disabled = false;
398
  btn.innerHTML = original;
399
  }
400
- });
 
 
401
 
402
- // Reset settings
403
- document.getElementById('reset-btn').addEventListener('click', async () => {
404
- if (!confirm('Reset all settings to defaults?')) return;
 
 
 
 
 
 
 
 
 
 
 
 
405
 
406
- const btn = document.getElementById('reset-btn');
 
 
407
  const original = btn.innerHTML;
408
  btn.disabled = true;
409
- btn.innerHTML = '<span class="spinner"></span>Resetting...';
 
 
 
 
 
 
 
 
 
410
 
411
  try {
412
- const res = await fetch(`${API_BASE}/api/settings/reset`, { method: 'POST' });
413
- const data = await res.json();
414
- showStatus('✅ Settings reset to defaults', 'success');
415
- loadSettings();
416
- loadCoinCount();
 
 
 
 
 
 
 
417
  } catch (err) {
418
- showStatus('❌ Error: ' + err.message, 'error');
 
419
  } finally {
420
  btn.disabled = false;
421
  btn.innerHTML = original;
422
  }
423
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
425
  // Initial load
426
- loadSettings();
427
- loadCoinCount();
 
 
428
  </script>
429
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
430
  </body>
431
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Settings — Blind Monkeys</title>
7
  <style>
8
  * { box-sizing: border-box; margin: 0; padding: 0; }
9
  body {
 
185
  border-color: #f0b90b;
186
  color: #f0b90b;
187
  }
188
+ .panel-title {
189
+ color: #f0b90b;
190
+ font-size: 20px;
191
+ font-weight: 700;
192
+ margin-bottom: 6px;
193
+ }
194
+ .panel-sub {
195
+ color: #8b949e;
196
+ font-size: 13px;
197
+ margin-bottom: 20px;
198
+ }
199
  .spinner {
200
  display: inline-block;
201
  width: 14px;
 
228
  </nav>
229
 
230
  <div class="container">
231
+ <h1>⚙️ Settings</h1>
232
+ <p class="subtitle">Automated trading settings — changes apply immediately</p>
233
 
234
  <div class="status" id="status"></div>
235
+ <div id="access-note" class="hint" style="display:none; margin:0 0 16px; color:#f0b90b;">👁️ View-only mode — sign in as an admin to edit settings.</div>
236
 
237
  <div class="card">
238
+ <div class="panel-title">🤖 Grid Settings</div>
239
+ <div class="panel-sub">Defaults for newly opened futures grid bots</div>
240
+
241
+ <div class="field">
242
+ <label for="g-lev">Leverage (1–10)</label>
243
+ <input type="number" id="g-lev" min="1" max="10" step="1">
244
+ <div class="hint">Leverage applied when opening a grid</div>
245
+ </div>
246
+
247
+ <div class="field">
248
+ <label for="g-rng">Range ±% (2–10)</label>
249
+ <input type="number" id="g-rng" min="2" max="10" step="1">
250
+ <div class="hint">Grid band above and below the entry price</div>
251
+ </div>
252
+
253
  <div class="field">
254
+ <label for="g-amt">Amount $ (100–99999)</label>
255
+ <input type="number" id="g-amt" min="100" max="99999" step="50">
256
+ <div class="hint">Capital allocated to each new grid</div>
 
 
 
 
 
 
257
  </div>
258
 
259
  <div class="field">
260
+ <label for="g-lines">Grid lines (5–20)</label>
261
+ <input type="number" id="g-lines" min="5" max="20" step="1">
262
+ <div class="hint">Number of grid levels within the range</div>
 
 
 
 
 
 
263
  </div>
264
 
265
  <div class="field">
266
+ <label for="g-cap">Daily cap $ (100–99999)</label>
267
+ <input type="number" id="g-cap" min="100" max="99999" step="500">
268
+ <div class="hint">Maximum total invested in new grids per day</div>
 
 
 
 
 
 
 
269
  </div>
270
 
271
  <div class="field">
272
+ <label for="g-tp">Take profit %</label>
273
+ <input type="number" id="g-tp" min="0.1" max="500" step="1">
274
+ <div class="hint">Take-profit target for the grid</div>
275
  </div>
276
+
277
+ <div class="field">
278
+ <label for="g-sl">Stop loss %</label>
279
+ <input type="number" id="g-sl" min="0.1" max="100" step="1">
280
+ <div class="hint">Stop-loss threshold for the grid</div>
281
+ </div>
282
+
283
+ <div class="field">
284
+ <label for="g-score">Auto open score ≥</label>
285
+ <input type="number" id="g-score" min="0" max="50" step="1">
286
+ <div class="hint">Minimum composite score to auto-open a grid</div>
287
+ </div>
288
+
289
+ <div class="field">
290
+ <label for="g-regime">Pause in downtrend: BTC 7d drift ≤ (%)</label>
291
+ <input type="number" id="g-regime" min="-100" max="0" step="1" value="-5">
292
+ <div class="hint">No new grids while BTC's 7-day drift is at or below this (set -100 to disable)</div>
293
+ </div>
294
+
295
+ <div class="buttons">
296
+ <button class="btn-primary" id="grid-save-btn">💾 Save Grid Settings</button>
297
+ </div>
298
+ <div id="grid-msg" class="hint"></div>
299
  </div>
300
 
301
+ <div class="card">
302
+ <div class="panel-title">📈 Futures Settings</div>
303
+ <div class="panel-sub">Auto-trade compounding and risk limits for futures</div>
304
+
305
+ <div class="field">
306
+ <label for="f-amt">Next order $ (override)</label>
307
+ <input type="number" id="f-amt" min="10" max="100000" step="1" placeholder="auto">
308
+ <div class="hint">Leave empty for the automatic compounding amount</div>
309
+ </div>
310
+
311
+ <div class="field">
312
+ <label for="f-up">Increase on TP (%)</label>
313
+ <input type="number" id="f-up" min="0" max="1000" step="1">
314
+ <div class="hint">Grow the order size after a take-profit</div>
315
+ </div>
316
+
317
+ <div class="field">
318
+ <label for="f-down">Decrease on SL (%)</label>
319
+ <input type="number" id="f-down" min="0" max="100" step="1">
320
+ <div class="hint">Shrink the order size after a stop-loss</div>
321
+ </div>
322
+
323
+ <div class="field">
324
+ <label for="f-cap">Daily cap ($)</label>
325
+ <input type="number" id="f-cap" min="10" max="100000" step="10">
326
+ <div class="hint">Maximum total invested in new futures positions per day</div>
327
+ </div>
328
+
329
+ <div class="buttons">
330
+ <button class="btn-primary" id="futures-save-btn">💾 Save Futures Settings</button>
331
+ </div>
332
+ <div id="futures-msg" class="hint"></div>
333
  </div>
334
 
335
+ <div class="card">
336
+ <div class="panel-title">🔺 Rising Coins Trading Settings</div>
337
+ <div class="panel-sub">Rules for trading coins identified by the rising coins scanner</div>
338
+
339
+ <div class="field">
340
+ <label for="r-amt">Amount ($)</label>
341
+ <input type="number" id="r-amt" min="10" max="100000" step="10" value="100">
342
+ <div class="hint">Capital allocated to each rising-coin position</div>
343
+ </div>
344
+
345
+ <div class="field">
346
+ <label for="r-lev">Leverage (x)</label>
347
+ <input type="number" id="r-lev" min="1" max="20" step="1" value="3">
348
+ <div class="hint">Leverage applied when opening a position</div>
349
+ </div>
350
+
351
+ <div class="field">
352
+ <label for="r-tp">Take Profit (%)</label>
353
+ <input type="number" id="r-tp" min="1" max="100" step="1" value="3">
354
+ <div class="hint">Take-profit target for the position</div>
355
+ </div>
356
+
357
+ <div class="field">
358
+ <label for="r-sl">Stop Loss (%)</label>
359
+ <input type="number" id="r-sl" min="1" max="100" step="1" value="3">
360
+ <div class="hint">Stop-loss threshold for the position</div>
361
  </div>
362
+
363
+ <div class="field">
364
+ <label for="r-cap">Daily Cap ($)</label>
365
+ <input type="number" id="r-cap" min="100" max="100000" step="100" value="1000">
366
+ <div class="hint">Maximum total invested in rising-coin positions per day</div>
367
  </div>
368
+
369
+ <div class="field">
370
+ <label for="r-fund">Max Funding Rate (%)</label>
371
+ <input type="number" id="r-fund" min="-1" max="100" step="0.01" value="0">
372
+ <div class="hint">Auto-open only when the coin's funding rate is at or below this (0 = longs are paid; 99 = gate off)</div>
373
  </div>
374
+
375
+ <div class="buttons">
376
+ <button class="btn-primary" id="riser-save-btn">💾 Save Rising Coins Settings</button>
377
+ </div>
378
+ <div id="riser-msg" class="hint"></div>
379
  </div>
380
 
381
  <div class="nav-links">
 
397
  }, 5000);
398
  }
399
 
400
+ // Grid Settings
 
 
 
 
 
 
 
 
 
 
 
401
 
402
+ async function loadGridSettings() {
403
  try {
404
+ const res = await fetch(`${API_BASE}/api/grid-config`);
405
+ const s = await res.json();
406
+ if (s.leverage != null) document.getElementById('g-lev').value = s.leverage;
407
+ if (s.range_percent != null) document.getElementById('g-rng').value = s.range_percent;
408
+ if (s.amount != null) document.getElementById('g-amt').value = s.amount;
409
+ if (s.grid_lines != null) document.getElementById('g-lines').value = s.grid_lines;
410
+ if (s.daily_cap != null) document.getElementById('g-cap').value = s.daily_cap;
411
+ if (s.tp_percent != null) document.getElementById('g-tp').value = s.tp_percent;
412
+ if (s.stop_loss_percent != null) document.getElementById('g-sl').value = s.stop_loss_percent;
413
+ if (s.auto_min_score != null) document.getElementById('g-score').value = s.auto_min_score;
414
+ if (s.regime_pause_drift != null) document.getElementById('g-regime').value = s.regime_pause_drift;
415
  } catch (err) {
416
+ // grid settings unavailable — leave defaults
417
  }
418
  }
419
 
420
+ async function saveGridSettings() {
421
+ const btn = document.getElementById('grid-save-btn');
422
+ const msg = document.getElementById('grid-msg');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
  const original = btn.innerHTML;
424
  btn.disabled = true;
425
  btn.innerHTML = '<span class="spinner"></span>Saving...';
426
 
427
+ const payload = {
428
+ leverage: Number(document.getElementById('g-lev').value),
429
+ range_percent: Number(document.getElementById('g-rng').value),
430
+ amount: Number(document.getElementById('g-amt').value),
431
+ grid_lines: Number(document.getElementById('g-lines').value),
432
+ daily_cap: Number(document.getElementById('g-cap').value),
433
+ tp_percent: Number(document.getElementById('g-tp').value),
434
+ stop_loss_percent: Number(document.getElementById('g-sl').value),
435
+ auto_min_score: Number(document.getElementById('g-score').value),
436
+ regime_pause_drift: Number(document.getElementById('g-regime').value)
437
  };
438
 
439
  try {
440
+ const res = await fetch(`${API_BASE}/api/grid-config`, {
441
  method: 'POST',
442
  headers: { 'Content-Type': 'application/json' },
443
+ body: JSON.stringify(payload)
444
  });
445
+ if (res.ok) {
446
+ msg.textContent = '✓ saved';
447
+ msg.style.color = '#4ade80';
 
448
  } else {
449
+ msg.textContent = '❌ save failed';
450
+ msg.style.color = '#f87171';
451
  }
452
  } catch (err) {
453
+ msg.textContent = '❌ ' + err.message;
454
+ msg.style.color = '#f87171';
455
  } finally {
456
  btn.disabled = false;
457
  btn.innerHTML = original;
458
  }
459
+ }
460
+
461
+ document.getElementById('grid-save-btn').addEventListener('click', saveGridSettings);
462
+
463
+ // Futures Settings
464
+ async function loadFuturesSettings() {
465
+ try {
466
+ const res = await fetch(`${API_BASE}/api/futures-config`);
467
+ const s = await res.json();
468
+ const amt = document.getElementById('f-amt');
469
+ if (s.override_amount != null && s.override_amount !== '') amt.value = s.override_amount;
470
+ else amt.value = '';
471
+ if (s.increase_pct != null) document.getElementById('f-up').value = s.increase_pct;
472
+ if (s.decrease_pct != null) document.getElementById('f-down').value = s.decrease_pct;
473
+ if (s.daily_cap != null) document.getElementById('f-cap').value = s.daily_cap;
474
+ } catch (err) {
475
+ // futures settings unavailable — leave defaults
476
+ }
477
+ }
478
 
479
+ async function saveFuturesSettings() {
480
+ const btn = document.getElementById('futures-save-btn');
481
+ const msg = document.getElementById('futures-msg');
482
  const original = btn.innerHTML;
483
  btn.disabled = true;
484
+ btn.innerHTML = '<span class="spinner"></span>Saving...';
485
+
486
+ const amtVal = document.getElementById('f-amt').value;
487
+ const payload = {
488
+ increase_pct: Number(document.getElementById('f-up').value),
489
+ decrease_pct: Number(document.getElementById('f-down').value),
490
+ daily_cap: Number(document.getElementById('f-cap').value),
491
+ override_amount: (amtVal !== '' && amtVal != null) ? Number(amtVal) : null
492
+ };
493
 
494
  try {
495
+ const res = await fetch(`${API_BASE}/api/futures-config`, {
496
+ method: 'POST',
497
+ headers: { 'Content-Type': 'application/json' },
498
+ body: JSON.stringify(payload)
499
+ });
500
+ if (res.ok) {
501
+ msg.textContent = '✓ saved';
502
+ msg.style.color = '#4ade80';
503
+ } else {
504
+ msg.textContent = '❌ save failed';
505
+ msg.style.color = '#f87171';
506
+ }
507
  } catch (err) {
508
+ msg.textContent = '❌ ' + err.message;
509
+ msg.style.color = '#f87171';
510
  } finally {
511
  btn.disabled = false;
512
  btn.innerHTML = original;
513
  }
514
+ }
515
+
516
+ document.getElementById('futures-save-btn').addEventListener('click', saveFuturesSettings);
517
 
518
+ // Rising Coins Trading Settings
519
+ async function loadRiserSettings() {
520
+ try {
521
+ const res = await fetch(`${API_BASE}/api/riser-config`);
522
+ const s = await res.json();
523
+ if (s.amount != null) document.getElementById('r-amt').value = s.amount;
524
+ if (s.leverage != null) document.getElementById('r-lev').value = s.leverage;
525
+ if (s.tp_percent != null) document.getElementById('r-tp').value = s.tp_percent;
526
+ if (s.stop_loss_percent != null) document.getElementById('r-sl').value = s.stop_loss_percent;
527
+ if (s.daily_cap != null) document.getElementById('r-cap').value = s.daily_cap;
528
+ if (s.min_funding != null) document.getElementById('r-fund').value = s.min_funding;
529
+ } catch (err) {
530
+ // riser settings unavailable — leave defaults
531
+ }
532
+ }
533
 
534
+ async function saveRiserSettings() {
535
+ const btn = document.getElementById('riser-save-btn');
536
+ const msg = document.getElementById('riser-msg');
537
  const original = btn.innerHTML;
538
  btn.disabled = true;
539
+ btn.innerHTML = '<span class="spinner"></span>Saving...';
540
+
541
+ const payload = {
542
+ amount: Number(document.getElementById('r-amt').value),
543
+ leverage: Number(document.getElementById('r-lev').value),
544
+ tp_percent: Number(document.getElementById('r-tp').value),
545
+ stop_loss_percent: Number(document.getElementById('r-sl').value),
546
+ daily_cap: Number(document.getElementById('r-cap').value),
547
+ min_funding: Number(document.getElementById('r-fund').value)
548
+ };
549
 
550
  try {
551
+ const res = await fetch(`${API_BASE}/api/riser-config`, {
552
+ method: 'POST',
553
+ headers: { 'Content-Type': 'application/json' },
554
+ body: JSON.stringify(payload)
555
+ });
556
+ if (res.ok) {
557
+ msg.textContent = '✓ saved';
558
+ msg.style.color = '#4ade80';
559
+ } else {
560
+ msg.textContent = '❌ save failed (admin only)';
561
+ msg.style.color = '#f87171';
562
+ }
563
  } catch (err) {
564
+ msg.textContent = '❌ ' + err.message;
565
+ msg.style.color = '#f87171';
566
  } finally {
567
  btn.disabled = false;
568
  btn.innerHTML = original;
569
  }
570
+ }
571
+
572
+ document.getElementById('riser-save-btn').addEventListener('click', saveRiserSettings);
573
+
574
+ // View-only enforcement: hide write controls for non-admin users
575
+ async function applyAccess() {
576
+ try {
577
+ const res = await fetch(`${API_BASE}/api/whoami`);
578
+ const w = await res.json();
579
+ if (w.logged_in && w.role !== 'admin') {
580
+ ['grid-save-btn', 'futures-save-btn', 'riser-save-btn'].forEach(id => {
581
+ const b = document.getElementById(id);
582
+ if (b) b.style.display = 'none';
583
+ });
584
+ const note = document.getElementById('access-note');
585
+ if (note) note.style.display = 'block';
586
+ }
587
+ } catch (err) {}
588
+ }
589
 
590
  // Initial load
591
+ loadGridSettings();
592
+ loadFuturesSettings();
593
+ loadRiserSettings();
594
+ applyAccess();
595
  </script>
596
  <script src="/css/nav.js"></script>
597
+ <!--Start of Tawk.to Script-->
598
+ <script type="text/javascript">
599
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
600
+ (function(){
601
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
602
+ s1.async=true;
603
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
604
+ s1.charset='UTF-8';
605
+ s1.setAttribute('crossorigin','*');
606
+ s0.parentNode.insertBefore(s1,s0);
607
+ })();
608
+ </script>
609
+ <!--End of Tawk.to Script-->
610
  </body>
611
  </html>
static/sideways/index.html ADDED
@@ -0,0 +1,523 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Sideways Market — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <link rel="stylesheet" href="/static/help.css">
9
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
10
+ <style>
11
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
12
+ .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
13
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
14
+ .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
15
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
16
+ .breadcrumbs .bc-current { color: #e6edf3; }
17
+ @media (max-width: 640px) { .breadcrumbs { display: none; } }
18
+
19
+ .section-title { text-align: center; font-size: 30px; font-weight: 700; color: #f0b90b; margin: 8px 0 10px; letter-spacing: 0.5px; }
20
+ .page-subtitle { font-size: 14px; color: #8b949e; margin-bottom: 24px; text-align: center; }
21
+ .market-nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin: 0 0 24px; }
22
+ .market-nav-btn {
23
+ display: inline-block;
24
+ padding: 10px 22px;
25
+ background: #f0b90b;
26
+ color: #0d1117;
27
+ border-radius: 8px;
28
+ font-weight: 700;
29
+ font-size: 14px;
30
+ text-decoration: none;
31
+ transition: opacity 0.15s;
32
+ }
33
+ .market-nav-btn:hover { opacity: 0.85; }
34
+ .market-nav-btn.active { box-shadow: 0 0 0 2px #0d1117, 0 0 0 4px #ffffff; }
35
+
36
+ /* ---------- Grid tables ---------- */
37
+ .grid-section { margin-bottom: 32px; }
38
+ .grid-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
39
+ .table-wrap { overflow-x: auto; background: #1e2329; border: 2px solid #30363d; border-radius: 12px; }
40
+ .grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
41
+ .grid-table th { text-align: right; padding: 10px 12px; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 13px; font-weight: 400; border-bottom: 1px solid #30363d; white-space: nowrap; }
42
+ .grid-table th:first-child { text-align: left; }
43
+ .grid-table td { padding: 10px 12px; border-bottom: 1px solid #21262d; text-align: right; font-family: 'SF Mono', Monaco, monospace; white-space: nowrap; }
44
+ .grid-table td:first-child { text-align: left; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
45
+ .grid-table th.center, .grid-table td.center { text-align: center; }
46
+ .grid-table tr:last-child td { border-bottom: none; }
47
+ .grid-table tbody tr:hover { background: #161b22; }
48
+ .grid-table tfoot td { border-top: 2px solid #30363d; border-bottom: none; font-weight: 700; background: #161b22; }
49
+
50
+ th.sortable { cursor: pointer; user-select: none; }
51
+ th.sortable:hover { color: #f0b90b; }
52
+ .srt { margin-left: 5px; font-size: 10px; color: #8b949e; }
53
+ th.sorted-asc, th.sorted-desc { color: #f0b90b; }
54
+ th.sorted-asc .srt, th.sorted-desc .srt { color: #f0b90b; }
55
+ .srt-btn { background: transparent; border: 1px solid #30363d; color: #8b949e; cursor: pointer; font-size: 10px; padding: 1px 3px; margin-left: 2px; line-height: 1; border-radius: 3px; font-family: inherit; }
56
+ .srt-btn:hover { color: #f0b90b; border-color: #f0b90b; }
57
+ .srt-btn.active { color: #0d1117; background: #f0b90b; border-color: #f0b90b; font-weight: 700; }
58
+
59
+ .view-btn {
60
+ display: inline-block;
61
+ padding: 5px 10px;
62
+ border-radius: 6px;
63
+ font-weight: 700;
64
+ font-size: 12px;
65
+ text-decoration: none;
66
+ background: #6c8cff;
67
+ color: #fff;
68
+ white-space: nowrap;
69
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
70
+ }
71
+ .view-btn:hover { opacity: 0.85; }
72
+
73
+ .open-all-btn {
74
+ display: inline-block;
75
+ padding: 5px 10px;
76
+ border-radius: 6px;
77
+ font-weight: 700;
78
+ font-size: 12px;
79
+ background: #4ade80;
80
+ color: #fff;
81
+ border: none;
82
+ cursor: pointer;
83
+ white-space: nowrap;
84
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
85
+ }
86
+ .open-all-btn:hover { opacity: 0.85; }
87
+
88
+ .pos { color: #4ade80; }
89
+ .neg { color: #f87171; }
90
+ .mut { color: #8b949e; }
91
+ .muted { color: #8b949e; text-align: center !important; }
92
+ .btc-section { margin-bottom: 32px; }
93
+ .btc-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
94
+ .btc-card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 16px 18px; }
95
+ .btc-change { text-align: center; font-size: 14px; color: #e6edf3; margin-bottom: 8px; }
96
+ .btc-chart { width: 100%; }
97
+ </style>
98
+ </head>
99
+ <body>
100
+ <nav class="nav-bar">
101
+ <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
102
+ <div class="nav-links">
103
+ <a href="/scan/" class="nav-link">🔍 Scan</a>
104
+ <a href="/price/" class="nav-link">💵 ETH Price</a>
105
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
106
+ </div>
107
+ </nav>
108
+
109
+ <div class="page-content">
110
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Sideways Market</span></div>
111
+
112
+ <div class="market-nav">
113
+ <a class="market-nav-btn" href="/upward">Upward Markets</a>
114
+ <a class="market-nav-btn active" href="/sideways">Sideways Markets</a>
115
+ <a class="market-nav-btn" href="/downward">Downward Markets</a>
116
+ </div>
117
+
118
+ <h1 class="section-title">Tools for Sideways Markets</h1>
119
+ <p class="page-subtitle">↔️ Sideways Market — range-bound strategies when price chops sideways.</p>
120
+
121
+ <section class="btc-section">
122
+ <h2 class="btc-h2">BTC Spot Price · Last 7 Days</h2>
123
+ <div class="btc-card">
124
+ <div class="btc-change" data-btc-change>Loading…</div>
125
+ <div class="btc-chart" data-btc-chart></div>
126
+ </div>
127
+ </section>
128
+
129
+ <!-- Running Grids -->
130
+ <section class="grid-section">
131
+ <h2 class="grid-h2">🟢 Active Grids</h2>
132
+ <div class="table-wrap">
133
+ <table class="grid-table">
134
+ <thead><tr>
135
+ <th class="sortable" data-table="running" data-key="symbol">Symbol<span class="srt">↕</span></th>
136
+ <th class="sortable center" data-table="running" data-key="lev">Lev<span class="srt">↕</span></th>
137
+ <th class="sortable" data-table="running" data-key="invested">Invested<span class="srt">↕</span></th>
138
+ <th class="sortable" data-table="running" data-key="grid_profit">Grid Profit<span class="srt">↕</span></th>
139
+ <th class="sortable" data-table="running" data-key="realised">Realized<span class="srt">↕</span></th>
140
+ <th class="sortable" data-table="running" data-key="pnl">Total P&amp;L<span class="srt">↕</span></th>
141
+ <th class="sortable" data-table="running" data-key="duration">Duration<span class="srt">↕</span></th>
142
+ <th><button type="button" id="open-all-btn" class="open-all-btn">Open All</button></th>
143
+ </tr></thead>
144
+ <tbody id="running-tbody"><tr><td colspan="8" class="muted">Loading…</td></tr></tbody>
145
+ <tfoot>
146
+ <tr>
147
+ <td colspan="2">Totals</td>
148
+ <td class="mut" id="tot-invested">—</td>
149
+ <td id="tot-gridprofit">—</td>
150
+ <td id="tot-realised">—</td>
151
+ <td id="tot-pnl">—</td>
152
+ <td></td>
153
+ <td></td>
154
+ </tr>
155
+ </tfoot>
156
+ </table>
157
+ </div>
158
+ </section>
159
+
160
+ <!-- Grid Opportunities -->
161
+ <section class="grid-section">
162
+ <h2 class="grid-h2">🟡 Grid Opportunities</h2>
163
+ <div class="table-wrap">
164
+ <table class="grid-table">
165
+ <thead><tr>
166
+ <th class="sortable" data-table="opps" data-key="rank">#<span class="srt">↕</span></th>
167
+ <th class="sortable" data-table="opps" data-key="symbol">Symbol<span class="srt">↕</span></th>
168
+ <th class="sortable" data-table="opps" data-key="width">Width %<span class="srt">↕</span></th>
169
+ <th class="sortable" data-table="opps" data-key="w24">24h %<span class="srt">↕</span></th>
170
+ <th class="sortable" data-table="opps" data-key="touches">Touches<span class="srt">↕</span></th>
171
+ <th class="sortable" data-table="opps" data-key="drift">Drift %<span class="srt">↕</span></th>
172
+ <th class="sortable" data-table="opps" data-key="adx">ADX<span class="srt">↕</span></th>
173
+ <th class="sortable" data-table="opps" data-key="replay">Backtest 7d<span class="srt">↕</span></th>
174
+ <th class="sortable" data-table="opps" data-key="maxdd">Max DD<span class="srt">↕</span></th>
175
+ <th class="sortable" data-table="opps" data-key="score">Score<span class="srt">↕</span></th>
176
+ </tr></thead>
177
+ <tbody id="opp-tbody"><tr><td colspan="11" class="muted">Loading…</td></tr></tbody>
178
+ </table>
179
+ </div>
180
+ </section>
181
+
182
+ <!-- Archived Grids -->
183
+ <section class="grid-section">
184
+ <h2 class="grid-h2">⚪ Archived Grids</h2>
185
+ <div class="table-wrap">
186
+ <table class="grid-table">
187
+ <thead><tr>
188
+ <th class="sortable" data-table="archiv" data-key="symbol">Symbol<span class="srt">↕</span></th>
189
+ <th class="sortable center" data-table="archiv" data-key="lev">Lev<span class="srt">↕</span></th>
190
+ <th class="sortable" data-table="archiv" data-key="invested">Invested<span class="srt">↕</span></th>
191
+ <th class="sortable" data-table="archiv" data-key="grid_profit">Grid Profit<span class="srt">↕</span></th>
192
+ <th class="sortable" data-table="archiv" data-key="realised">Realized<span class="srt">↕</span></th>
193
+ <th class="sortable" data-table="archiv" data-key="pnl">Total P&amp;L<span class="srt">↕</span></th>
194
+ <th class="sortable" data-table="archiv" data-key="archived">Archived<span class="srt">↕</span></th>
195
+ </tr></thead>
196
+ <tbody id="archived-tbody"><tr><td colspan="7" class="muted">Loading…</td></tr></tbody>
197
+ </table>
198
+ </div>
199
+ </section>
200
+ </div>
201
+
202
+ <script src="/css/nav.js"></script>
203
+ <script src="/static/btc-chart.js"></script>
204
+ <script>
205
+ function num0(v) {
206
+ var n = Number(v);
207
+ return (v === null || v === undefined || v === '' || isNaN(n)) ? 0 : n;
208
+ }
209
+ function fmt(n) {
210
+ if (n === null || n === undefined || n === '' || (typeof n === 'number' && isNaN(n))) return '—';
211
+ return Number(n).toLocaleString(undefined, { maximumFractionDigits: 4 });
212
+ }
213
+ function money(n) {
214
+ if (n === null || n === undefined || n === '' || (typeof n === 'number' && isNaN(n))) return '—';
215
+ var v = Number(n);
216
+ return (v < 0 ? '-' : '') + '$' + Math.abs(v).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
217
+ }
218
+ function pnlCls(n) {
219
+ if (n === null || n === undefined || n === '' || (typeof n === 'number' && isNaN(n))) return 'mut';
220
+ var v = Number(n);
221
+ if (v > 0) return 'pos';
222
+ if (v < 0) return 'neg';
223
+ return 'mut';
224
+ }
225
+
226
+ function pctSuffix(pnl, invested) {
227
+ var p = num0(pnl), inv = num0(invested);
228
+ if (inv <= 0) return '';
229
+ var pct = p / inv * 100;
230
+ return ' <span class="mut">(' + (pct > 0 ? '+' : '') + pct.toFixed(1) + '%)</span>';
231
+ }
232
+
233
+ var DATA = { running: [], opps: [], archiv: [] };
234
+ var SORT = { running: { key: 'pnl', dir: -1 }, opps: { key: null, dir: 1 }, archiv: { key: null, dir: 1 } };
235
+ var IS_ADMIN = false;
236
+
237
+ var KEYS = {
238
+ running: {
239
+ symbol: function (b) { return b.symbol || ''; },
240
+ lev: function (b) { return Number(b.leverage || 1); },
241
+ invested: function (b) { return num0(b.invested != null && b.invested !== '' ? b.invested : b.total_investment); },
242
+ grid_profit: function (b) { return num0(b.grid_profit); },
243
+ realised: function (b) { return num0(b.realised_pnl); },
244
+ pnl: function (b) {
245
+ var inv = num0(b.invested != null && b.invested !== '' ? b.invested : b.total_investment);
246
+ var p = num0(b.pnl);
247
+ return inv > 0 ? (p / inv * 100) : 0;
248
+ },
249
+ duration: function (b) { return durationMs(b); }
250
+ },
251
+ opps: {
252
+ rank: function (c) { return num0(c.rank); },
253
+ symbol: function (c) { return c.symbol || ''; },
254
+ width: function (c) { return num0(c.width); },
255
+ w24: function (c) { return num0(c.w24); },
256
+ touches: function (c) { return num0(c.touches); },
257
+ drift: function (c) { return num0(c.drift); },
258
+ adx: function (c) { return num0(c.adx); },
259
+ atr: function (c) { return num0(c.atr); },
260
+ replay: function (c) { return c.replay_total == null ? -Infinity : Number(c.replay_total); },
261
+ maxdd: function (c) { return c.replay_max_dd == null ? -Infinity : Number(c.replay_max_dd); },
262
+ score: function (c) { return num0(c.score); }
263
+ },
264
+ archiv: {
265
+ symbol: function (b) { return b.symbol || ''; },
266
+ lev: function (b) { return Number(b.leverage || 1); },
267
+ invested: function (b) { return num0(b.invested); },
268
+ grid_profit: function (b) { return num0(b.grid_profit); },
269
+ realised: function (b) { return num0(b.realised_pnl); },
270
+ pnl: function (b) { return num0(b.pnl); },
271
+ archived: function (b) { return num0(b.archived_ms); }
272
+ }
273
+ };
274
+
275
+ function sortedList(t) {
276
+ var st = SORT[t];
277
+ var arr = DATA[t];
278
+ if (!st.key) return arr;
279
+ var fn = KEYS[t][st.key];
280
+ if (!fn) return arr;
281
+ return arr.slice().sort(function (a, b) {
282
+ var va = fn(a), vb = fn(b);
283
+ var c;
284
+ if (typeof va === 'number' && typeof vb === 'number') c = va - vb;
285
+ else c = String(va).toLowerCase() < String(vb).toLowerCase() ? -1 : (String(va).toLowerCase() > String(vb).toLowerCase() ? 1 : 0);
286
+ return c * st.dir;
287
+ });
288
+ }
289
+
290
+ var FIRST_SEEN = {};
291
+ function durationMs(b) {
292
+ if (b && b.opened_ms) {
293
+ var ms = Number(b.opened_ms);
294
+ if (ms) return Date.now() - ms;
295
+ }
296
+ var id = b && b.bot_id;
297
+ if (!id) return null;
298
+ if (!FIRST_SEEN[id]) FIRST_SEEN[id] = Date.now();
299
+ return Date.now() - FIRST_SEEN[id];
300
+ }
301
+ function fmtDuration(ms) {
302
+ if (ms === null || ms === undefined || isNaN(ms) || ms < 0) return '—';
303
+ var s = Math.floor(ms / 1000);
304
+ var d = Math.floor(s / 86400); s -= d * 86400;
305
+ var h = Math.floor(s / 3600); s -= h * 3600;
306
+ var m = Math.floor(s / 60);
307
+ if (d > 0) return d + 'd ' + h + 'h';
308
+ if (h > 0) return h + 'h ' + m + 'm';
309
+ if (m > 0) return m + 'm';
310
+ return s + 's';
311
+ }
312
+
313
+ function viewBtn(botId) {
314
+ return '<a class="view-btn" href="https://scan.blind-monkeys.com/grid/chart?bot_id=' + encodeURIComponent(botId) + '" target="_blank" rel="noopener">View Grid</a>';
315
+ }
316
+
317
+ function renderRunningBody() {
318
+ var tb = document.getElementById('running-tbody');
319
+ var bots = sortedList('running');
320
+ if (!bots.length) { tb.innerHTML = '<tr><td colspan="8" class="muted">No running grid bots.</td></tr>'; return; }
321
+ tb.innerHTML = bots.map(function (b) {
322
+ var lev = b.leverage || 1;
323
+ var invested = (b.invested != null && b.invested !== '') ? b.invested : (b.total_investment || 0);
324
+ return '<tr>'
325
+ + '<td>' + b.symbol + '</td>'
326
+ + '<td class="center">' + lev + 'x</td>'
327
+ + '<td class="mut">' + money(invested) + '</td>'
328
+ + '<td class="' + pnlCls(b.grid_profit) + '">' + money(b.grid_profit) + '</td>'
329
+ + '<td class="' + pnlCls(b.realised_pnl) + '">' + money(b.realised_pnl) + '</td>'
330
+ + '<td class="' + pnlCls(b.pnl) + '">' + money(b.pnl) + pctSuffix(b.pnl, invested) + '</td>'
331
+ + '<td class="mut">' + fmtDuration(durationMs(b)) + '</td>'
332
+ + '<td>' + viewBtn(b.bot_id) + '</td>'
333
+ + '</tr>';
334
+ }).join('');
335
+ renderRunningTotals();
336
+ }
337
+
338
+ function renderRunningTotals() {
339
+ var bots = DATA.running;
340
+ var sum = function (fn) { return bots.reduce(function (a, b) { return a + fn(b); }, 0); };
341
+ var invEl = document.getElementById('tot-invested');
342
+ invEl.textContent = money(sum(KEYS.running.invested));
343
+ invEl.className = 'mut';
344
+ function set(id, v) {
345
+ var el = document.getElementById(id);
346
+ el.textContent = money(v);
347
+ el.className = pnlCls(v);
348
+ }
349
+ set('tot-gridprofit', sum(function (b) { return num0(b.grid_profit); }));
350
+ set('tot-realised', sum(function (b) { return num0(b.realised_pnl); }));
351
+ set('tot-pnl', sum(function (b) { return num0(b.pnl); }));
352
+ }
353
+
354
+ function renderOppsBody() {
355
+ var tb = document.getElementById('opp-tbody');
356
+ var cands = sortedList('opps');
357
+ if (!cands.length) { tb.innerHTML = '<tr><td colspan="11" class="muted">No range-bound candidates found.</td></tr>'; return; }
358
+ tb.innerHTML = cands.map(function (c) {
359
+ var btCell, ddCell;
360
+ if (c.replay_total == null) { btCell = '<span class="mut">—</span>'; }
361
+ else if (c.replay_stopped) {
362
+ var t = Number(c.replay_total);
363
+ btCell = '<span style="color:#f87171;font-weight:700;">SL ' + t.toFixed(2) + '%</span>';
364
+ }
365
+ else {
366
+ var t = Number(c.replay_total);
367
+ var col = t >= 1 ? '#4ade80' : (t >= 0 ? '#f0b90b' : '#f87171');
368
+ btCell = '<span style="color:' + col + ';font-weight:700;">' + (t >= 0 ? '+' : '') + t.toFixed(2) + '%</span>';
369
+ }
370
+ if (c.replay_max_dd == null) { ddCell = '<span class="mut">—</span>'; }
371
+ else {
372
+ var d = Number(c.replay_max_dd);
373
+ var dcol = d >= -1 ? '#4ade80' : (d >= -3 ? '#f0b90b' : '#f87171');
374
+ ddCell = '<span style="color:' + dcol + ';font-weight:700;">' + d.toFixed(2) + '%</span>';
375
+ }
376
+ return '<tr>'
377
+ + '<td class="mut">' + c.rank + '</td>'
378
+ + '<td>' + c.symbol + '</td>'
379
+ + '<td>' + Number(c.width).toFixed(2) + '%</td>'
380
+ + '<td>' + Number(c.w24).toFixed(2) + '%</td>'
381
+ + '<td>' + c.touches + '</td>'
382
+ + '<td>' + Number(c.drift).toFixed(2) + '%</td>'
383
+ + '<td>' + Number(c.adx).toFixed(1) + '</td>'
384
+ + '<td>' + Number(c.atr).toFixed(2) + '%</td>'
385
+ + '<td>' + btCell + '</td>'
386
+ + '<td>' + ddCell + '</td>'
387
+ + '<td class="mut">' + Number(c.score).toFixed(1) + '</td>'
388
+ + '</tr>';
389
+ }).join('');
390
+ }
391
+
392
+ function renderArchivBody() {
393
+ var tb = document.getElementById('archived-tbody');
394
+ var list = sortedList('archiv');
395
+ if (!list.length) { tb.innerHTML = '<tr><td colspan="7" class="muted">No archived grid bots.</td></tr>'; return; }
396
+ tb.innerHTML = list.map(function (b) {
397
+ var lev = b.leverage || 1;
398
+ var invested = b.invested || 0;
399
+ var date = b.archived_ms ? new Date(Number(b.archived_ms)).toLocaleDateString() : '—';
400
+ return '<tr>'
401
+ + '<td>' + b.symbol + '</td>'
402
+ + '<td class="center">' + lev + 'x</td>'
403
+ + '<td class="mut">' + money(invested) + '</td>'
404
+ + '<td class="' + pnlCls(b.grid_profit) + '">' + money(b.grid_profit) + '</td>'
405
+ + '<td class="' + pnlCls(b.realised_pnl) + '">' + money(b.realised_pnl) + '</td>'
406
+ + '<td class="' + pnlCls(b.pnl) + '">' + money(b.pnl) + pctSuffix(b.pnl, invested) + '</td>'
407
+ + '<td class="mut">' + date + '</td>'
408
+ + '</tr>';
409
+ }).join('');
410
+ }
411
+
412
+ function renderTable(t) {
413
+ if (t === 'running') renderRunningBody();
414
+ else if (t === 'opps') renderOppsBody();
415
+ else if (t === 'archiv') renderArchivBody();
416
+ }
417
+
418
+ function updateSortUI(t) {
419
+ var st = SORT[t];
420
+ document.querySelectorAll('th[data-table="' + t + '"]').forEach(function (th) {
421
+ th.classList.remove('sorted-asc', 'sorted-desc');
422
+ th.querySelectorAll('.srt-btn').forEach(function (b) { b.classList.remove('active'); });
423
+ });
424
+ if (st.key) {
425
+ var active = document.querySelector('th[data-table="' + t + '"][data-key="' + st.key + '"]');
426
+ if (active) {
427
+ active.classList.add(st.dir === 1 ? 'sorted-asc' : 'sorted-desc');
428
+ var btn = active.querySelector('.srt-btn[data-dir="' + (st.dir === 1 ? 'asc' : 'desc') + '"]');
429
+ if (btn) btn.classList.add('active');
430
+ }
431
+ }
432
+ }
433
+
434
+ function applySort(th, dir) {
435
+ var t = th.getAttribute('data-table');
436
+ var key = th.getAttribute('data-key');
437
+ SORT[t].key = key;
438
+ SORT[t].dir = dir;
439
+ renderTable(t);
440
+ updateSortUI(t);
441
+ }
442
+
443
+ function setupSortButtons() {
444
+ document.querySelectorAll('th.sortable').forEach(function (th) {
445
+ var span = th.querySelector('.srt');
446
+ if (!span) return;
447
+ span.textContent = '';
448
+ var asc = document.createElement('button');
449
+ asc.type = 'button';
450
+ asc.className = 'srt-btn';
451
+ asc.setAttribute('data-dir', 'asc');
452
+ asc.textContent = '▲';
453
+ asc.title = 'Sort ascending';
454
+ var desc = document.createElement('button');
455
+ desc.type = 'button';
456
+ desc.className = 'srt-btn';
457
+ desc.setAttribute('data-dir', 'desc');
458
+ desc.textContent = '▼';
459
+ desc.title = 'Sort descending';
460
+ span.appendChild(asc);
461
+ span.appendChild(desc);
462
+ asc.addEventListener('click', function (e) { e.stopPropagation(); applySort(th, 1); });
463
+ desc.addEventListener('click', function (e) { e.stopPropagation(); applySort(th, -1); });
464
+ });
465
+ }
466
+
467
+ function fetchJSON(url, cb) {
468
+ fetch(url).then(function (r) {
469
+ if (!r.ok) throw new Error('HTTP ' + r.status);
470
+ return r.json();
471
+ }).then(cb).catch(function () {});
472
+ }
473
+
474
+ function loadAll() {
475
+ fetchJSON('/api/grid-bots', function (bots) {
476
+ // Running Grids shows only live bots; completed/stopped bots keep
477
+ // their final Bybit P&L frozen (e.g. a closed bot stuck at +$3.08),
478
+ // which would pollute the table and the totals row.
479
+ DATA.running = (bots || []).filter(function (b) {
480
+ return b.status === 'FUTURE_GRID_STATUS_RUNNING' ||
481
+ b.status === 'FUTURE_GRID_STATUS_PAUSED';
482
+ });
483
+ renderTable('running');
484
+ updateSortUI('running');
485
+ });
486
+ fetchJSON('/api/grid-candidates', function (cands) {
487
+ DATA.opps = (cands && cands.length) ? cands : [];
488
+ renderTable('opps');
489
+ });
490
+ fetchJSON('/api/grid-archived', function (list) {
491
+ DATA.archiv = (list && list.length) ? list : [];
492
+ renderTable('archiv');
493
+ });
494
+ }
495
+
496
+ function openAllGrids() {
497
+ var bots = DATA.running;
498
+ if (!bots.length) return;
499
+ bots.forEach(function (b) {
500
+ if (b.bot_id) window.open('https://scan.blind-monkeys.com/grid/chart?bot_id=' + encodeURIComponent(b.bot_id), '_blank');
501
+ });
502
+ }
503
+ document.getElementById('open-all-btn').addEventListener('click', openAllGrids);
504
+
505
+ setupSortButtons();
506
+ loadAll();
507
+ setInterval(loadAll, 90000);
508
+ </script>
509
+ <!--Start of Tawk.to Script-->
510
+ <script type="text/javascript">
511
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
512
+ (function(){
513
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
514
+ s1.async=true;
515
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
516
+ s1.charset='UTF-8';
517
+ s1.setAttribute('crossorigin','*');
518
+ s0.parentNode.insertBefore(s1,s0);
519
+ })();
520
+ </script>
521
+ <!--End of Tawk.to Script-->
522
+ </body>
523
+ </html>
static/upward/index.html ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Upward Market — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <link rel="stylesheet" href="/static/help.css">
9
+ <link rel="stylesheet" href="/static/scan-widget.css">
10
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
11
+ <style>
12
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
13
+ .breadcrumbs { margin: 0 0 14px 0; font-size: 13px; color: #8b949e; }
14
+ .breadcrumbs a { color: #8b949e; text-decoration: none; }
15
+ .breadcrumbs a:hover { color: #f0b90b; text-decoration: underline; }
16
+ .breadcrumbs .bc-sep { margin: 0 6px; color: #484f58; }
17
+ .breadcrumbs .bc-current { color: #e6edf3; }
18
+ @media (max-width: 640px) { .breadcrumbs { display: none; } }
19
+
20
+ .section-title { text-align: center; font-size: 30px; font-weight: 700; color: #f0b90b; margin: 8px 0 10px; letter-spacing: 0.5px; }
21
+ .page-subtitle { font-size: 14px; color: #8b949e; margin-bottom: 24px; text-align: center; }
22
+ .market-nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin: 0 0 24px; }
23
+ .market-nav-btn {
24
+ display: inline-block;
25
+ padding: 10px 22px;
26
+ background: #f0b90b;
27
+ color: #0d1117;
28
+ border-radius: 8px;
29
+ font-weight: 700;
30
+ font-size: 14px;
31
+ text-decoration: none;
32
+ transition: opacity 0.15s;
33
+ }
34
+ .market-nav-btn:hover { opacity: 0.85; }
35
+ .market-nav-btn.active { box-shadow: 0 0 0 2px #0d1117, 0 0 0 4px #ffffff; }
36
+ .placeholder {
37
+ background: #1e2329;
38
+ border: 2px solid #30363d;
39
+ border-radius: 12px;
40
+ padding: 40px 24px;
41
+ text-align: center;
42
+ color: #8b949e;
43
+ font-size: 14px;
44
+ }
45
+ .pos { color: #4ade80; }
46
+ .neg { color: #f87171; }
47
+ .mut { color: #8b949e; }
48
+ .muted { color: #8b949e; }
49
+ .btc-section { margin-bottom: 32px; }
50
+ .btc-h2 { text-align: center; font-size: 20px; font-weight: 700; color: #f0b90b; margin: 0 0 14px; }
51
+ .btc-card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 16px 18px; }
52
+ .btc-change { text-align: center; font-size: 14px; color: #e6edf3; margin-bottom: 8px; }
53
+ .btc-chart { width: 100%; }
54
+ </style>
55
+ </head>
56
+ <body>
57
+ <nav class="nav-bar">
58
+ <a href="/" class="nav-brand">🙈 Blind Monkeys</a>
59
+ <div class="nav-links">
60
+ <a href="/scan/" class="nav-link">🔍 Scan</a>
61
+ <a href="/price/" class="nav-link">💵 ETH Price</a>
62
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
63
+ </div>
64
+ </nav>
65
+
66
+ <div class="page-content">
67
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Upward Market</span></div>
68
+
69
+ <div class="market-nav">
70
+ <a class="market-nav-btn active" href="/upward">Upward Markets</a>
71
+ <a class="market-nav-btn" href="/sideways">Sideways Markets</a>
72
+ <a class="market-nav-btn" href="/downward">Downward Markets</a>
73
+ </div>
74
+
75
+ <h1 class="section-title">Tools for Upward Markets</h1>
76
+ <p class="page-subtitle">📈 Upward Market — riding momentum when the market is trending higher.</p>
77
+
78
+ <section class="btc-section">
79
+ <h2 class="btc-h2">BTC Spot Price · Last 7 Days</h2>
80
+ <div class="btc-card">
81
+ <div class="btc-change" data-btc-change>Loading…</div>
82
+ <div class="btc-chart" data-btc-chart></div>
83
+ </div>
84
+ </section>
85
+
86
+ <section class="scan-embed">
87
+ <h2 class="scan-h2">🔍 Coin Scan</h2>
88
+ <div style="background:#1e2329;border:2px solid #30363d;border-radius:12px;padding:20px 18px;">
89
+ <div class="scan-line">
90
+ <div class="scan-field">
91
+ <label>💵 Planned Invest</label>
92
+ <input type="text" id="sw-investment" placeholder="$10,000" inputmode="numeric" autocomplete="off">
93
+ </div>
94
+ <div class="scan-field">
95
+ <label>📊 ATR Multiplier</label>
96
+ <select id="sw-atr">
97
+ <option value="2" selected>2× (default)</option>
98
+ <option value="3">3×</option>
99
+ </select>
100
+ </div>
101
+ <div class="scan-tabs" id="sw-tabs">
102
+ <button class="scan-tab active" data-mode="conservative">🛡️ Conservative</button>
103
+ <button class="scan-tab risk" data-mode="risk">🎲 Risk Taker</button>
104
+ </div>
105
+ <button class="btn btn-primary" id="sw-run">🔄 Run Scan</button>
106
+ </div>
107
+ <div id="sw-progress" class="scan-progress" style="display:none;">
108
+ <div class="scan-spinner"></div>
109
+ <span id="sw-status" style="font-size:13px;color:#8b949e;">Scanning…</span>
110
+ <span id="sw-timer" style="font-family:'SF Mono',Monaco,monospace;font-weight:700;">00:00</span>
111
+ </div>
112
+ <div id="sw-results" style="margin-top:16px;color:#8b949e;">Click "Run Scan" to begin…</div>
113
+ </div>
114
+ </section>
115
+ </div>
116
+
117
+ <script src="/css/nav.js"></script>
118
+ <script src="/static/btc-chart.js"></script>
119
+ <script src="/static/scan-widget.js"></script>
120
+ <!--Start of Tawk.to Script-->
121
+ <script type="text/javascript">
122
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
123
+ (function(){
124
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
125
+ s1.async=true;
126
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
127
+ s1.charset='UTF-8';
128
+ s1.setAttribute('crossorigin','*');
129
+ s0.parentNode.insertBefore(s1,s0);
130
+ })();
131
+ </script>
132
+ <!--End of Tawk.to Script-->
133
+ </body>
134
+ </html>
templates/about.html CHANGED
@@ -150,5 +150,18 @@
150
  </div>
151
 
152
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  </body>
154
  </html>
 
150
  </div>
151
 
152
  <script src="/css/nav.js"></script>
153
+ <!--Start of Tawk.to Script-->
154
+ <script type="text/javascript">
155
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
156
+ (function(){
157
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
158
+ s1.async=true;
159
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
160
+ s1.charset='UTF-8';
161
+ s1.setAttribute('crossorigin','*');
162
+ s0.parentNode.insertBefore(s1,s0);
163
+ })();
164
+ </script>
165
+ <!--End of Tawk.to Script-->
166
  </body>
167
  </html>
templates/admin_alerts.html CHANGED
@@ -123,5 +123,18 @@
123
  })();
124
  </script>
125
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  </body>
127
  </html>
 
123
  })();
124
  </script>
125
  <script src="/css/nav.js"></script>
126
+ <!--Start of Tawk.to Script-->
127
+ <script type="text/javascript">
128
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
129
+ (function(){
130
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
131
+ s1.async=true;
132
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
133
+ s1.charset='UTF-8';
134
+ s1.setAttribute('crossorigin','*');
135
+ s0.parentNode.insertBefore(s1,s0);
136
+ })();
137
+ </script>
138
+ <!--End of Tawk.to Script-->
139
  </body>
140
  </html>
templates/admin_cron.html CHANGED
@@ -244,5 +244,18 @@
244
 
245
 
246
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  </body>
248
  </html>
 
244
 
245
 
246
  <script src="/css/nav.js"></script>
247
+ <!--Start of Tawk.to Script-->
248
+ <script type="text/javascript">
249
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
250
+ (function(){
251
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
252
+ s1.async=true;
253
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
254
+ s1.charset='UTF-8';
255
+ s1.setAttribute('crossorigin','*');
256
+ s0.parentNode.insertBefore(s1,s0);
257
+ })();
258
+ </script>
259
+ <!--End of Tawk.to Script-->
260
  </body>
261
  </html>
templates/admin_home.html ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Admin — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <style>
9
+ * { box-sizing: border-box; }
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
11
+ .page-content { max-width: 800px; margin: 0 auto; padding: 32px 20px; }
12
+ h1 { font-size: 24px; margin: 0 0 4px; }
13
+ .sub { color: #8b949e; font-size: 14px; margin-bottom: 24px; }
14
+ .tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
15
+ .tool { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; text-decoration: none; color: #e6edf3; transition: transform .15s ease, border-color .15s ease; }
16
+ .tool:hover { transform: translateY(-2px); border-color: #f0b90b; }
17
+ .tool .ico { font-size: 28px; line-height: 1; margin-bottom: 10px; }
18
+ .tool .t { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
19
+ .tool .d { font-size: 13px; color: #8b949e; line-height: 1.4; }
20
+ </style>
21
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
22
+ </head>
23
+ <body>
24
+ <nav class="nav-bar">
25
+ <div class="nav-brand">🙈 Blind Monkeys</div>
26
+ <div class="nav-links">
27
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
28
+ <a href="/profile/" class="nav-link">👤 Profile</a>
29
+ <a href="/logout" class="nav-link">🚪 Logout</a>
30
+ </div>
31
+ </nav>
32
+ <div class="page-content">
33
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Admin</span></div>
34
+ <h1>🛠️ Admin</h1>
35
+ <p class="sub">Administration tools for the Blind Monkeys platform.</p>
36
+ <div class="tools">
37
+ <a class="tool" href="/admin/cron"><div class="ico">⏰</div><div class="t">Cron Jobs</div><div class="d">Scheduled jobs: scans, summaries, balance snapshots.</div></a>
38
+ <a class="tool" href="/admin/alerts"><div class="ico">🔔</div><div class="t">Coin Alerts</div><div class="d">Manage price and event alert rules.</div></a>
39
+ <a class="tool" href="/admin/users"><div class="ico">👥</div><div class="t">Users</div><div class="d">Approve registrations, manage roles and accounts.</div></a>
40
+ </div>
41
+ </div>
42
+ <script src="/css/nav.js"></script>
43
+ </body>
44
+ </html>
templates/admin_users.html CHANGED
@@ -256,5 +256,18 @@
256
  </div>
257
  </div>
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  </body>
260
  </html>
 
256
  </div>
257
  </div>
258
 
259
+ <!--Start of Tawk.to Script-->
260
+ <script type="text/javascript">
261
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
262
+ (function(){
263
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
264
+ s1.async=true;
265
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
266
+ s1.charset='UTF-8';
267
+ s1.setAttribute('crossorigin','*');
268
+ s0.parentNode.insertBefore(s1,s0);
269
+ })();
270
+ </script>
271
+ <!--End of Tawk.to Script-->
272
  </body>
273
  </html>
templates/analytics.html ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Analytics — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <style>
9
+ * { box-sizing: border-box; }
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
11
+ .page-content { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }
12
+ h1 { font-size: 24px; margin: 0 0 4px; }
13
+ .sub { color: #8b949e; font-size: 14px; margin-bottom: 24px; }
14
+ .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 24px; }
15
+ .stat { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 18px; }
16
+ .stat .t { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #f0b90b; margin-bottom: 8px; }
17
+ .stat .v { font-size: 26px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; }
18
+ .stat .d { font-size: 12px; color: #8b949e; margin-top: 6px; }
19
+ .pos { color: #4ade80; } .neg { color: #f87171; } .mut { color: #8b949e; }
20
+ .card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; margin-bottom: 20px; }
21
+ .card h2 { font-size: 14px; color: #f0b90b; margin: 0 0 16px; letter-spacing: 1px; text-transform: uppercase; }
22
+ table { width: 100%; border-collapse: collapse; }
23
+ th { text-align: left; padding: 10px 8px; color: #8b949e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; }
24
+ td { padding: 12px 8px; border-bottom: 1px solid #21262d; font-size: 14px; }
25
+ tr:last-child td { border-bottom: none; }
26
+ .mono { font-family: 'SF Mono', Monaco, monospace; }
27
+ .empty { color: #8b949e; font-size: 14px; padding: 16px 0; text-align: center; }
28
+ .more { display: inline-block; padding: 10px 22px; background: #f0b90b; color: #0d1117; border-radius: 8px; font-weight: 700; font-size: 14px; text-decoration: none; }
29
+ .more:hover { opacity: 0.85; }
30
+ </style>
31
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
32
+ </head>
33
+ <body>
34
+ <nav class="nav-bar">
35
+ <div class="nav-brand">🙈 Blind Monkeys</div>
36
+ <div class="nav-links">
37
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
38
+ <a href="/profile/" class="nav-link">👤 Profile</a>
39
+ <a href="/logout" class="nav-link">🚪 Logout</a>
40
+ </div>
41
+ </nav>
42
+ <div class="page-content">
43
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Analytics</span></div>
44
+ <h1>📈 Analytics</h1>
45
+ <p class="sub">Admin-only performance and market overview.</p>
46
+
47
+ <div class="stats">
48
+ <div class="stat"><div class="t">Total Equity</div><div class="v" id="v-eq">—</div><div class="d" id="d-eq">Funding + Unified + Grid</div></div>
49
+ <div class="stat"><div class="t">Grid Return — 30 Days</div><div class="v" id="v-gr">—</div><div class="d" id="d-gr">closed bots</div></div>
50
+ <div class="stat"><div class="t">Grid Win Rate</div><div class="v" id="v-wr">—</div><div class="d" id="d-wr">closed bots</div></div>
51
+ <div class="stat"><div class="t">S&amp;P 500 — 30 Days</div><div class="v" id="v-sp">—</div><div class="d" id="d-sp">benchmark</div></div>
52
+ </div>
53
+
54
+ <div class="card">
55
+ <h2>Bybit Balances</h2>
56
+ <table>
57
+ <tr><td>Funding Account</td><td class="mono" id="b-fund" style="text-align:right;">—</td></tr>
58
+ <tr><td>Unified Trading</td><td class="mono" id="b-uni" style="text-align:right;">—</td></tr>
59
+ <tr><td>Grid Investment</td><td class="mono" id="b-inv" style="text-align:right;">—</td></tr>
60
+ <tr><td>Futures Combo</td><td class="mono" id="b-fut" style="text-align:right;">—</td></tr>
61
+ </table>
62
+ </div>
63
+
64
+ <p><a class="more" href="/financials/">Full Financials →</a></p>
65
+ </div>
66
+ <script src="/css/nav.js"></script>
67
+ <script>
68
+ function col(v) { return v > 0 ? '#4ade80' : (v < 0 ? '#f87171' : '#e6edf3'); }
69
+ function sign(v) { return (v > 0 ? '+' : '') + v.toFixed(2) + '%'; }
70
+ fetch('/api/bybit-balance').then(function (r) { return r.json(); }).then(function (b) {
71
+ var f = Number(b.fund_usdt || 0), u = Number(b.unified_total || 0), i = Number(b.investment_total || 0);
72
+ document.getElementById('b-fund').textContent = '$' + f.toFixed(2);
73
+ document.getElementById('b-uni').textContent = '$' + u.toFixed(2);
74
+ document.getElementById('b-inv').textContent = '$' + i.toFixed(2);
75
+ document.getElementById('b-fut').textContent = '$' + Number(b.futures_combo || 0).toFixed(2);
76
+ var eq = f + u + i;
77
+ var el = document.getElementById('v-eq');
78
+ el.textContent = '$' + eq.toFixed(2);
79
+ }).catch(function () {});
80
+ fetch('https://scan.blind-monkeys.com/grid/returns').then(function (r) { return r.json(); }).then(function (d) {
81
+ var ret = Number(d.return_pct || 0);
82
+ var el = document.getElementById('v-gr');
83
+ el.textContent = sign(ret); el.style.color = col(ret);
84
+ document.getElementById('d-gr').textContent = d.count + ' closed bots · $' + Number(d.invested || 0).toFixed(0) + ' invested';
85
+ var wr = Number(d.win_rate || 0);
86
+ var elw = document.getElementById('v-wr');
87
+ elw.textContent = wr.toFixed(1) + '%'; elw.style.color = col(wr - 50);
88
+ document.getElementById('d-wr').textContent = (d.wins || 0) + ' wins / ' + (d.closed || 0) + ' closed';
89
+ }).catch(function () {});
90
+ fetch('/api/sp500-30d').then(function (r) { return r.json(); }).then(function (d) {
91
+ var ret = Number(d.return_pct || 0);
92
+ var el = document.getElementById('v-sp');
93
+ el.textContent = sign(ret); el.style.color = col(ret);
94
+ document.getElementById('d-sp').textContent = 'as of ' + (d.as_of || '?');
95
+ }).catch(function () {});
96
+ </script>
97
+ </body>
98
+ </html>
templates/bot_detail.html CHANGED
@@ -124,5 +124,18 @@
124
  });
125
  </script>
126
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  </body>
128
  </html>
 
124
  });
125
  </script>
126
  <script src="/css/nav.js"></script>
127
+ <!--Start of Tawk.to Script-->
128
+ <script type="text/javascript">
129
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
130
+ (function(){
131
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
132
+ s1.async=true;
133
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
134
+ s1.charset='UTF-8';
135
+ s1.setAttribute('crossorigin','*');
136
+ s0.parentNode.insertBefore(s1,s0);
137
+ })();
138
+ </script>
139
+ <!--End of Tawk.to Script-->
140
  </body>
141
  </html>
templates/contact.html CHANGED
@@ -163,5 +163,18 @@
163
  });
164
  })();
165
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  </body>
167
  </html>
 
163
  });
164
  })();
165
  </script>
166
+ <!--Start of Tawk.to Script-->
167
+ <script type="text/javascript">
168
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
169
+ (function(){
170
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
171
+ s1.async=true;
172
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
173
+ s1.charset='UTF-8';
174
+ s1.setAttribute('crossorigin','*');
175
+ s0.parentNode.insertBefore(s1,s0);
176
+ })();
177
+ </script>
178
+ <!--End of Tawk.to Script-->
179
  </body>
180
  </html>
templates/dart_add_bot.html CHANGED
@@ -58,5 +58,18 @@
58
  </form>
59
  </div>
60
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  </body>
62
  </html>
 
58
  </form>
59
  </div>
60
  <script src="/css/nav.js"></script>
61
+ <!--Start of Tawk.to Script-->
62
+ <script type="text/javascript">
63
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
64
+ (function(){
65
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
66
+ s1.async=true;
67
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
68
+ s1.charset='UTF-8';
69
+ s1.setAttribute('crossorigin','*');
70
+ s0.parentNode.insertBefore(s1,s0);
71
+ })();
72
+ </script>
73
+ <!--End of Tawk.to Script-->
74
  </body>
75
  </html>
templates/dart_performance.html CHANGED
@@ -187,5 +187,18 @@
187
  setInterval(loadData, AUTO_REFRESH_MS);
188
  </script>
189
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  </body>
191
  </html>
 
187
  setInterval(loadData, AUTO_REFRESH_MS);
188
  </script>
189
  <script src="/css/nav.js"></script>
190
+ <!--Start of Tawk.to Script-->
191
+ <script type="text/javascript">
192
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
193
+ (function(){
194
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
195
+ s1.async=true;
196
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
197
+ s1.charset='UTF-8';
198
+ s1.setAttribute('crossorigin','*');
199
+ s0.parentNode.insertBefore(s1,s0);
200
+ })();
201
+ </script>
202
+ <!--End of Tawk.to Script-->
203
  </body>
204
  </html>
templates/faq.html CHANGED
@@ -136,5 +136,18 @@
136
  </div>
137
 
138
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  </body>
140
  </html>
 
136
  </div>
137
 
138
  <script src="/css/nav.js"></script>
139
+ <!--Start of Tawk.to Script-->
140
+ <script type="text/javascript">
141
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
142
+ (function(){
143
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
144
+ s1.async=true;
145
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
146
+ s1.charset='UTF-8';
147
+ s1.setAttribute('crossorigin','*');
148
+ s0.parentNode.insertBefore(s1,s0);
149
+ })();
150
+ </script>
151
+ <!--End of Tawk.to Script-->
152
  </body>
153
  </html>
templates/glossary.html CHANGED
@@ -155,5 +155,18 @@
155
  </div>
156
 
157
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  </body>
159
  </html>
 
155
  </div>
156
 
157
  <script src="/css/nav.js"></script>
158
+ <!--Start of Tawk.to Script-->
159
+ <script type="text/javascript">
160
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
161
+ (function(){
162
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
163
+ s1.async=true;
164
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
165
+ s1.charset='UTF-8';
166
+ s1.setAttribute('crossorigin','*');
167
+ s0.parentNode.insertBefore(s1,s0);
168
+ })();
169
+ </script>
170
+ <!--End of Tawk.to Script-->
171
  </body>
172
  </html>
templates/license.html CHANGED
@@ -67,5 +67,18 @@ SOFTWARE.
67
  </div>
68
  </div>
69
  <script src="/css/nav.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </body>
71
  </html>
 
67
  </div>
68
  </div>
69
  <script src="/css/nav.js"></script>
70
+ <!--Start of Tawk.to Script-->
71
+ <script type="text/javascript">
72
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
73
+ (function(){
74
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
75
+ s1.async=true;
76
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
77
+ s1.charset='UTF-8';
78
+ s1.setAttribute('crossorigin','*');
79
+ s0.parentNode.insertBefore(s1,s0);
80
+ })();
81
+ </script>
82
+ <!--End of Tawk.to Script-->
83
  </body>
84
  </html>
templates/login.html CHANGED
@@ -74,5 +74,18 @@ document.addEventListener('DOMContentLoaded', function() {
74
  } catch(e) {}
75
  });
76
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  </body>
78
  </html>
 
74
  } catch(e) {}
75
  });
76
  </script>
77
+ <!--Start of Tawk.to Script-->
78
+ <script type="text/javascript">
79
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
80
+ (function(){
81
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
82
+ s1.async=true;
83
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
84
+ s1.charset='UTF-8';
85
+ s1.setAttribute('crossorigin','*');
86
+ s0.parentNode.insertBefore(s1,s0);
87
+ })();
88
+ </script>
89
+ <!--End of Tawk.to Script-->
90
  </body>
91
  </html>
templates/privacy.html CHANGED
@@ -88,5 +88,18 @@
88
 
89
  <div class="note">This is a working draft and should be reviewed by a qualified attorney before relying on it for legal purposes.</div>
90
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  </body>
92
  </html>
 
88
 
89
  <div class="note">This is a working draft and should be reviewed by a qualified attorney before relying on it for legal purposes.</div>
90
  </div>
91
+ <!--Start of Tawk.to Script-->
92
+ <script type="text/javascript">
93
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
94
+ (function(){
95
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
96
+ s1.async=true;
97
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
98
+ s1.charset='UTF-8';
99
+ s1.setAttribute('crossorigin','*');
100
+ s0.parentNode.insertBefore(s1,s0);
101
+ })();
102
+ </script>
103
+ <!--End of Tawk.to Script-->
104
  </body>
105
  </html>
templates/profile.html CHANGED
@@ -224,5 +224,18 @@ window.__et = function(name, props) {
224
  });
225
  })();
226
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  </body>
228
  </html>
 
224
  });
225
  })();
226
  </script>
227
+ <!--Start of Tawk.to Script-->
228
+ <script type="text/javascript">
229
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
230
+ (function(){
231
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
232
+ s1.async=true;
233
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
234
+ s1.charset='UTF-8';
235
+ s1.setAttribute('crossorigin','*');
236
+ s0.parentNode.insertBefore(s1,s0);
237
+ })();
238
+ </script>
239
+ <!--End of Tawk.to Script-->
240
  </body>
241
  </html>
templates/regimes.html ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Market Regimes — Blind Monkeys</title>
7
+ <link rel="stylesheet" href="/css/nav.css">
8
+ <style>
9
+ * { box-sizing: border-box; }
10
+ body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
11
+ .page-content { max-width: 1000px; margin: 0 auto; padding: 32px 20px 60px; }
12
+ h1 { font-size: 26px; margin: 0 0 4px; }
13
+ .sub { color: #8b949e; font-size: 14px; margin-bottom: 20px; }
14
+
15
+ .now { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; margin-bottom: 20px; text-align: center; }
16
+ .now .lbl { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #8b949e; margin-bottom: 8px; }
17
+ .now .val { font-size: 30px; font-weight: 700; }
18
+ .now .hint { font-size: 13px; color: #8b949e; margin-top: 8px; }
19
+
20
+ .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 28px; }
21
+ .stat { background: #1e2329; border: 1px solid #30363d; border-radius: 10px; padding: 14px 16px; }
22
+ .stat .t { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #f0b90b; margin-bottom: 6px; }
23
+ .stat .v { font-size: 20px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; }
24
+ .stat .d { font-size: 11px; color: #8b949e; margin-top: 4px; }
25
+
26
+ .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
27
+ .card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 22px; text-decoration: none; color: #e6edf3; display: flex; flex-direction: column; transition: transform .15s ease, box-shadow .15s ease; position: relative; }
28
+ .card:hover { transform: translateY(-2px); }
29
+ .up { border-color: #30363d; } .up.live { border-color: #4ade80; box-shadow: 0 0 18px rgba(74,222,128,.25); }
30
+ .side.live { border-color: #f0b90b; box-shadow: 0 0 18px rgba(240,185,11,.25); }
31
+ .down.live { border-color: #f87171; box-shadow: 0 0 18px rgba(248,113,113,.25); }
32
+ .ico { font-size: 32px; line-height: 1; margin-bottom: 12px; }
33
+ .t { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
34
+ .up .t { color: #4ade80; } .side .t { color: #f0b90b; } .down .t { color: #f87171; }
35
+ .desc { font-size: 13px; color: #8b949e; line-height: 1.5; margin-bottom: 12px; }
36
+ .strategy { font-size: 12px; line-height: 1.7; }
37
+ .strategy b { color: #e6edf3; }
38
+ .badge { position: absolute; top: 14px; right: 14px; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; padding: 4px 10px; border-radius: 6px; display: none; }
39
+ .card.live .badge { display: inline-block; }
40
+ .up .badge { background: rgba(74,222,128,.15); color: #4ade80; border: 1px solid #4ade80; }
41
+ .side .badge { background: rgba(240,185,11,.15); color: #f0b90b; border: 1px solid #f0b90b; }
42
+ .down .badge { background: rgba(248,113,113,.15); color: #f87171; border: 1px solid #f87171; }
43
+ </style>
44
+ <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
45
+ </head>
46
+ <body>
47
+ <nav class="nav-bar">
48
+ <div class="nav-brand">🙈 Blind Monkeys</div>
49
+ <div class="nav-links">
50
+ <a href="/settings/" class="nav-link">⚙️ Settings</a>
51
+ <a href="/profile/" class="nav-link">👤 Profile</a>
52
+ <a href="/logout" class="nav-link">🚪 Logout</a>
53
+ </div>
54
+ </nav>
55
+ <div class="page-content">
56
+ <div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">›</span><span class="bc-current">Regimes</span></div>
57
+ <h1>🌍 Market Regimes</h1>
58
+ <p class="sub">Live market direction and the strategy that fits each regime.</p>
59
+
60
+ <div class="now">
61
+ <div class="lbl">Current Regime</div>
62
+ <div class="val" id="now-regime">Detecting…</div>
63
+ <div class="hint" id="now-hint">Based on ETH and BTC 24-hour price action.</div>
64
+ </div>
65
+
66
+ <div class="stats">
67
+ <div class="stat"><div class="t">ETH off 24h High</div><div class="v" id="v-eth">—</div><div class="d" id="d-eth">24h drawdown</div></div>
68
+ <div class="stat"><div class="t">Fear &amp; Greed</div><div class="v" id="v-fng">—</div><div class="d" id="d-fng">sentiment</div></div>
69
+ <div class="stat"><div class="t">VIX</div><div class="v" id="v-vix">—</div><div class="d">volatility</div></div>
70
+ <div class="stat"><div class="t">10Y Treasury</div><div class="v" id="v-tsyy">—</div><div class="d">macro</div></div>
71
+ </div>
72
+
73
+ <div class="cards">
74
+ <a class="card up" id="card-up" href="/upward">
75
+ <span class="badge">Active Now</span>
76
+ <div class="ico">📈</div>
77
+ <div class="t">Upward Markets</div>
78
+ <div class="desc">Prices trending up with sustained momentum. Breakouts hold; dips get bought quickly.</div>
79
+ <div class="strategy">
80
+ <b>What runs here:</b> trend-following entries, momentum signals, let-winners-run bias.<br>
81
+ <b>Watch:</b> overheating — rising ADX and stretched RSI can mark exhaustion.
82
+ </div>
83
+ </a>
84
+ <a class="card side" id="card-side" href="/sideways">
85
+ <span class="badge">Active Now</span>
86
+ <div class="ico">↔️</div>
87
+ <div class="t">Sideways Markets</div>
88
+ <div class="desc">Range-bound price action — oscillation inside a band, low net drift.</div>
89
+ <div class="strategy">
90
+ <b>What runs here:</b> <b style="color:#f0b90b;">grid bots</b> — every oscillation is harvested profit. Our core strategy.<br>
91
+ <b>Watch:</b> bounces inside the ±3% band and low ADX (no trend).
92
+ </div>
93
+ </a>
94
+ <a class="card down" id="card-down" href="/downward">
95
+ <span class="badge">Active Now</span>
96
+ <div class="ico">📉</div>
97
+ <div class="t">Downward Markets</div>
98
+ <div class="desc">BTC/ETH declining from highs — most coins follow, grids go quiet.</div>
99
+ <div class="strategy">
100
+ <b>What runs here:</b> <b style="color:#4ade80;">combo futures on Rising Coins</b> — coins rising against a falling market show relative strength.<br>
101
+ <b>Watch:</b> coins defying the drawdown with volume and open-interest growth.
102
+ </div>
103
+ </a>
104
+ </div>
105
+ </div>
106
+ <script src="/css/nav.js"></script>
107
+ <script>
108
+ function setRegime(kind, label, hint) {
109
+ var el = document.getElementById('now-regime');
110
+ el.textContent = label;
111
+ el.style.color = kind === 'up' ? '#4ade80' : (kind === 'down' ? '#f87171' : '#f0b90b');
112
+ var h = document.getElementById('now-hint');
113
+ if (h) h.textContent = hint;
114
+ ['up', 'side', 'down'].forEach(function (k) {
115
+ document.getElementById('card-' + k).classList.toggle('live', k === kind);
116
+ });
117
+ }
118
+ fetch('/api/market-regime').then(function (r) { return r.json(); }).then(function (d) {
119
+ var drop = Number(d.drop_pct || d.drop_percentage || 0);
120
+ var el = document.getElementById('v-eth');
121
+ el.textContent = drop.toFixed(2) + '%';
122
+ el.style.color = drop >= 2 ? '#f87171' : (drop <= 0.5 ? '#4ade80' : '#f0b90b');
123
+ if (drop >= 2) {
124
+ setRegime('down', '📉 Downward', 'ETH is ' + drop.toFixed(2) + '% off its 24h high — Rising Coin futures are the active strategy.');
125
+ } else if (drop < 0.5) {
126
+ setRegime('side', '↔️ Sideways', 'ETH is ' + drop.toFixed(2) + '% off its 24h high — oscillation regime, grid bots are harvesting.');
127
+ } else {
128
+ setRegime('up', '📈 Upward', 'ETH holding near its 24h high — momentum regime.');
129
+ }
130
+ }).catch(function () {
131
+ setRegime('side', '↔️ Sideways (assumed)', 'Could not read live regime data.');
132
+ });
133
+ fetch('/api/regime-panel').then(function (r) { return r.json(); }).then(function (p) {
134
+ var f = p.fear_greed || {};
135
+ if (f && f.value !== undefined) {
136
+ var v = Number(f.value);
137
+ var el = document.getElementById('v-fng');
138
+ el.textContent = v;
139
+ el.style.color = v >= 55 ? '#4ade80' : (v <= 45 ? '#f87171' : '#f0b90b');
140
+ document.getElementById('d-fng').textContent = (f.classification || 'sentiment');
141
+ }
142
+ var vx = p.vix || {};
143
+ if (vx && vx.value !== undefined) {
144
+ var vv = Number(vx.value);
145
+ var elv = document.getElementById('v-vix');
146
+ elv.textContent = vv.toFixed(2);
147
+ elv.style.color = vv >= 25 ? '#f87171' : (vv <= 18 ? '#4ade80' : '#f0b90b');
148
+ }
149
+ var tr = p.treasury || {};
150
+ if (tr && tr.current !== undefined) {
151
+ var tv = Number(tr.current);
152
+ document.getElementById('v-tsyy').textContent = tv.toFixed(2) + '%';
153
+ }
154
+ }).catch(function () {});
155
+ </script>
156
+ </body>
157
+ </html>
templates/register.html CHANGED
@@ -120,5 +120,18 @@ window.__et = function(name, props) {
120
  } catch(e) {}
121
  };
122
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  </body>
124
  </html>
 
120
  } catch(e) {}
121
  };
122
  </script>
123
+ <!--Start of Tawk.to Script-->
124
+ <script type="text/javascript">
125
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
126
+ (function(){
127
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
128
+ s1.async=true;
129
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
130
+ s1.charset='UTF-8';
131
+ s1.setAttribute('crossorigin','*');
132
+ s0.parentNode.insertBefore(s1,s0);
133
+ })();
134
+ </script>
135
+ <!--End of Tawk.to Script-->
136
  </body>
137
  </html>
templates/register_pending.html CHANGED
@@ -59,5 +59,18 @@ window.__et = function(name, props) {
59
  <script>
60
  document.addEventListener('DOMContentLoaded', function() { window.__et && window.__et('register'); });
61
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  </body>
63
  </html>
 
59
  <script>
60
  document.addEventListener('DOMContentLoaded', function() { window.__et && window.__et('register'); });
61
  </script>
62
+ <!--Start of Tawk.to Script-->
63
+ <script type="text/javascript">
64
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
65
+ (function(){
66
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
67
+ s1.async=true;
68
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
69
+ s1.charset='UTF-8';
70
+ s1.setAttribute('crossorigin','*');
71
+ s0.parentNode.insertBefore(s1,s0);
72
+ })();
73
+ </script>
74
+ <!--End of Tawk.to Script-->
75
  </body>
76
  </html>
templates/reset.html CHANGED
@@ -49,5 +49,18 @@ window.__et = function(name, props) {
49
  } catch(e) {}
50
  };
51
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  </body>
53
  </html>
 
49
  } catch(e) {}
50
  };
51
  </script>
52
+ <!--Start of Tawk.to Script-->
53
+ <script type="text/javascript">
54
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
55
+ (function(){
56
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
57
+ s1.async=true;
58
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
59
+ s1.charset='UTF-8';
60
+ s1.setAttribute('crossorigin','*');
61
+ s0.parentNode.insertBefore(s1,s0);
62
+ })();
63
+ </script>
64
+ <!--End of Tawk.to Script-->
65
  </body>
66
  </html>
templates/reset_new.html CHANGED
@@ -58,5 +58,18 @@ window.__et = function(name, props) {
58
  } catch(e) {}
59
  };
60
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  </body>
62
  </html>
 
58
  } catch(e) {}
59
  };
60
  </script>
61
+ <!--Start of Tawk.to Script-->
62
+ <script type="text/javascript">
63
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
64
+ (function(){
65
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
66
+ s1.async=true;
67
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
68
+ s1.charset='UTF-8';
69
+ s1.setAttribute('crossorigin','*');
70
+ s0.parentNode.insertBefore(s1,s0);
71
+ })();
72
+ </script>
73
+ <!--End of Tawk.to Script-->
74
  </body>
75
  </html>
templates/terms.html CHANGED
@@ -69,5 +69,18 @@
69
  <h2>11. Contact</h2>
70
  <p>Questions about these Terms? Email <a href="mailto:dean@zojax.com">dean@zojax.com</a>.</p>
71
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  </body>
73
  </html>
 
69
  <h2>11. Contact</h2>
70
  <p>Questions about these Terms? Email <a href="mailto:dean@zojax.com">dean@zojax.com</a>.</p>
71
  </div>
72
+ <!--Start of Tawk.to Script-->
73
+ <script type="text/javascript">
74
+ var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
75
+ (function(){
76
+ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
77
+ s1.async=true;
78
+ s1.src='https://embed.tawk.to/6ad326872ab00434d21793a2/1k54ic9h0';
79
+ s1.charset='UTF-8';
80
+ s1.setAttribute('crossorigin','*');
81
+ s0.parentNode.insertBefore(s1,s0);
82
+ })();
83
+ </script>
84
+ <!--End of Tawk.to Script-->
85
  </body>
86
  </html>