This is a simple implementation of arbitrage project where currently triangular arbitrage is implemented. The Bellman-Ford algorithm is used to detect tradeable cycles. Right now, this is not a complete trading bot — there’s no order execution or risk management yet — but it’s a clean starting point for anyone who wants to step foot into implementing such project with Go language.
Basically we are going to solve the following problem.
If there are three pairs and exchange rates like this:
-
$R_{12}$ : from currency USDT → BTC -
$R_{23}$ : from currency BTC → ETH -
$R_{31}$ : from currency ETH → USDT
We also take fees into account:
The condition for arbitrage is:
Now applying negative logarithm to both side:
This condition corresponds to detecting negative cycles in the Bellman-Ford algorithm. In a Bellman-Ford graph with weights
- Only supports Binance exchange
- Based on the REST API (slow compared to WebSockets)
- No order execution / trading support
- No risk management
- Uses govalues/decimal as a replacement for
float64, with an added wrapper to supportInfinity - Rate limiting via a custom Limiter to control HTTP request frequency to the exchange
- Efficient use of Go goroutines to burst requests when needed (e.g., Depths, Klines, etc.)
- Simple configuration file (TOML format)
Clone the repository:
git clone https://github.com/0xarash/arbitrage.git
cd arbitrageInstall dependencies:
go mod tidyOr build and run:
go build -o arbitrage
./arbitrageThe project uses a simple config file (config.toml). Below is an example of such config file.
[arbitrage]
start_currencies = ["USDT"]
[ranking]
volume_threshold = 1_000_000
top_pairs = 500
ignore_zero = true
[worker]
concurrency = 8
[limiter]
weight_kline = 2
weight_depth = 5
[binance]
trading_fee = 0.001