trump-code-market-signals

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Trump Code — Market Signal Analysis

Trump Code — 市场信号分析

Skill by ara.so — Daily 2026 Skills collection.
Trump Code is an open-source system that applies brute-force computation to find statistically significant patterns between Trump's Truth Social/X posting behavior and S&P 500 movements. It has tested 31.5M model combinations, maintains 551 surviving rules, and has a verified 61.3% hit rate across 566 predictions (z=5.39, p<0.05).
ara.so开发的Skill — 2026每日技能合集。
Trump Code是一个开源系统,通过暴力计算寻找特朗普在Truth Social/X上的发帖行为与标普500指数走势之间的统计显著模式。它已测试了3150万种模型组合,保留了551条有效规则,在566次预测中验证的命中率达61.3%(z=5.39,p<0.05)。

Installation

安装

bash
git clone https://github.com/sstklen/trump-code.git
cd trump-code
pip install -r requirements.txt
bash
git clone https://github.com/sstklen/trump-code.git
cd trump-code
pip install -r requirements.txt

Environment Variables

环境变量

bash
undefined
bash
undefined

Required for AI briefing and chatbot

AI简报和聊天机器人所需

export GEMINI_KEYS="key1,key2,key3" # Comma-separated Gemini API keys
export GEMINI_KEYS="key1,key2,key3" # 逗号分隔的Gemini API密钥

Optional: for Claude Opus deep analysis

可选:用于Claude Opus深度分析

export ANTHROPIC_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"

Optional: for Polymarket/Kalshi integration

可选:用于Polymarket/Kalshi集成

export POLYMARKET_API_KEY="your-key-here"
undefined
export POLYMARKET_API_KEY="your-key-here"
undefined

CLI — Key Commands

CLI — 核心命令

bash
undefined
bash
undefined

Today's detected signals from Trump's posts

今日从特朗普帖子中检测到的信号

python3 trump_code_cli.py signals
python3 trump_code_cli.py signals

Model performance leaderboard (all 11 named models)

模型性能排行榜(全部11个命名模型)

python3 trump_code_cli.py models
python3 trump_code_cli.py models

Get LONG/SHORT consensus prediction

获取多模型一致的LONG/SHORT预测

python3 trump_code_cli.py predict
python3 trump_code_cli.py predict

Prediction market arbitrage opportunities

预测市场套利机会

python3 trump_code_cli.py arbitrage
python3 trump_code_cli.py arbitrage

System health check (circuit breaker state)

系统健康检查(熔断机制状态)

python3 trump_code_cli.py health
python3 trump_code_cli.py health

Full daily report (trilingual)

完整每日报告(三语言)

python3 trump_code_cli.py report
python3 trump_code_cli.py report

Dump all data as JSON

导出所有数据为JSON格式

python3 trump_code_cli.py json
undefined
python3 trump_code_cli.py json
undefined

Core Scripts

核心脚本

bash
undefined
bash
undefined

Real-time Trump post monitor (polls every 5 min)

实时特朗普帖子监控(每5分钟轮询一次)

python3 realtime_loop.py
python3 realtime_loop.py

Brute-force model search (~25 min, tests millions of combos)

暴力模型搜索(约25分钟,测试数百万种组合)

python3 overnight_search.py
python3 overnight_search.py

Individual analyses

独立分析脚本

python3 analysis_06_market.py # Posts vs S&P 500 correlation python3 analysis_09_combo_score.py # Multi-signal combo scoring
python3 analysis_06_market.py # 帖子与标普500指数相关性分析 python3 analysis_09_combo_score.py # 多信号组合评分

Web dashboard + AI chatbot on port 8888

网页仪表盘 + AI聊天机器人(端口8888)

export GEMINI_KEYS="key1,key2,key3" python3 chatbot_server.py
export GEMINI_KEYS="key1,key2,key3" python3 chatbot_server.py
undefined
undefined

REST API (Live at trumpcode.washinmura.jp)

REST API(部署于trumpcode.washinmura.jp)

python
import requests

BASE = "https://trumpcode.washinmura.jp"
python
import requests

