Designing a Broker-Agnostic API Layer in Elixir

Four Elixir behaviours keep a production trading pipeline completely broker-agnostic — not one big interface but four, each with a distinct responsibility. The dispatch mechanism stores the broker module as an atom in the database and calls behaviour callbacks directly on it: no case statements, no pattern matching on broker types, just function dispatch to whatever module is configured for the session. The post also covers partial implementations (brokers that do market data but not order execution), auth isolation that ranges from standard OAuth2 to a username/password flow with a push-based token refresh model, and two things in the design I’d change now.

2 Likes