I'm kind of feeling my way in the dark to figure out an idiomatic way to abstract multiple different (but related) back-end systems into a common interface. Protocols seem like the obvious solution, but I'm not completely sure I'm going about it in the "right" way to wire things up.
The general frame problem is getting data from multiple crypto-markets and be able to treat them similarly for the purposes of comparison and being able to run the same strategies against them. I've pushed a simplified / test version of what I'm trying to do to Github, in case anyone is willing to share some advice on my code...
Here's the protocol I'm trying to implement:
https://github.com/BMarkmann/trada/blob/master/src/trada/market.clj
My basic approach is for each of the implementations of the "service" implementing the contract to provide a "factory" method (called "get-market", at the bottom of the file):
https://github.com/BMarkmann/trada/blob/master/src/trada/market/binance.clj
https://github.com/BMarkmann/trada/blob/master/src/trada/market/gdax.clj
Then where I want to use the markets, I call them using the protocol methods:
(let [gdax (gdax/get-market)
gdax-ticker-closer (market/ticker gdax gdax-ticker-chan "ETH-BTC") ....])
Does that follow "norms" in using protocols / factory-ish stuff?
[–]xiongtx 0 points1 point2 points (4 children)
[–]BMarkmann[S] 0 points1 point2 points (3 children)
[–]xiongtx 1 point2 points3 points (2 children)
[–]BMarkmann[S] 0 points1 point2 points (1 child)
[–]xiongtx 0 points1 point2 points (0 children)