BASE = "https://trumpcode.washinmura.jp"

All dashboard data in one call

一次性获取所有仪表盘数据

data = requests.get(f"{BASE}/api/dashboard").json()
data = requests.get(f"{BASE}/api/dashboard").json()

Today's signals + 7-day history

今日信号 + 7天历史数据

signals = requests.get(f"{BASE}/api/signals").json()
signals = requests.get(f"{BASE}/api/signals").json()

Model performance rankings

模型性能排名

models = requests.get(f"{BASE}/api/models").json()
models = requests.get(f"{BASE}/api/models").json()

Latest 20 Trump posts with signal tags

带信号标签的最新20条特朗普帖子

posts = requests.get(f"{BASE}/api/recent-posts").json()
posts = requests.get(f"{BASE}/api/recent-posts").json()

Live Polymarket Trump prediction markets (316+)

Polymarket平台上的特朗普相关实时预测市场(316+个)

markets = requests.get(f"{BASE}/api/polymarket-trump").json()
markets = requests.get(f"{BASE}/api/polymarket-trump").json()

LONG/SHORT playbooks

LONG/SHORT操作指南

playbook = requests.get(f"{BASE}/api/playbook").json()
playbook = requests.get(f"{BASE}/api/playbook").json()

System health / circuit breaker state

系统健康状态 / 熔断机制状态

status = requests.get(f"{BASE}/api/status").json()
undefined
status = requests.get(f"{BASE}/api/status").json()
undefined

AI Chatbot API

AI聊天机器人API

python
import requests

response = requests.post(
    "https://trumpcode.washinmura.jp/api/chat",
    json={"message": "What signals fired today and what's the consensus?"}
)
print(response.json()["reply"])
python
import requests

response = requests.post(
    "https://trumpcode.washinmura.jp/api/chat",
    json={"message": "今天触发了哪些信号?一致预测是什么?"}
)
print(response.json()["reply"])

MCP Server (Claude Code / Cursor Integration)

MCP服务器(Claude Code / Cursor集成)

Add to
~/.claude/settings.json
:
json
{
  "mcpServers": {
    "trump-code": {
      "command": "python3",
      "args": ["/path/to/trump-code/mcp_server.py"]
    }
  }
}
Available MCP tools:
signals
,
models
,
predict
,
arbitrage
,
health
,
events
,
dual_platform
,
crowd
,
full_report
添加到
~/.claude/settings.json
:
json
{
  "mcpServers": {
    "trump-code": {
      "command": "python3",
      "args": ["/path/to/trump-code/mcp_server.py"]
    }
  }
}
可用MCP工具:
signals
,
models
,
predict
,
arbitrage
,
health
,
events
,
dual_platform
,
crowd
,
full_report

Open Data Files

开放数据文件

All data lives in
data/
and is updated daily:
python
import json, pathlib

DATA = pathlib.Path("data")
所有数据存储在
data/
目录下,每日更新:
python
import json, pathlib

DATA = pathlib.Path("data")

44,000+ Truth Social posts

44000+条Truth Social帖子

posts = json.loads((DATA / "trump_posts_all.json").read_text())
posts = json.loads((DATA / "trump_posts_all.json").read_text())

Posts with signals pre-tagged

预标记信号的帖子

posts_lite = json.loads((DATA / "trump_posts_lite.json").read_text())
posts_lite = json.loads((DATA / "trump_posts_lite.json").read_text())

566 verified predictions with outcomes

566条带结果的已验证预测

predictions = json.loads((DATA / "predictions_log.json").read_text())
predictions = json.loads((DATA / "predictions_log.json").read_text())

551 active rules (brute-force + evolved)

551条有效规则(暴力测试+进化生成)

rules = json.loads((DATA / "surviving_rules.json").read_text())
rules = json.loads((DATA / "surviving_rules.json").read_text())

384 features × 414 trading days

384个特征 × 414个交易日

features = json.loads((DATA / "daily_features.json").read_text())
features = json.loads((DATA / "daily_features.json").read_text())

S&P 500 OHLC history

标普500指数OHLC历史数据

