Blackbird Bitcoin Arbitrage is a C++ trading system that does automatic long/short arbitrage between Bitcoin exchanges.
Bitcoin is still a new and inefficient market. Several Bitcoin exchanges exist around the world and the proposed prices (bid and ask) can be briefly different from an exchange to another. The purpose of Blackbird is to automatically exploit these temporary price differences.
Here is an example with real data. Blackbird analyzes the bid/ask information from two Bitcoin exchanges, Bitfinex and Bitstamp, every few seconds. At some point the spread between Bitfinex and Bitstamp prices is higher than an ENTRY
threshold (first vertical line): an arbitrage opportunity exists and Blackbird buys Bitstamp and short sells Bitfinex.
Then, about 4.5 hours later the spread decreases below an EXIT
threshold (second vertical line) so Blackbird exits the market by selling Bitstamp and buying Bitfinex back.
USE THE SOFTWARE AT YOUR OWN RISK. YOU ARE RESPONSIBLE FOR YOUR OWN MONEY. PAST PERFORMANCE IS NOT NECESSARILY INDICATIVE OF FUTURE RESULTS. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.
BEFORE STARTING BLACKBIRD MAKE SURE THAT YOU ARE 100% USD AND 0% BTC ON EACH OF YOUR EXCHANGES.
The two parameters used to control the arbitrage are SpreadEntry
and SpreadExit
.
SpreadEntry
: the limit above which the long/short trades are triggeredSpreadExit
: the limit below which the long/short trades are closed
SpreadEntry
is actually the limit after the exchange fees which means that SpreadEntry
represents the net profit. If two exchanges have a 0.20% fees for every trade then we will have in total:
- 0.20% entry long + 0.20% entry short + 0.20% exit long + 0.20% exit short = 0.80% total fees
Note: the actual total will be slightly different since it is a percentage of each individual trade.
Now if the profit we target is 0.30% ("SpreadEntry": 0.0030
) then Blackbird will set the entry threshold at 1.10% (0.80% total fees + 0.30% target).
Defining a smaller spread will generates more trades but with less profit each.
Blackbird uses the base64 functions written by René Nyffenegger to encode and decode base64 in C++. Thank you René your code works well with Blackbird.
The trade results are stored in CSV files. A new CSV file is created every time Blackbird is started.
It is possible to properly stop Blackbird after the next trade has closed. While Blackbird is running just create an empty file called stop_after_exit in the working directory. This will make Blackbird automatically stop after the next trade closes.
Please make sure that you understand the disclaimer above if you want to test Blackbird with real money. You can start by testing with a limited amount of money, like $25 per exchange.
Note that it is never entirely safe to just tell Blackbird to use only $25 per exchange (parameter CashForTesting
). You also need to only have $25 available on each of your trading accounts and 0 BTC. In this case you are sure than even if a bug with CashForTesting
exists your maximum loss on an exchange won't be greater than $25 no matter what.
BEFORE STARTING BLACKBIRD MAKE SURE THAT YOU ARE 100% USD AND 0% BTC ON EACH OF YOUR EXCHANGES.
As of today the exchanges fully implemented are Bitfinex, OKCoin, Bitstamp and Gemini. For each of your exchange accounts you need to create API authentication keys. This is usually done in the Settings section of your accounts.
Then, you need to add your keys in the file config.json. Never share this file as it will contain your personal exchange credentials! If you don't have an account for one of the exchanges just leave it blank. But you need at least two exchanges and as of today one of them has to be Bitfinex.
Modify the stategy parameters to match your trading style (few trades with high spreads or many trades with low spreads):
"SpreadEntry": 0.0020,
"SpreadExit": -0.0020,
If you set UseFullCash
at true
then Blackbird will use the minimum cash on the accounts of your two trades, minus a small percentage defined by UntouchedCash
.
For example, if you have:
"UseFullCash": true,
"UntouchedCash": 0.01,
"CashForTesting": 25.00,
"MaxExposure": 25000.00,
And let's say you have $1,000 on your Bitfinex trading account and $1,100 on your OKCoin trading account. Blackbird will then use $990 on each exchange (i.e. $1,000 - 1%) so your total exposure will be $1,980. Now if you change UseFullCash
to false
then Blackbird will use $25 per exchange (total exposure $50).
MaxExposure
defines the maximum cash exposure on each exchange. In the example above the maximum size of a trade will be $25,000 per exchange.
Blackbird can send you an automatic e-mail every time an arbitrage trade is completed. The e-mail contains information like the names of the traded exchanges and the trade performance.
This feature is optional. If you let the parameter SendEmail
to false
then you don't need to fill the other e-mail parameters.
You need the following libraries: Crypto, Jansson v2.7, cURL and sendEmail.
Note: you need Jansson version 2.7 minimum otherwise you will get the following compilation error: 'json_boolean_value' was not declared in this scope
For instance on Ubuntu you need to install the following libaries:
libssl-dev
libjansson-dev
libcurl4-openssl-dev
sendemail
Build the software by typing:
make
Then start the software:
./blackbird
Alternatively, you may want to start it in the background:
./blackbird > output.txt &
Please check the issues page for the current tasks and issues. If you face any problems with Blackbird please open a new issue on that page.
- First release
- Bitstamp exchange added
- Kraken exchange added (bid/ask information only, other functions to be implemented)
- Improved JSON and cURL exceptions management
- Added the milliseconds to the nonce used for exchange authentification
- JSON memory leak fixed
- Minor fixes and improvements
- General performance and stability improvements (merge from julianmi:performance_improvements)
- ItBit exchange added (bid/ask information only, other functions to be implemented)
- Minor fixes and improvements
- Gemini exchange added and fully implemented
- No need to have accounts on all the exchanges anymore
- Bug #16 (nonce too small) fixed
- Bug #19 (process hangs) fixed
- Minor fixes and improvements
- Trailing spread implemented
- If you found a bug, please open a new issue with the label bug
- If you have a general question or have troubles running Blackbird, you can open a new issue with the label question or help wanted
- For anything else you can directly contact me by email: [email protected]
This is what Blackbird looks like when it is started:
Blackbird Bitcoin Arbitrage
DISCLAIMER: USE THE SOFTWARE AT YOUR OWN RISK.
[ Targets ]
Spread to enter: -0.20%
Spread to exit: -0.20%
[ Current balances ]
Bitfinex: 1,857.79 USD 0.000000 BTC
OKCoin: 1,801.38 USD 0.000436 BTC
Bitstamp: 1,694.15 USD 0.000000 BTC
Gemini: 1,720.38 USD 0.000000 BTC
[ Cash exposure ]
FULL cash used!
[ 10/31/2015 08:32:45 ]
Bitfinex: 325.21 / 325.58
OKCoin: 326.04 / 326.10
Bitstamp: 325.37 / 325.82
Gemini: 325.50 / 328.74
----------------------------
OKCoin/Bitfinex: -0.27% [target 1.00%, min -0.27%, max -0.27%]
Bitstamp/Bitfinex: -0.19% [target 1.10%, min -0.19%, max -0.19%]
Gemini/Bitfinex: -1.07% [target 1.10%, min -1.07%, max -1.07%]
[ 10/31/2015 08:32:48 ]
Bitfinex: 325.21 / 325.58
OKCoin: 326.04 / 326.10
Bitstamp: 325.39 / 325.68
Gemini: 325.50 / 328.67
----------------------------
OKCoin/Bitfinex: -0.27% [target 1.00%, min -0.27%, max -0.27%]
Bitstamp/Bitfinex: -0.14% [target 1.10%, min -0.19%, max -0.14%]
Gemini/Bitfinex: -1.05% [target 1.10%, min -1.07%, max -1.05%]