Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,6 +68,10 @@ ALIASES = {
|
|
| 68 |
"until": ["until", "end", "end_time", "endTime", "to", "before"],
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
TF_MS = {"1m": 60_000, "5m": 300_000, "15m": 900_000, "1h": 3_600_000,
|
| 72 |
"4h": 14_400_000, "1d": 86_400_000}
|
| 73 |
|
|
@@ -176,9 +180,19 @@ def make_features(df: pd.DataFrame):
|
|
| 176 |
lr = np.log(c).diff()
|
| 177 |
|
| 178 |
# Getiri / momentum (çok ölçekli)
|
| 179 |
-
for n in (1, 2, 3, 6, 12, 24, 48):
|
| 180 |
f[f"ret{n}"] = c.pct_change(n)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# Volatilite rejimi
|
| 183 |
for n in (6, 24, 96):
|
| 184 |
f[f"vol{n}"] = lr.rolling(n).std()
|
|
@@ -381,7 +395,19 @@ async def run_async(symbol, timeframe, exchange, horizon, limit):
|
|
| 381 |
timeframe=timeframe, exchange=exchange)
|
| 382 |
ind = await call_tool(session, tools, "compute_indicators", symbol=symbol,
|
| 383 |
timeframe=timeframe, exchange=exchange)
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
|
| 387 |
def _root(e):
|
|
@@ -393,7 +419,7 @@ def _root(e):
|
|
| 393 |
|
| 394 |
def run(symbol, timeframe, exchange, horizon, limit):
|
| 395 |
try:
|
| 396 |
-
ohlcv, deep, ind = asyncio.run(run_async(symbol, timeframe, exchange, horizon, limit))
|
| 397 |
df = to_df(ohlcv)
|
| 398 |
res = predict(df, int(horizon))
|
| 399 |
except BaseException as e: # noqa: BLE001
|
|
@@ -432,7 +458,7 @@ def run(symbol, timeframe, exchange, horizon, limit):
|
|
| 432 |
arrayminus=[res["center"] - res["low"]])))
|
| 433 |
fig.update_layout(height=450, xaxis_rangeslider_visible=False, margin=dict(l=10, r=10, t=30, b=10))
|
| 434 |
|
| 435 |
-
raw = json.dumps({"deep_analyze": deep, "compute_indicators": ind},
|
| 436 |
indent=2, ensure_ascii=False, default=str)
|
| 437 |
return md, fig, raw
|
| 438 |
|
|
|
|
| 68 |
"until": ["until", "end", "end_time", "endTime", "to", "before"],
|
| 69 |
}
|
| 70 |
|
| 71 |
+
EXTRA_TOOLS = ["detect_divergence", "detect_patterns", "analyze_structure",
|
| 72 |
+
"find_support_resistance", "detect_cross", "get_orderbook",
|
| 73 |
+
"get_ticker", "get_recent_trades", "server_status"]
|
| 74 |
+
|
| 75 |
TF_MS = {"1m": 60_000, "5m": 300_000, "15m": 900_000, "1h": 3_600_000,
|
| 76 |
"4h": 14_400_000, "1d": 86_400_000}
|
| 77 |
|
|
|
|
| 180 |
lr = np.log(c).diff()
|
| 181 |
|
| 182 |
# Getiri / momentum (çok ölçekli)
|
| 183 |
+
for n in (1, 2, 3, 6, 12, 24, 48, 96, 192):
|
| 184 |
f[f"ret{n}"] = c.pct_change(n)
|
| 185 |
|
| 186 |
+
# Çoklu zaman dilimi (lookahead'siz yuvarlanan pencereler): ~4x ve ~16x üst TF benzeri
|
| 187 |
+
dd = c.diff()
|
| 188 |
+
for k in (4, 16):
|
| 189 |
+
up_k = dd.clip(lower=0).ewm(alpha=1 / (14 * k), adjust=False).mean()
|
| 190 |
+
dn_k = (-dd.clip(upper=0)).ewm(alpha=1 / (14 * k), adjust=False).mean()
|
| 191 |
+
f[f"rsi_htf{k}"] = 100 - 100 / (1 + up_k / (dn_k + 1e-12))
|
| 192 |
+
f[f"ema_dist_htf{k}"] = c / c.ewm(span=20 * k, adjust=False).mean() - 1
|
| 193 |
+
f[f"chan_pos{k}"] = (c - l.rolling(20 * k).min()) / (h.rolling(20 * k).max() - l.rolling(20 * k).min() + 1e-12)
|
| 194 |
+
f[f"vol_htf{k}"] = lr.rolling(20 * k).std()
|
| 195 |
+
|
| 196 |
# Volatilite rejimi
|
| 197 |
for n in (6, 24, 96):
|
| 198 |
f[f"vol{n}"] = lr.rolling(n).std()
|
|
|
|
| 395 |
timeframe=timeframe, exchange=exchange)
|
| 396 |
ind = await call_tool(session, tools, "compute_indicators", symbol=symbol,
|
| 397 |
timeframe=timeframe, exchange=exchange)
|
| 398 |
+
|
| 399 |
+
# Tickscope'un diğer tüm analiz/piyasa araçları (canlı bağlam; şema uyuşmazsa hata olarak kaydedilir)
|
| 400 |
+
extra = {}
|
| 401 |
+
for name in EXTRA_TOOLS:
|
| 402 |
+
if name not in tools:
|
| 403 |
+
continue
|
| 404 |
+
try:
|
| 405 |
+
extra[name] = await call_tool(session, tools, name, symbol=symbol,
|
| 406 |
+
timeframe=timeframe, exchange=exchange)
|
| 407 |
+
except Exception as e: # noqa: BLE001
|
| 408 |
+
extra[name] = {"error": _root(e)}
|
| 409 |
+
extra["_available_tools"] = list(tools)
|
| 410 |
+
return ohlcv, deep, ind, extra
|
| 411 |
|
| 412 |
|
| 413 |
def _root(e):
|
|
|
|
| 419 |
|
| 420 |
def run(symbol, timeframe, exchange, horizon, limit):
|
| 421 |
try:
|
| 422 |
+
ohlcv, deep, ind, extra = asyncio.run(run_async(symbol, timeframe, exchange, horizon, limit))
|
| 423 |
df = to_df(ohlcv)
|
| 424 |
res = predict(df, int(horizon))
|
| 425 |
except BaseException as e: # noqa: BLE001
|
|
|
|
| 458 |
arrayminus=[res["center"] - res["low"]])))
|
| 459 |
fig.update_layout(height=450, xaxis_rangeslider_visible=False, margin=dict(l=10, r=10, t=30, b=10))
|
| 460 |
|
| 461 |
+
raw = json.dumps({"deep_analyze": deep, "compute_indicators": ind, **extra},
|
| 462 |
indent=2, ensure_ascii=False, default=str)
|
| 463 |
return md, fig, raw
|
| 464 |
|