market = json.loads((DATA / "market_SP500.json").read_text())
market = json.loads((DATA / "market_SP500.json").read_text())

Circuit breaker / system health

熔断机制 / 系统健康状态

cb = json.loads((DATA / "circuit_breaker_state.json").read_text())
cb = json.loads((DATA / "circuit_breaker_state.json").read_text())

Rule evolution log (crossover/mutation)

规则进化日志(交叉/突变)

evo = json.loads((DATA / "evolution_log.json").read_text())
undefined
evo = json.loads((DATA / "evolution_log.json").read_text())
undefined

Download Data via API

通过API下载数据

python
import requests

BASE = "https://trumpcode.washinmura.jp"
python
import requests

BASE = "https://trumpcode.washinmura.jp"

List available datasets

查看可用数据集

catalog = requests.get(f"{BASE}/api/data").json()
catalog = requests.get(f"{BASE}/api/data").json()

Download a specific file

下载指定文件

raw = requests.get(f"{BASE}/api/data/surviving_rules.json").content rules = json.loads(raw)
undefined
raw = requests.get(f"{BASE}/api/data/surviving_rules.json").content rules = json.loads(raw)
undefined

Real Code Examples

实际代码示例

Parse Today's Signals

解析今日信号

python
import requests

signals_data = requests.get("https://trumpcode.washinmura.jp/api/signals").json()

today = signals_data.get("today", {})
print("Signals fired today:", today.get("signals", []))
print("Consensus:", today.get("consensus"))        # "LONG" / "SHORT" / "NEUTRAL"
print("Confidence:", today.get("confidence"))      # 0.0–1.0
print("Active models:", today.get("active_models", []))
python
import requests

signals_data = requests.get("https://trumpcode.washinmura.jp/api/signals").json()

today = signals_data.get("today", {})
print("今日触发的信号:", today.get("signals", []))
print("一致预测:", today.get("consensus"))        # "LONG" / "SHORT" / "NEUTRAL"
print("置信度:", today.get("confidence"))      # 0.0–1.0
print("活跃模型:", today.get("active_models", []))

Find Top Performing Rules from Surviving Rules

从有效规则中筛选表现最佳的规则

python
import json

rules = json.loads(open("data/surviving_rules.json").read())
python
import json

rules = json.loads(open("data/surviving_rules.json").read())

Sort by hit rate descending

按命中率降序排序

top_rules = sorted(rules, key=lambda r: r.get("hit_rate", 0), reverse=True)
for rule in top_rules[:10]: print(f"Rule: {rule['id']} | Hit Rate: {rule['hit_rate']:.1%} | " f"Trades: {rule['n_trades']} | Avg Return: {rule['avg_return']:.3%}")
undefined
top_rules = sorted(rules, key=lambda r: r.get("hit_rate", 0), reverse=True)
for rule in top_rules[:10]: print(f"规则ID: {rule['id']} | 命中率: {rule['hit_rate']:.1%} | " f"交易次数: {rule['n_trades']} | 平均收益: {rule['avg_return']:.3%}")
undefined

Check Prediction Market Opportunities

寻找预测市场机会

python
import requests

arb = requests.get("https://trumpcode.washinmura.jp/api/insights").json()
markets = requests.get("https://trumpcode.washinmura.jp/api/polymarket-trump").json()
python
import requests

arb = requests.get("https://trumpcode.washinmura.jp/api/insights").json()
markets = requests.get("https://trumpcode.washinmura.jp/api/polymarket-trump").json()

Markets sorted by volume

按交易量排序的市场

active = [m for m in markets.get("markets", []) if m.get("active")] by_volume = sorted(active, key=lambda m: m.get("volume", 0), reverse=True)
for m in by_volume[:5]: print(f"{m['title']}: YES={m['yes_price']:.0%} | Vol=${m['volume']:,.0f}")
undefined
active = [m for m in markets.get("markets", []) if m.get("active")] by_volume = sorted(active, key=lambda m: m.get("volume", 0), reverse=True)
for m in by_volume[:5]: print(f"{m['title']}: YES={m['yes_price']:.0%} | 交易量=${m['volume']:,.0f}")
undefined

