Batch swap matcher
Traders who want to swap Bitcoin, Ethereum and Monero are matched with each other at one fair price per coin, with Kraken’s live market as the fallback. Add some traders, run the batch, and compare it with the alternatives.
Live prices
Streamed from Kraken by the Java price server over WebSocket. Bid = what you can sell for, ask = what you pay to buy.
Who wants to trade
Fake traders for the demo. Each one gives up an amount of one coin for another and says how far from the market price they will go (−1% = “I accept up to 1% less than market”).
| Name | Gives | Amount | Wants | Tolerance % | Worth | Worst rate accepted | Alone on Kraken | |
|---|---|---|---|---|---|---|---|---|
| No traders yet. Pick a scenario above or add one. | ||||||||
How it works
The idea in four steps.
- Collect orders into a batch. Instead of filling each order the moment it arrives, the system gathers everyone who wants to swap over a short window. Each person says what they give, what they want, and the worst rate they will accept.
- Find who can swap with whom. If Alice has Monero and wants Bitcoin while Erin has Bitcoin and wants Monero, they can simply swap: a coincidence of wants. Often there is no direct partner, but there is a loop: XMR → BTC → ETH → XMR. A ring trade lets all of them swap at once.
- Set one fair price per coin. The algorithm picks a single price for each coin that clears the whole batch at once. Everyone buying Bitcoin pays the same price, whoever they are and whenever they joined.
- Use Kraken only for the leftovers. If more of one coin is offered than wanted, Kraken takes the rest at its real, live price. So the batch is never worse than going to Kraken directly, and whatever is matched between traders skips Kraken’s spread and fees.
Why this is the best possible outcome
What “best” means, and how each claim is checked on every run.
1. Never worse than Kraken
Kraken sits inside every batch as a participant, quoting its real bid, ask and fees. Any trader whose order Kraken would fill gets at least Kraken’s price. Usually more, because matching with another trader avoids the spread and the fee on both legs.
2. One price for everyone
There is a single clearing price per coin, and prices are consistent across pairs, so there is no arbitrage loop inside the batch. Nobody pays more than anyone else for the same thing, and nobody ever trades past the limit they set.
3. The market clears
If the price beats your limit, your whole order is filled. Only the side with more on offer than anyone wants can be partly filled, and only at exactly its own limit. Economists call this a competitive equilibrium: the outcome of a perfectly fair auction.
4. No one can beat it
No group of traders could leave the batch, trade among themselves, and all come out ahead. A standard theorem says an equilibrium has this property (it is in the core). The page checks it two ways: a certificate that verifies the equilibrium conditions, and a brute-force search over every group of traders.
5. The most value among fair outcomes
Several sets of prices can satisfy all of the above. The optimiser (SCIP, a global solver) picks the one where traders gain the most in total above their limits, and proves no better one exists rather than settling for a good guess.
Compare: the alternatives fail
Kraken alone charges a spread and a fee on every leg; Monero to Ethereum pays both twice. Greedy matching settles the best loop first and prices each loop separately, so the same coin trades at different prices. The checklist above shows, on your own data, a group that could walk away from each of them.