MIT Crypto Trading Competition Win
MIT Crypto Trading Competition Win
565 1
MIT students recently had the opportunity to peer into this profitable world
of crypto trading, and compete in our own small version of it.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 1/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
The month long crypto trading workshop at MIT was sponsored by MIT’s Bitcoin club and Celo.
This post is an overview of what we learned about the markets and arbitrage
strategies that make crypto trading profitable, as well as how I used those
strategies to win the crypto trading competition to take home some cash.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 2/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
How Celo uses a price stability protocol to control the volatility of its
crypto assets and maintain a stable token (i.e. a cryptocurrency that is
pegged to a fiat currency such as the US dollar)
Centralized exchanges
Centralized exchanges manage trades between buyers (B) and sellers (S).
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 3/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Like traditional financial markets, many of the large exchanges support limit
and stop orders. They also provide APIs — application programming
interfaces that make it possible to write code that trades on behalf of its
programmer. While people can submit manual trades on these platforms,
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 4/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 5/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
million in Bitcoin due to a hack in 2014. Most of the lost bitcoins were their
customers’.
Decentralized Exchanges
Decentralized exchanges allow buyers (B) and sellers (S) to trade peer-to-peer.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 6/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
There are also decentralized exchanges (DEX), such as Etherdelta and IDEX.
These are open source platforms with no central authority, where traders
can exchange currencies on a peer-to-peer basis. They allow users to
maintain control of their funds (and anonymity), which makes them more
resistant to hacks. They are also more difficult to use, and so have lower
trade volume than centralized exchanges, which has kept their fees higher.
Most trades are still conducted on centralized exchanges.
While most exchanges maintain order books and facilitate matches between
buyers and sellers, these alternative systems use smart contracts to hold
liquidity reserves of various tokens, and execute trades directly against these
reserves.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 7/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
The product
x∗y=k
Source: https://ethresear.ch/t/improving-front-running-resistance-of-x-y-k-market-makers/1281
“The idea is that you have a contract that holds x coins of token A and y coins of
token B, and always maintains the invariant that x∗y=k for some constant k.
Anyone can buy or sell coins by essentially shifting the market maker’s position on
the x∗y=k curve; if they shift the point to the right, then the amount by which they
move it right is the amount of token A they have to put in, and the amount by
which they shift the point down corresponds to how much of token B they get out.”
— Vitalik Buterin, Ethereum Founder.
The token exchange price is then determined by the ratio x:y in the pair of
token reserves. Naturally, the market drives this ratio towards a price that
matches that of the other token exchanges. If the ratio did not match the
exchange rate on other exchanges, then there would be a price differential
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 8/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Note that the exchange rate for tokens in an “x∗y=k” model changes with
each trade, because each trade alters the ratio of tokens. This creates a
continuous “slippage” that can be mathematically determined prior to the
trade.
The “x*y=k market maker” operates “on-chain”. The exchanges that operate
by this model are decentralized, and trades are automated by smart
contracts (e.g. see Uniswap’s smart contracts). Those who supply the initial
liquidy for the token reserves can then reap yields. A small fee (0.3% for
Uniswap) is taken out of each trade and added to the reserves, generating the
yield for the liquidity providers, as well as increasing the overall quantity of
reserves. Increasing the size of the reserves increases the stability of the
exchange rate between tokens, because a larger trade is then required to
alter the ratio between tokens.
Arbitrage
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 9/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
2 token B → 1 token A
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 10/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Arbitrage is a set of transactions that involve no negative cash flow, and only
positive cashflow. An arbitrage cycle, such as the example 2-leg cycle, is a
series of trades that generates a “riskless” profit.
In practice, 2-leg arbitrage and other trading strategies that require moving
assets between exchanges are risky and not well suited for cryptocurrency
markets. Moving assets between exchanges means withdrawing funds from
one exchange, making a transaction on the blockchain, and then depositing
the funds in another exchange to complete the next transaction. Each of
these steps incurs fees and are time intensive. In the time it takes for a
transaction to complete on the blockchain, a profitable opportunity can
disappear. Executing a series of transactions within a single centralized
exchange is much faster, and arbitrage opportunities can still be found
within a single exchange.
Triangular arbitrage — my messy notes from a session with a professional crypto trader during Celo’s crypto
trading workshop.
Similar to 2-leg arbitrage cycles, traders can find arbitrage cycles with more
legs. For example, an arbitrage cycle with 3 legs, known as “triangular
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 11/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Finding arbitrage cycles can be done by analyzing graphs — from a presentation by Celo during their crypto
trading workshop.
different prices across the two exchanges in order to take a short position
where the asset is more expensive, and a long position where the asset is
cheaper.
Every so often, the trader withdraws or deposit funds on the two exchanges
in order to rebalance the values in the accounts or extract their profits.
buys token A for token B on exchange X & sells token A for token B on exchange Y
sells token A for token B on exchange X & buys token A for token B on exchange Y
There are many more arbitrage strategies, such as those that capitalize on
price differentials over time. However, the professional crypto traders that
joined Celo’s workshop had found their financial successes through the
arbitrage strategies presented above. These same strategies were useful in
Celo’s crypto trading competition that I and the other workshop participants
competed in.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 14/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Celo has two crypto assets and uses them in a clever protocol in order to
algorithmically address the price stability problem:
The Celo Dollar token (cUSD) is a stable token that is pegged to the US dollar
(USD). It has an elastic supply.
The Celo Gold token (cGLD) has a fixed supply, but its value is allowed to
vary.
Celo Gold is used to help control the circulation of the Celo Dollar and keep
its value pegged to the value of USD. Celo’s protocol does this by
automatically adjusting the supply of Celo Dollars by buying or selling Celo
Dollars (cUSD) for Celo Gold (cGLD).
Let’s briefly revisit Economics 101 with the Celo Dollar as the commodity of
interest:
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 15/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
When there is more demand than supply for the Celo Dollar, its price is
pushed up above $1. On the other hand, when the supply exceeds the
demand then the price is pushed below $1.
Expansions
When the price of Celo Dollars is greater than $1, the protocol expands the
supply of Celo Dollars until the market price for the Celo Dollar is $1. These
expansions are handled by a smart contract that creates new Celo Dollars
and sells them on the open market in exchange for Celo Gold and other
crypto assets that it puts in Celo’s reserve.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 16/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Contractions
When the market price of Celo Dollars is less than $1, the protocol contracts
the supply of Celo Dollars until the market price reaches $1. To contract the
Celo Dollar supply, the protocol purchases Celo Dollars from the open
market with Celo Gold and other assets in the reserve, and then “burns” the
Celo Dollars.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 17/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Sealed bids — Bids submitted by traders are hidden until the auction bidding
stage is complete. Since traders cannot see each others submissions for in-
progress auctions, they must instead use past auction bid prices to
determine their optimal next bid. (Another blogpost could be written about
how the wonders of cryptography allow for the design of sealed-bid auction
protocols).
Multi-unit — Traders can bid on any fraction of the total pool of assets being
auctioned off. Different portions of the pool can sell for different prices, and
traders can even submit multiple bids at different price points. For example,
if 2 cUSD is being auctioned off, 1.5 units of cUSD may go to a bidder who
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 18/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
bids at a 1 cUSD / 3 cGLD exchange rate, while the remaining 0.5 units goes
to a bidder who bid at a 1 cUSD / 2 cGLD exchange rate.
Capped — Each auction has a limit (“cap”) to the amount of Celo Dollars that
will be bought or sold. Submitted bids are ordered by price, from highest to
lowest, and the auction then fills those bids in order until the cap is reached.
For example, in an expansion with a cap of 100 cUSD (i.e. the auction is
selling a total of 100 cUSD for cGLD to the highest bidders), the following
bids might be placed:
These bids are ordered by the highest cGLD / cUSD rates to the lowest, and
filled until the 100 cUSD cap is reached:
Filled
(c: partial) 20 cGLD for 20 cUSD (1 / 1 rate) — 100 cUSD cap reached
Not filled
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 19/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Game Mechanics
25 cUSD
25 cGLD
The winner of the competition would be the one with the most value in their
wallet at the end of the month. The prize was payment of the wallet’s value in
US Dollars, plus a $1000 added bonus for the winner. (Celo also awarded bug
bounties).
1. Auction
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 20/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
A Celo auction ran once an hour, on the hour. Traders could bid to either buy
or sell cUSD for cGLD, depending on whether the auction was performing a
market expansion or contraction. Because the auction was capped, not all
bids could be filled, so traders bid in direct competition with one another.
Bids that were too low were not filled. There was a small cost to bidding, as a
small transaction fee (“gas”) was always extracted by the Ethereum network.
2. Exchange
There was also an exchange that operated by the x∗y=k model. The exchange
held reserves of Celo Dollars (cUSD) and Celo Gold (cGLD) and could be used
at any time to trade between the two assets. The exchange rate between
cUSD and cGLD was simply the ratio of the quantities of these two assets in
the exchange reserves. This exchange rate established the understood value
of cGLD relative to cUSD at any given time.
The total value of any heterogeneous quantity of cUSD and cGLD could be
computed by using the exchange rate to value the cGLD in terms of cUSD,
and then evaluating the resulting total cUSD value in dollars, since the value
of cUSD is pegged to $1.
For example, if my wallet contained 100 cUSD, 200 cGLD, and the exchange
rate for cUSD / cGLD = 1 / 2, then my wallet had a value of:
=> $200
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 21/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Arbitrage Algorithms
I programmed an algorithm that ran around the clock by using Celo’s SDK
and hacking on some of their sample code. By the end of the competition it
had net a profit of about $500 after starting off with about $50 of crypto.
The algorithm’s approach to profit was simple, like 2-leg arbitrage: “buy low,
sell high”. If tokens can be bought in an auction and then sold on the
exchange for a higher rate, then profit can be made. The implementation
involved the following ideas and variables:
Balance
Bid discount
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 22/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Bid adjustment
Success streak
Balance — Remember how at any given time, the cUSD / cGLD exchange rate
is determined by the ratio of these two tokens in the exchange operating by
thex∗y=k model. The value of cGLD in my wallet can then be calculated in
terms of cUSD by simply multiplying its quantity by the exchange rate.
However, this value is subject to change with the exchange rate, and the
exchange rate moves with each trade, since each trade alters the ratio of
tokens in the reserves of the x∗y=k model. This makes the total value of my
wallet precarious. To minimize risk, I kept the value of cUSD and cGLD in my
wallet “balanced”. I kept a target balance of 50 / 50 such that about 50% of the
total value in the wallet was in cUSD, the other 50% cGLD.
After each auction closed, the algorithm checked the cUSD / cGLD exchange
rate, and recalculated the value ratios of cUSD / cGLD in my wallet. If the
ratio had deviated from the 50 / 50 target by a given threshold (10%), then I
traded with the exchange so that the target balance was restored.
Bid discount — profit could be made from the auctions by placing bids at a
“discount” to the exchange rate, and then trading the auctioned tokens at the
exchange for the exchange rate (less slippage). For example, suppose the
cUSD / cGLD exchange rate was 1 / 2, and the action was an expansion,
auctioning off cUSD for cGLD. With a bid discount of 1.1, I would bid for
cUSD in the auction at a 1.1 / 2 rate for cUSD / cGLD. If my bids were
successful, I could then trade the cUSD I had won back on the exchange for
the 1 / 2 rate, gaining a profit of 0.1 cUSD for 1 cUSD unit traded.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 23/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
The higher the bid-discount, the higher the profit margin. However, too high
a bid-discount jeopardized making any profit at all, because other traders
would outbid. Getting outbid was a loss: There was the opportunity cost of
not successfully participating in the hourly auction, as well as the
transaction fees consumed by the network for transacting with the auction.
Minimum bid discount — The bid-discount was never allowed to fall below a
minimum value (e.g. ~1.01) even if this meant being outbid. Bidding in the
auction was not profitable below this value.
Now, for a simple algorithm that used these variables (in pseudocode). Note
that exchange rate could be in terms of cGLD or cUSD, depending on which
is being auctioned off.
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 25/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
Alex Berke in MIT MEDIA LAB Celo Foundation in The Celo Blog
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 26/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
38 min read · Jan 22, 2020 4 min read · Apr 22, 2024
192 111
146 3
See all from Alex Berke See all from The Celo Blog
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 27/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
182 420 5
Lists
Modern Marketing
136 stories · 634 saves
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 28/29
5/19/24, 10:31 PM Arbitrage and Winning a Cryptocurrency Trading Competition at MIT | by Alex Berke | The Celo Blog
112 2
Bluestock SR
52 30 3
https://blog.celo.org/arbitrage-and-winning-a-cryptocurrency-trading-competition-at-mit-32e183766e42 29/29