54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
import argparse
|
|
|
|
from .adapters import PriceFeedAdapter, BrokerAdapter
|
|
from .coordinator import CentralCoordinator
|
|
from .core import AuditLog
|
|
|
|
|
|
def run_demo(iterations: int = 5) -> None:
|
|
# Simple two-venue scenario using the toy adapters
|
|
adA = PriceFeedAdapter("VenueA", ["AAPL", "MSFT"])
|
|
adB = PriceFeedAdapter("VenueB", ["AAPL", "MSFT"])
|
|
brokerA = BrokerAdapter("VenueA")
|
|
brokerB = BrokerAdapter("VenueB")
|
|
|
|
coord = CentralCoordinator()
|
|
log = AuditLog()
|
|
|
|
for i in range(iterations):
|
|
pA, sA = adA.step()
|
|
pB, sB = adB.step()
|
|
planA = coord.ingest_local(pA, sA)
|
|
planB = coord.ingest_local(pB, sB)
|
|
if planA:
|
|
resA = brokerA.execute(planA)
|
|
log.log(f"VenueA executed plan: {resA}")
|
|
if planB:
|
|
resB = brokerB.execute(planB)
|
|
log.log(f"VenueB executed plan: {resB}")
|
|
# Simulate a reconnect/reconcile step every 3 iterations
|
|
if (i + 1) % 3 == 0:
|
|
recon = coord.reconcile()
|
|
if recon:
|
|
log.log(f"Reconciled plan: {recon.to_dict()}")
|
|
time.sleep(0.05)
|
|
|
|
# Print log
|
|
for i, e in enumerate(log.entries):
|
|
print(f"LOG {i}: {e}")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--iterations", type=int, default=5, help="Number of iterations in demo")
|
|
args = parser.parse_args()
|
|
run_demo(args.iterations)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|