5.3 Example Consumers
import requests
import time
API_URL = "http://localhost:8000/opportunities"
def fetch_opportunities():
r = requests.get(API_URL, timeout=2)
r.raise_for_status()
return r.json()
def main():
while True:
opps = fetch_opportunities()
for opp in opps:
if opp["profit_bps"] >= 50:
process_profitable_opportunity(opp)
time.sleep(2)
def process_profitable_opportunity(opp):
# Your own logic: log, alert, execute, etc.
print("Profitable:", opp)
if __name__ == "__main__":
main()Last updated

