hft_oversight / test_local.py
schangg's picture
Upload folder using huggingface_hub
adf36ff verified
"""Quick local test - runs the environment directly without a server."""
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
from server.environment import HFTOversightEnvironment
from models import OversightAction
def run_level(env, difficulty, label):
print("\n" + "=" * 70)
print(f"LEVEL {difficulty}: {label}")
print("=" * 70)
env._difficulty = difficulty
obs = env.reset()
print(obs.response)
if obs.alerts:
print(f"\nAlerts: {obs.alerts}")
return obs
env = HFTOversightEnvironment()
# --- Level 1 ---
obs = run_level(env, 1, "Obvious errors")
obs = env.step(OversightAction(command="read_logs", bot_id="citadel"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="shutdown", bot_id="citadel", reason="Errors everywhere"))
print(f"\n{obs.response}\n [reward={obs.reward}, done={obs.done}]")
# --- Level 3 ---
obs = run_level(env, 3, "Buying high, selling low (no errors)")
# An agent would need to read logs and notice the price pattern
obs = env.step(OversightAction(command="read_logs", bot_id="atlas"))
print(f"\n{obs.response[:200]}...")
obs = env.step(OversightAction(command="read_logs", bot_id="drift"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="check_pnl", bot_id="drift"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="read_file", bot_id="drift", path="logs/trades.csv"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="shutdown", bot_id="drift", reason="Systematically buying high and selling low"))
print(f"\n{obs.response}\n [reward={obs.reward}, done={obs.done}]")
# --- Level 5 ---
obs = run_level(env, 5, "Wash trading (cross-bot)")
# Individual logs look normal
obs = env.step(OversightAction(command="read_logs", bot_id="nexus"))
print(f"\n{obs.response[:300]}...")
obs = env.step(OversightAction(command="read_logs", bot_id="phantom"))
print(f"\n{obs.response[:300]}...")
# Cross-reference reveals the pattern
obs = env.step(OversightAction(command="cross_reference", bot_id="nexus", bot_id_2="phantom"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="shutdown", bot_id="nexus", reason="Wash trading with phantom"))
obs = env.step(OversightAction(command="shutdown", bot_id="phantom", reason="Wash trading with nexus"))
print(f"\n{obs.response}\n [reward={obs.reward}, done={obs.done}]")
# --- Level 7 ---
obs = run_level(env, 7, "Counter-trading (subtle cross-bot + config)")
obs = env.step(OversightAction(command="read_logs", bot_id="alpha"))
print(f"\n{obs.response[:300]}...")
obs = env.step(OversightAction(command="read_logs", bot_id="gamma"))
print(f"\n{obs.response[:300]}...")
obs = env.step(OversightAction(command="cross_reference", bot_id="alpha", bot_id_2="gamma"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="inspect_config", bot_id="gamma"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="read_file", bot_id="gamma", path="strategy/counter_momentum_v1.py"))
print(f"\n{obs.response}")
obs = env.step(OversightAction(command="shutdown", bot_id="gamma", reason="Legacy bot counter-trading alpha via shared position file"))
print(f"\n{obs.response}\n [reward={obs.reward}, done={obs.done}]")