Loading...
Every trading agent has the same bones: load state, fetch data, evaluate signal, act, save state. Loop.
while True:
balance = fetch_balance()
state.last_balance = balance.stable
positions = list(state.positions)
if positions:
evaluate_exits(state) # check trailing stop, take profit, etc.
else:
candidates = scan_universe()
best = pick_best(candidates)
if best and passes_gates(best):
execute_entry(state, best)
save_state(state)
sleep(poll_sec)That's it. Our YOLO agents in production use this exact shape with ~650 lines of gates, error handling, and rails, but the core loop fits in 10 lines.
Write a skeleton function that implements this loop structure (using stubs for the exchange calls).