Correlate Post Features with Returns

关联帖子特征与收益

python
import json
import numpy as np

features = json.loads(open("data/daily_features.json").read())
market   = json.loads(open("data/market_SP500.json").read())
python
import json
import numpy as np

features = json.loads(open("data/daily_features.json").read())
market   = json.loads(open("data/market_SP500.json").read())

Build date-indexed return map

构建日期索引的收益映射

returns = {d["date"]: d["close_pct"] for d in market}
returns = {d["date"]: d["close_pct"] for d in market}

Example: correlate post_count with next-day return

示例:关联发帖数量与次日收益

xs, ys = [], [] for day in features: date = day["date"] if date in returns: xs.append(day.get("post_count", 0)) ys.append(returns[date])
correlation = np.corrcoef(xs, ys)[0, 1] print(f"Post count vs same-day return: r={correlation:.3f}")
undefined
xs, ys = [], [] for day in features: date = day["date"] if date in returns: xs.append(day.get("post_count", 0)) ys.append(returns[date])
correlation = np.corrcoef(xs, ys)[0, 1] print(f"发帖数量 vs 当日收益: r={correlation:.3f}")
undefined

Run a Backtest on a Custom Signal

对自定义信号进行回测

python
import json

posts    = json.loads(open("data/trump_posts_lite.json").read())
market   = json.loads(open("data/market_SP500.json").read())

returns  = {d["date"]: d["close_pct"] for d in market}
python
import json

posts    = json.loads(open("data/trump_posts_lite.json").read())
market   = json.loads(open("data/market_SP500.json").read())

returns  = {d["date"]: d["close_pct"] for d in market}

Find days with RELIEF signal before 9:30 AM ET

寻找开盘前(9:30 AM前)出现RELIEF信号的日期

relief_days = [ p["date"] for p in posts if "RELIEF" in p.get("signals", []) and p.get("hour", 24) < 9 ]
hits = [returns[d] for d in relief_days if d in returns] if hits: print(f"RELIEF pre-market: n={len(hits)}, " f"avg={sum(hits)/len(hits):.3%}, " f"hit_rate={sum(1 for h in hits if h > 0)/len(hits):.1%}")
undefined
relief_days = [ p["date"] for p in posts if "RELIEF" in p.get("signals", []) and p.get("hour", 24) < 9 ]
hits = [returns[d] for d in relief_days if d in returns] if hits: print(f"开盘前RELIEF信号: 样本数={len(hits)}, " f"平均收益={sum(hits)/len(hits):.3%}, " f"命中率={sum(1 for h in hits if h > 0)/len(hits):.1%}")
undefined

Key Signal Types

核心信号类型

SignalDescriptionTypical Impact
RELIEF
pre-market
"Relief" language before 9:30 AMAvg +1.12% same-day
TARIFF
market hours
Tariff mention during tradingAvg -0.758% next day
DEAL
Deal/agreement language52.2% hit rate
CHINA
(Truth Social only)
China mentions (never on X)1.5× weight boost
SILENCE
Zero-post day80% bullish, avg +0.409%
Burst → silenceRapid posting then goes quiet65.3% LONG signal
信号描述典型影响
RELIEF
开盘前
9:30 AM前发布含“宽慰”类语言的帖子当日平均涨幅+1.12%
TARIFF
交易时段
交易时间内提及关税次日平均跌幅-0.758%
DEAL
提及交易/协议相关内容命中率52.2%
CHINA
(仅Truth Social)
提及中国(从未在X上出现)权重提升1.5倍
SILENCE
当日无发帖80%概率上涨,平均涨幅+0.409%
爆发式发帖→沉默快速发帖后陷入沉寂65.3%概率触发LONG信号

Model Reference

模型参考

