
Bitcoin arbitrage without market risk - butor
https://github.com/butor/blackbird
======
Animats
All the US dollar exchanges with substantial volume are within 1% of each
other. [1] Some of the little guys are a few points out there, but any
significant order would blow the price. All the exchanges lock together within
the range of the cost of trading, which is usually at least 1% when you
combine buying, selling, short-selling loan, blockchain reward, and cash
withdrawal fees.

[1]
[http://bitcoincharts.com/markets/currency/USD.html](http://bitcoincharts.com/markets/currency/USD.html)

~~~
Veratyr
They are right now but this isn't always the case. For example you can see
just from that page that in the past 24h, Kraken reached a low of 1025 while
Bitstamp only reached a low of 1118, a difference of 9%. If at that low, you'd
bought BTC on Kraken and sold BTC on Bitstamp, you would have made that 9%
difference.

This is the point of the strategy. Whenever they diverge for whatever reason,
assume it's temporary and that they'll reconverge. Make money converging them.

~~~
tom_wilde
How does the engine know the direction the converge will take? I'm missing
something here.. :?

~~~
Veratyr
The direction doesn't actually matter since you're trading both sides. An
example:

Exchange 1: 1000 Exchange 2: 900

You sell 1 of exchange 1 and buy 1 of exchange 2.

Scenario 1: Exchange 2 rises to meet exchange 1, exchange 1 stays stable. You
make $100 as you bought exchange 2 at 900 and its price is now 1000. You lose
nothing on exchange 1 since the price hasn't changed.

Scenario 2: Exchange 1 falls to meet exchange 2, exchange 2 stays stable. You
make $100 as you sold exchange 1 at 1000 and its price is now 900. You lose
nothing on exchange 2 since the price hasn't changed.

Scenario 3: Exchange 1 rises to 1100 and exchange 2 rises to meet it. You make
$200 as you bought exchange 2 at 900 and its price is now 1100. You lose $100
as you sold exchange 1 at 1000 and its price is now 1100. The ultimate profit
is $100.

The important thing is that you trade both sides.

------
ns8sl
Historically, exchanges that are failing have significant spreads from stable
exchanges (Mt. Gox comes to mind).

So, there is risk with this strategy. One of the exchanges could fail and you
lose everything you have on that exchange.

~~~
butor
This is correct. That's why I specified _market_ risk. Of course not all the
risks are overcome.

~~~
ns8sl
I know. I'm pointing out that seemingly profitable arbitrage opportunities
carry very significant risks besides market risk.

~~~
gricardo99
I agree. Exchange failure is generally something separate from "market risk",
and is sometimes categorized as "counterparty risk". With bitcoin,
counterparty risk with exchanges is a very real thing, and an added risk
beyond what would be considered "market risk" (i.e. asset price fluctuations).

------
lz400
Are you eliminating execution risk? with these exchanges and this liquidity I
wouldn't be surprised if your algo slips and actually loses money on the
attempted executions on the arbitrage prices. Isn't that too dangerous to
claim you've eliminated "market risk"?

------
Taek
Some exchanges are going to be more permanently divergent. Does the software
handle this well?

An exchange can be permanently cheaper if withdrawals are limited, trust is
lower, or some other effect reduces trader confidence in the exchange.

Major events like hacks are also imo likely to cause this software to stumble.
Are there safety features to make sure it'll stop trading if something
sufficiently unusual is happening?

~~~
butor
You're absolutely right: some exchanges are systematically divergent. It has
been the case with BTC-e for a long time. This is not natively handled by the
software.

The long/short mechanism overcomes the market risk (i.e. risk of losing money
due to market moves) and reduces the slippage risk, but not the other risks,
like technical issues on an exchange.

~~~
wocram
Why is BTC-e divergent? Are prices in blackbird adjusted for that, or other
more easily quantifiable things such as fees?

------
t3soro
The reason this doesn't profit is because the spread tends not to exceed the
difference in exchange fees. So while there may be a $1 spread between two
exchanges, the sum total of two 0.5% exchange fees on a $1000 coin will only
net the exchange profits in fees, and you might earn a penny.

------
matt_wulfeck
I always wondered who might be doing this. I never expected to see an open-
source tool, since it introduces immediate competition.

~~~
ng12
Yeah I don't understand -- if it works well wouldn't it be better to keep it
to yourself?

~~~
55555
Perhaps they wrote it for their own use, then were unable to make it
consistently profitable to a worthwhile degree, so they just open-sourced it?

~~~
jliptzin
Agreed. I would find it hard to believe that there still exists an arbitrage
opportunity here, 5 years after bitcoin went (somewhat) mainstream.

~~~
askmike
> 5 years after bitcoin went (somewhat) mainstream.

Arbitrage is as much about volume as it is about differences in price. Volume
is something bitcoin markets do not really have (compared to most other
financial markets).

------
garethsprice
Cool to see a project like this open-sourced regardless of it's profitability,
fintech/trading is usually such a black box.

Are there any other examples of trading systems like this that are good to
read for someone with a passing interest in building simple trading systems?

------
t3soro
It would be dangerous to run this open source code, also, since your program
could be manipulated with precision timing attacks, if it were to be fooled
into making a bid at a price flash. There is in fact plenty of technical risk.
Caveat emptor!

~~~
omgam
This is basically how many closed source Bitcoin trading robots operate. They
create giant waves of predictable trades because naive operators leave the
default parameters for trading signals. Other traders just get in (and out)
right before the robots.

~~~
wocram
How do you know that?

~~~
omgam
Trading with my own robots and by hand.

I found that automated triangular (and 4, 5...) arbitrage was possible in the
past, mainly due to fee-raking exchanges providing superfluous instruments.
Opportunities were usually small, counterparty risk and fees usually large.

There also seemed to usually be someone else's bots doing the same thing,
although occasionally decent sized trades appeared in slow/extraneous markets.
Exploiting these mechanically eventually results in humans looking for the
source of the arbitrage, and even if there aren't competing bots running it
won't last long.

Arbitrage based on first-moving markets and slower moving markets was pretty
common, and some people seemed to have automated it.

And of course the market making robots run by the exchanges are the most fun
to watch. Lots of times they trigger the crossover bot traders' algorithms on
purpose.

------
reckoner2
When building an automated trading system the first thing you write should be
the risk system. Simply having a 'MaxExposure' per exchange doesn't cut it.

This has nothing to do with it being a market-neutral strategy or not. All
code has bugs in it, exchanges have hiccups, quotes from many exchanges are
notoriously wonky, programs freeze, Internet connections go down, users fat
finger inputs etc. This needs a real risk system built into it.

~~~
blantonl
But there is no market risk, because the project says so.

------
jacobwcarlson
It's weird that over the course of 7 hours no one on a site called Hacker News
noticed that send_email.cpp passes unsanitized user-supplied args to system().
I've spent less than 5 minutes looking at this code, so maybe that's the worst
of it. But if 5 minutes of investigation found 1980's style bugs I doubt
that's the worst of it.

~~~
xapata
I haven't read the code, but regarding unsanitized user input... Isn't the
user the, well, user, in this case?

Complaining about bad data in that situation is like complaining that an admin
could hit the power switch.

Or maybe I've completely misunderstood the purpose of this software.

~~~
jacobwcarlson
Assuming input is from a benign source is literally the cause every single
security issue ever. It's bizarre that I've been downvoted for this. And
you're commenting about how I'm wrong without even reading the code. I
seriously don't understand this site.

~~~
Steeeve
I, for one, am astounded at the responses in this thread of discussion.

> why shouldn't my financial system be as open as bash?

Oh my lord...

~~~
xapata
... but it ain't your financial system. Unless I've seriously misunderstood
the README.

I put my cups in the dishwasher, not the autoclave. I use 2fa for my financial
accounts, but not for my frisbee league. Security is about appropriate
paranoia.

~~~
Steeeve
In no scenario is it better to allow arbitrary hidden process creation than to
spend 10 minutes writing a function that validates parameters provided to
launch a process.

~~~
xapata
I respectfully disagree.

------
fuddle
Have you made much profit using the software?

------
omarforgotpwd
Looks like a great app for anyone looking to accidentally destroy their life
savings and get arrested by the IRS.

~~~
leadingthenet
Why? Genuine question.

~~~
thehardsphere
Short selling is significantly more dangerous than other forms of investing,
because it requires borrowing the securities that you then immediately sell.
You eventually have to return those securities to the person you borrowed them
from, so that requires a purchase in the future. If the price of the security
goes up, you don't just lose your money, you take on a debt that you must
repay.

The worst thing that can happen if you buy a security is that it will become
worthless, thus you lose all the money you put in. The worst thing that can
happen if you use any form of debt to leverage your investments is that you
get wiped out completely because you end up owing more money than you can
possibly pay back.

~~~
nommm-nommm
See: Help! My short position got crushed, and now I owe E-Trade $106,445.56

[http://www.marketwatch.com/story/help-my-short-position-
got-...](http://www.marketwatch.com/story/help-my-short-position-got-crushed-
and-now-i-owe-e-trade-10644556-2015-11-19)

------
RoboTeddy
Are the price differences between markets already arbitraged to the point of
maximum profitability?

(which wouldn't be 100% due to eg exchange failure risk, transaction fees,
risk of getting hacked while currency is in play, etc)

~~~
kbody
There is at least one exchange that has enough discount, but their reputation
is horrible, so if you want to arbitrage that then it's on your head. In
general that's the case if there is any opportunity. While they don't make
mainstream headlines, mini MTGox'es still happen, like a Polish exchange some
months ago.

There are a lot of people going after it, and probably some that do it wrongly
thinking they are profitable while they are not. If you look at some of those
bitcoin bots, they full of wrong calculations.

------
rampage101
Just curious why someone would open source a project like this?

If it works, it should be making money consistenly, but giving away the system
will make the arbitrage opportunity non-existant if enough people use it.

~~~
dalore
Perhaps he realises that other people are doing it too and, as you said,
realised the more people who do arbitrage the more it goes away. He could be
out to stabilise the bitcoin exchanges as well as provide liquidity to the
market.

Perhaps as more people use it, the demand for bitcoins go up also, and since
limited supply the price goes up. And he might have substantial holdings of
bitcoin he wants to sell. More people trying to find arbitrage opportunities
makes it easier to sell his bitcoin which are now higher value.

~~~
_coldfire
A big red flag in the SEC decision was that large arbitrage opportunities
exist in bitcoin markets for far longer than is considered normal.

Anyone wanting more mainstream adoption of bitcoin would do well to promote
arbitrage trading to as many as possible.

------
random3
given the high latency with the exchanges the choice of language seems an
unnecessary risk

~~~
TheDong
The main bitcoin codebase is in C++ so C++ has the most mature library and
best support for the protocol.

Other implementations, including two Javascript ones and a Go one, have had
significant bugs in handling the protocol correctly.

Seems like a pointless risk and waste of time to use any non-c++ language for
dealing with the BTC protocol

~~~
gst
Does the library directly use the Bitcoin protocol? I had the impression that
it only uses the Rest API of the individual exchanges interact with them.

~~~
askmike
Your impression was correct, the only crypto this touches is signing API calls
to the REST APIs of exchanges.

------
thehardsphere
"without market risk"

> Blackbird doesn't sell but actually short sells Bitcoin on the short
> exchange.

Because nobody ever faced risk short selling. That big market crash that was
part of the worst recession in 60 years had nothing to do with short selling.
Long Term Captial Management totally came out of that just fine. Bear Sterns
is alive today and doing swell.

Jesus.

~~~
galacticpony
What does that have to do with anything? You don't understand the point.

You go short on one market, while simultaneously going long on the other
market. That's how you _profit_ (arbitrage).

~~~
thehardsphere
"Going short on one market" = "I can expose myself to losing a sum of money
that I don't have if it goes tits up"

~~~
galacticpony
Not if you simultaneously BUY ON THE OTHER MARKET.

Jesus.

You also can't lose money beyond what you put in (on the exchanges that allow
for this), your position just gets terminated.

