Crypto arbitrage‎ > ‎

working4arbitrage

Introduction

This script downloads full market depth on several exchanges and detects triangular arbitrage opportunities.
Please don't download data too often (use flag --nodownload).

Help

$ python w4arbitrage.py
usage: w4arbitrage.py [-h] [--nodownload] [--printjson] [--printmk]
                      [--nocalculate] [--plot] [--pmin PMIN] [--pmax PMAX]
                      [--showstats] [--markets MARKETS] [--loop LOOP]
                      [--action ACTION] [--reldiff RELDIFF]
                      [--currency1 CURRENCY1] [--direction DIRECTION]
                      [--requested_cur1_amount REQUESTED_CUR1_AMOUNT]
                      [--requested_cur2_amount REQUESTED_CUR2_AMOUNT]
                      [--sendemail] [--sendpush] [--debug] [--test]

Use the following parameters

optional arguments:
  -h, --help            show this help message and exit
  --nodownload          use this flag to avoid downloading orderbook (will use
                        a previously downloaded file)
  --printjson           use this flag to pretty print JSON
  --printmk             use this flag to print market
  --nocalculate         use this flag to disable calculus with DataFrame
  --plot                use this flag to display order book depth graph
  --pmin PMIN           use this flag to define price min to plot
  --pmax PMAX           use this flag to define price max to plot
  --showstats           use this flag to show market stats
  --markets MARKETS     use this flag to define markets
  --loop LOOP           use this flag to run program in an infinite loop (LOOP
                        parameters is pause in seconds)
  --action ACTION       use this flag to set 'arbitrage' mode or to reply to
                        'howmuch' question or just 'printmk' to print market
                        order book
  --reldiff RELDIFF     use this flag to show only arbitrage opportunities >=
                        reldiff (%)
  --currency1 CURRENCY1
                        use this flag to set arbitrage size (in currency 1 =
                        BTC)
  --direction DIRECTION
                        use this flag to set how much direction
  --requested_cur1_amount REQUESTED_CUR1_AMOUNT
                        use this flag to set how much cur1 is requested
  --requested_cur2_amount REQUESTED_CUR2_AMOUNT
                        use this flag to set how much cur2 is requested
  --sendemail           use this flag to send email when arbitrage
                        opportunities are found
  --sendpush            use this flag to send push notification
  --debug               use this flag to switch to debug mode
  --test                use this flag to test notifications (email, SMS, push)

Sample

$ python w4arbitrage.py --markets "vcx|BTC/USD intrsng|BTC/USD cbx|BTC/USD bc|BTC/USD rock|BTC/USD bitme|BTC/USD btc24|BTC/USD bitfloor|BTC/USD btce|BTC/USD bitstamp|BTC/USD mtgox|BTC/USD" --action arbitrage --currency1 20 --plot --reldiff 2

===== Running 2013-04-15 18:05 =====
Reading order book (full depth) for BTC/USD at vcxBTCUSD from file "data_in/vcxBTCUSD.json"
Reading order book (full depth) for BTC/USD at intrsngBTCUSD from file "data_in/intrsngBTCUSD.json"
Can't plot
  Can't get bid price for intrsng|BTC/USD (market is probably not big enough)
  Can't get ask for price intrsng|BTC/USD (market is probably not big enough)
Reading order book (full depth) for BTC/USD at cbxBTCUSD from file "data_in/cbxBTCUSD.json"
Reading order book (full depth) for BTC/USD at bcBTCUSD from file "data_in/bcBTCUSD.json"
  Can't get bid price for bc|BTC/USD (market is probably not big enough)
Reading order book (full depth) for BTC/USD at rockBTCUSD from file "data_in/rockBTCUSD.json"
Reading order book (full depth) for BTC/USD at bitmeBTCUSD from file "data_in/bitmeBTCUSD.json"
  Can't get ask for price bitme|BTC/USD (market is probably not big enough)
Reading order book (full depth) for BTC/USD at btc24BTCUSD from file "data_in/btc24BTCUSD.json"
Reading order book (full depth) for BTC/USD at bitfloorBTCUSD from file "data_in/bitfloorBTCUSD.json"
Reading order book (full depth) for BTC/USD at btceBTCUSD from file "data_in/btceBTCUSD.json"
Reading order book (full depth) for BTC/USD at bitstampBTCUSD from file "data_in/bitstampBTCUSD.json"
Reading order book (full depth) for BTC/USD at mtgoxBTCUSD from file "data_in/mtgoxBTCUSD.json"
========== Tickers for 20.00000000BTC ==========
                        bid         ask nb_asks asks_cur2_amount_cum_max asks_cur1_amount_cum_max nb_bids bids_cur1_amount_cum_max bids_cur2_amount_cum_max     spread
