GithubHelp home page GithubHelp logo

pangcong / blackbird Goto Github PK

View Code? Open in Web Editor NEW

This project forked from buanderie/blackbird

0.0 1.0 0.0 429 KB

Blackbird Bitcoin Arbitrage: a long/short market-neutral strategy

License: MIT License

Makefile 0.40% C++ 99.42% C 0.17%

blackbird's Introduction

Blackbird Bitcoin Arbitrage

Introduction

Blackbird Bitcoin Arbitrage is a C++ trading system that does automatic long/short arbitrage between Bitcoin exchanges.

How It Works

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 profit from 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.

Spread Example

Disclaimer

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.

Arbitrage Parameters

The two parameters used to control the arbitrage are SpreadEntry and SpreadExit.

  • SpreadEntry: the limit above which the long/short trades are triggered
  • SpreadExit: 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.

Code Information

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.

How To Test Blackbird

Note

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.

IMPORTANT: all your BTC accounts on these exchanges have to be empty before starting Blackbird.

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 as well as 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.

AGAIN, BEFORE STARTING BLACKBIRD MAKE SURE THAT YOU ARE 100% USD AND 0% BTC ON EACH OF YOUR EXCHANGES.

Credentials

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.

Strategy parameters

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,

Risk parameters

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.

E-mail parameters (optional)

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.

Run the software

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 &

Tasks And Issues

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.

Changelog

May 2015
  • First release
July 2015
  • 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
September 2015
  • 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
October 2015
  • 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
November 2015
  • Trailing spread implemented

Links

License

Contact

  • 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]

Console Output Example

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%]

blackbird's People

Contributors

julianmi avatar natebrune avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.