ModelStrategyHit RateAvg Return
A3Pre-market RELIEF → surge72.7%+1.206%
D3Volume spike → panic bottom70.2%+0.306%
D2Signature switch → formal statement70.0%+0.472%
C1Burst → long silence → LONG65.3%+0.145%
C3 ⚠️Late-night tariff (anti-indicator)37.5%−0.414%
Note: C3 is an anti-indicator — if it fires, the circuit breaker auto-inverts it to LONG (62% accuracy after inversion).
模型策略命中率平均收益
A3开盘前RELIEF信号→上涨72.7%+1.206%
D3交易量激增→恐慌底部70.2%+0.306%
D2发帖风格切换→正式声明70.0%+0.472%
C1爆发式发帖→长时间沉寂→LONG65.3%+0.145%
C3 ⚠️深夜提及关税(反向指标)37.5%−0.414%
注意: C3是反向指标——若触发该信号,熔断机制会自动将其反转成LONG信号(反转后准确率62%)。

System Architecture Flow

系统架构流程

Truth Social post detected (every 5 min)
    → Classify signals (RELIEF / TARIFF / DEAL / CHINA / etc.)
    → Dual-platform boost (TS-only China = 1.5× weight)
    → Snapshot Polymarket + S&P 500
    → Run 551 surviving rules → generate prediction
    → Track at 1h / 3h / 6h
    → Verify outcome → update rule weights
    → Circuit breaker: if system degrades → pause/invert
    → Daily: evolve rules (crossover / mutation / distillation)
    → Sync data to GitHub
检测到Truth Social新帖子(每5分钟一次)
    → 信号分类(RELIEF / TARIFF / DEAL / CHINA 等)
    → 双平台权重提升(仅Truth Social的China提及权重×1.5)
    → 快照Polymarket数据 + 标普500指数
    → 运行551条有效规则→生成预测
    → 按1小时/3小时/6小时跟踪结果
    → 验证结果→更新规则权重
    → 熔断机制:若系统性能下降→暂停/反转信号
    → 每日:规则进化(交叉/突变/蒸馏)
    → 同步数据至GitHub

Troubleshooting

故障排除

realtime_loop.py
not detecting new posts
  • Check your network access to Truth Social scraper endpoints
  • Verify
    data/trump_posts_all.json
    timestamp is recent
  • Run
    python3 trump_code_cli.py health
    to see circuit breaker state
chatbot_server.py
fails to start
  • Ensure
    GEMINI_KEYS
    env var is set:
    export GEMINI_KEYS="key1,key2"
  • Port 8888 may be in use:
    lsof -i :8888
overnight_search.py
runs out of memory
  • Runs ~31.5M combinations — needs ~4GB RAM
  • Run on a machine with 8GB+ or reduce search space in script config
Hit rate dropping below 55%
  • Check
    data/circuit_breaker_state.json
    — system may have auto-paused
  • Review
    data/learning_report.json
    for demoted rules
  • Re-run
    overnight_search.py
    to refresh surviving rules
Stale data in
data/
directory
  • Daily pipeline syncs to GitHub automatically if running
  • Manually trigger:
    python3 trump_code_cli.py report
    to force refresh
  • Or pull latest from remote:
    git pull origin main
realtime_loop.py
无法检测到新帖子
  • 检查Truth Social爬虫端点的网络访问权限
  • 验证
    data/trump_posts_all.json
    的时间戳是否为近期
  • 运行
    python3 trump_code_cli.py health
    查看熔断机制状态
chatbot_server.py
启动失败
  • 确保已设置
    GEMINI_KEYS
    环境变量:
    export GEMINI_KEYS="key1,key2"
  • 端口8888可能被占用:使用
    lsof -i :8888
    检查
overnight_search.py
内存不足
  • 需测试约3150万种组合——需约4GB内存
  • 在8GB+内存的机器上运行,或在脚本配置中缩小搜索范围
命中率降至55%以下
  • 查看
    data/circuit_breaker_state.json
    ——系统可能已自动暂停
  • 查看
    data/learning_report.json
    了解被降级的规则
  • 重新运行
    overnight_search.py
    刷新有效规则
data/
目录数据过时
  • 若系统正常运行,每日流水线会自动同步至GitHub
  • 手动触发刷新:运行
    python3 trump_code_cli.py report
  • 或从远程拉取最新数据:
    git pull origin main