mtgox|BTC/USD     95.402253   95.777746    4504             1.410672e+13                 142433.1    7041             4.379787e+07             1.460781e+07   0.375493
bitstamp|BTC/USD  92.567288   93.000000     707                  1703179                 9204.062     469                 49326.14                 659208.6   0.432712
cbx|BTC/USD       94.595836  100.077972     119                 147634.9                 804.4627     160                 2040.277                 79075.07   5.482136
btc24|BTC/USD     68.985571   92.984579      71                 622348.1                  265.425      83                 1918.491                 18779.23  23.999007
btce|BTC/USD      93.384923   94.303957     150                 95348.71                  977.606     150                 1206.544                 109590.3   0.919034
bitfloor|BTC/USD  92.466821   95.943691      50                 34886.29                  351.314      50                 741.7571                 66806.79   3.476870
vcx|BTC/USD       84.335574  106.738853      57                 24510.22                 87.00034      32                 358.1143                 6093.029  22.403279
bitme|BTC/USD     47.767389         NaN       2                  2250.29                   8.6345      12                 38.95508                 1135.493        NaN
rock|BTC/USD      76.859385  136.920000       9                  4924.93                    28.36      26                    38.65                 1713.249  60.060615
bc|BTC/USD              NaN  123.169108      10                 31691.15                 159.5757       1                    0.274                 20.11342        NaN
intrsng|BTC/USD         NaN         NaN       0                        0                        0       0                        0                        0        NaN
========== Tickers stats ==========
Total asks: 5679
Total bid: 8024

========== Relative difference (%) ==========
                  mtgox|BTC/USD  bitstamp|BTC/USD  cbx|BTC/USD  btc24|BTC/USD  btce|BTC/USD  bitfloor|BTC/USD  vcx|BTC/USD  bitme|BTC/USD  rock|BTC/USD  bc|BTC/USD
mtgox|BTC/USD         -0.392046         -3.351987    -1.234013     -27.973278     -2.498307         -3.456883   -11.946587     -50.126839    -19.752355         NaN
bitstamp|BTC/USD       2.583068         -0.465281     1.715952     -25.821967      0.413896         -0.573311    -9.316587     -48.637216    -17.355500         NaN
cbx|BTC/USD           -4.672076         -7.504832    -5.477865     -31.068176     -6.687834         -7.605221   -15.730133     -52.269827    -23.200497         NaN
btc24|BTC/USD          2.600081         -0.448774     1.732822     -25.809664      0.430550         -0.556821    -9.301547     -48.628697    -17.341793         NaN
btce|BTC/USD           1.164634         -1.841565     0.309508     -26.847639     -0.974544         -1.948100   -10.570482     -49.347418    -18.498240         NaN
bitfloor|BTC/USD      -0.564329         -3.519150    -1.404840     -28.097856     -2.666948         -3.623865   -12.098886     -50.213100    -19.891153         NaN
vcx|BTC/USD          -10.620875        -13.276857   -11.376380     -35.369765    -12.510842        -13.370981   -20.988870     -55.248358    -27.993057         NaN
bitme|BTC/USD               NaN               NaN          NaN            NaN           NaN               NaN          NaN            NaN           NaN         NaN
rock|BTC/USD         -30.322632        -32.393158   -30.911601     -49.616147    -31.795995        -32.466534   -38.405219     -65.112921    -43.865480         NaN
bc|BTC/USD           -22.543684        -24.845369   -23.198408     -43.991174    -24.181538        -24.926938   -31.528632     -61.218044    -37.598489         NaN
========================================
                                          ask        bid    abs diff   rel diff
market_buy       market_sell                                                   
cbx|BTC/USD      rock|BTC/USD      100.077972  76.859385 -464.371735 -23.200497
bc|BTC/USD       cbx|BTC/USD       123.169108  94.595836 -571.465449 -23.198408
                 mtgox|BTC/USD     123.169108  95.402253 -555.337102 -22.543684
vcx|BTC/USD      vcx|BTC/USD       106.738853  84.335574 -448.065582 -20.988870
bitfloor|BTC/USD rock|BTC/USD       95.943691  76.859385 -381.686124 -19.891153
mtgox|BTC/USD    rock|BTC/USD       95.777746  76.859385 -378.367214 -19.752355
btce|BTC/USD     rock|BTC/USD       94.303957  76.859385 -348.891442 -18.498240
bitstamp|BTC/USD rock|BTC/USD       93.000000  76.859385 -322.812300 -17.355500
btc24|BTC/USD    rock|BTC/USD       92.984579  76.859385 -322.503871 -17.341793
cbx|BTC/USD      vcx|BTC/USD       100.077972  84.335574 -314.847959 -15.730133
vcx|BTC/USD      bitfloor|BTC/USD  106.738853  92.466821 -285.440634 -13.370981
                 bitstamp|BTC/USD  106.738853  92.567288 -283.431291 -13.276857
                 btce|BTC/USD      106.738853  93.384923 -267.078592 -12.510842
bitfloor|BTC/USD vcx|BTC/USD        95.943691  84.335574 -232.162348 -12.098886
mtgox|BTC/USD    vcx|BTC/USD        95.777746  84.335574 -228.843438 -11.946587
vcx|BTC/USD      cbx|BTC/USD       106.738853  94.595836 -242.860348 -11.376380
                 mtgox|BTC/USD     106.738853  95.402253 -226.732000 -10.620875
btce|BTC/USD     vcx|BTC/USD        94.303957  84.335574 -199.367666 -10.570482
bitstamp|BTC/USD vcx|BTC/USD        93.000000  84.335574 -173.288524  -9.316587
btc24|BTC/USD    vcx|BTC/USD        92.984579  84.335574 -172.980095  -9.301547
cbx|BTC/USD      bitfloor|BTC/USD  100.077972  92.466821 -152.223011  -7.605221
                 bitstamp|BTC/USD  100.077972  92.567288 -150.213668  -7.504832
                 btce|BTC/USD      100.077972  93.384923 -133.860968  -6.687834
                 cbx|BTC/USD       100.077972  94.595836 -109.642725  -5.477865
                 mtgox|BTC/USD     100.077972  95.402253  -93.514377  -4.672076
bitfloor|BTC/USD bitfloor|BTC/USD   95.943691  92.466821  -69.537400  -3.623865
                 bitstamp|BTC/USD   95.943691  92.567288  -67.528057  -3.519150
mtgox|BTC/USD    bitfloor|BTC/USD   95.777746  92.466821  -66.218489  -3.456883
                 bitstamp|BTC/USD   95.777746  92.567288  -64.209146  -3.351987
bitfloor|BTC/USD btce|BTC/USD       95.943691  93.384923  -51.175358  -2.666948
mtgox|BTC/USD    btce|BTC/USD       95.777746  93.384923  -47.856447  -2.498307
btce|BTC/USD     bitfloor|BTC/USD   94.303957  92.466821  -36.742717  -1.948100
                 bitstamp|BTC/USD   94.303957  92.567288  -34.733374  -1.841565
bitfloor|BTC/USD cbx|BTC/USD        95.943691  94.595836  -26.957114  -1.404840
mtgox|BTC/USD    cbx|BTC/USD        95.777746  94.595836  -23.638203  -1.234013
btce|BTC/USD     btce|BTC/USD       94.303957  93.384923  -18.380675  -0.974544
bitstamp|BTC/USD bitfloor|BTC/USD   93.000000  92.466821  -10.663576  -0.573311
bitfloor|BTC/USD mtgox|BTC/USD      95.943691  95.402253  -10.828766  -0.564329
btc24|BTC/USD    bitfloor|BTC/USD   92.984579  92.466821  -10.355146  -0.556821
bitstamp|BTC/USD bitstamp|BTC/USD   93.000000  92.567288   -8.654233  -0.465281
btc24|BTC/USD    bitstamp|BTC/USD   92.984579  92.567288   -8.345804  -0.448774
mtgox|BTC/USD    mtgox|BTC/USD      95.777746  95.402253   -7.509855  -0.392046
btce|BTC/USD     cbx|BTC/USD        94.303957  94.595836    5.837569   0.309508
bitstamp|BTC/USD btce|BTC/USD       93.000000  93.384923    7.698467   0.413896
btc24|BTC/USD    btce|BTC/USD       92.984579  93.384923    8.006896   0.430550
btce|BTC/USD     mtgox|BTC/USD      94.303957  95.402253   21.965917   1.164634
bitstamp|BTC/USD cbx|BTC/USD        93.000000  94.595836   31.916711   1.715952
btc24|BTC/USD    cbx|BTC/USD        92.984579  94.595836   32.225140   1.732822
bitstamp|BTC/USD mtgox|BTC/USD      93.000000  95.402253   48.045058   2.583068
btc24|BTC/USD    mtgox|BTC/USD      92.984579  95.402253   48.353488   2.600081
========== Arbitrage opportunities (better than 2.0%)==========
opportunity - buy 20.0BTC at 92.98458USD (for 1908.05USD at btc24|BTC/USD) - sell at 95.40225USD (for 1859.69USD at mtgox|BTC/USD) - 2.60% - 48.35USD
opportunity - buy 20.0BTC at 93.00000USD (for 1908.05USD at bitstamp|BTC/USD) - sell at 95.40225USD (for 1860.00USD at mtgox|BTC/USD) - 2.58% - 48.05USD

Plot arbitrage opportunities
Diff max buy@btc24|BTC/USD sell@mtgox|BTC/USD = 1401.26554683USD for 0.2626063BTC
...




Get source code and install

I never provide binaries package... always source code.
So you will have to
  • download and install Python http://www.python.org/ (if it was not already installed)
    • Linux Debian (or Ubuntu, Mint...)
      • $ sudo apt-get install python
  • install dependencies (if they are not already installed)
$ python btccharts-arbitrage.py --printmk --currency EUR --reldiff 4 --arbitrage
  • change settings
edit email_notifier.py to set your SMTP server, your email adress in order to receive email notifications
$ python btccharts-arbitrage.py --printmk --currency EUR --reldiff 4 --arbitrage --loop 600 --sendemail

edit pushover_notifier.py to set your API and user key for to receive push notifications to your mobile device(s) (iOS, Android) thanks to Pushover https://pushover.net/
$ python btccharts-arbitrage.py --printmk --currency EUR --reldiff 4 --arbitrage --loop 600 --sendpush
  • improve your installation
Use GNU Screen with a screen for each currency




Keep in mind that everything is "virtual"... but use this at your own risk !!!