Hacker News new | ask | show | jobs
by withinboredom 981 days ago
I wrote an arbitrage bot and gave it $100 ... then promptly forgot about it. Several years later, when I stumbled across it, still faithfully running on my server, it had nearly 11 million worth of coins. I opened the project and had it start shuffling everything off to bitcoin, slowly, over days/weeks to bitcoin. I was going to just cash out.

Well, it turns out that when I originally wrote the code, time was calculated in milliseconds, not seconds. So, when I thought I calculated out 17 days, it was like half an hour-ish. It caused a small crash trying to dump everything almost all at once, on some of the alt-coin markets, and lost almost all the money.

I walked away with ~$700.

I was literally in tears, as I went from so excited and I'm going to "just retire" ... to just as broke as I was an hour prior. The emotional roller-coaster of euphoria, to 'oh shit, what did I do!?', to 'well ... fuck' was not fun.

Anyway, good luck. There might be a lesson in there, but mostly, be careful where the intersection of money and programming lie.

11 comments

I dont think reputable alt-coins with liquidity could turn into 11mil->700$ in an hour, so i consider it pretty safe to assume that 11 million wasnt actually 11 million: it doesnt matter if nobody wants it. Nevertheless, great work on processing such emotional burden.
It's a great story but what makes me question it is the idea that any altcoin exchange from 10yrs ago ran for more than a year without getting "hacked" and/or outright disappearing.
Where did you get 10 years from?
In another comment you said this was 3-4 years ago, and by that point apparently this had been running "several years", which one usually takes to mean 3 or more years, so in total 7-8+ years ago at least, which I rounded up to 10.

For what it's worth, I'm not accusing you of lying, I'm making a tongue in cheek observation about altcoin exchanges.

It does seem like you are stating the MTM valuation (i.e. spot x notional) without mentioning liquidity, which is where the confusion from others is coming in. It's very possible to accumulate a large position in a low liquidity altcoin that you will have zero hopes of selling for that valuation, even over time.

Ah, yeah, I can see that. I wrote the initial code in 2018ish, re-discovered it just before covid, IIRC.

> It does seem like you are stating the MTM valuation (i.e. spot x notional) without mentioning liquidity, which is where the confusion from others is coming in. It's very possible to accumulate a large position in a low liquidity altcoin that you will have zero hopes of selling for that valuation, even over time.

I'm not 100% what those words mean, but if I'm understanding you correctly, this 11 million was if I could sell it for in a perfect universe. It wasn't the actual price I could sell it for ... obviously, that was about $700.

> I'm not 100% what those words mean, but if I'm understanding you correctly, this 11 million was if I could sell it for in a perfect universe. It wasn't the actual price I could sell it for ... obviously, that was about $700.

That's right. So you may have accumulated 11m HN coins, but the market for them is dead except for 1 exchange where a pump n dumper is the only person offering to buy any. They are currently paying 1 USD for each of them, but they are only willing to buy up 700 HN coins at most. MTM is 11 million USD but liquidity is only 700 USD.

So your story is perfectly possible, but without stating liquidity it's unclear which number you meant when you said $11m unless people are familiar with the markets in which case it's obvious you meant MTM. Most people would expect min(MTM, liquidity over reasonable time frame), though.

I’m not sure what I’m finding harder to believe here. That one could lose more than 99.99% due to a timing fat finger (even on a quiet market - 11m over 30 minutes eating through the order book?), or that an arb bot that you forgot about managed to run for that long on a server without hitting endpoint changes, API changes, re-auth requests, etc.
Yeah this is a made-up story so obvious for anyone who spent any time whatsoever programming against those exchanges... Please don't upvote just to keep your replies on the top...
I highly doubt we are/were on the same exchanges. The algorithm only worked on volatile coins with low-mid market volume. It wouldn't work on high market volume or stable coins.
In order to eat through over 99.99% of the price, this isn’t a low-mid market volume. It’s non-existent market volume.

I’ve worked on everything from the ultra liquid equity futures markets down to the shittiest of shitcoins imaginable and these numbers just don’t make sense at all. There’s a paradox: your valuation implies an active market and your execution implies a dead market.

When shitcoin markets die, they die at small fractions of a cent, and there are lingering sell orders in from people who got caught in the pump’n’dump and live under the false hope that their superconductorcoin will be worth something later on, which then removes the possibility of any remaining large-price buy orders. So for your valuation to be that high, it can’t have been a dead market.

But for your execution to be that low, it has to have been one.

I can’t truly believe that someone who is smart enough to build a system that accidentally stays functioning in the background for that long (I’ve never seen such a thing) is silly enough to calculate valuations so naively.

Not dead markets, but not very active ones by the time the death of this project occurred. I'd have to review the code to see how it calculated a 'cash out' value, exactly, but IIRC, it basically just took the highest bid to convert to bitcoin/eth or whatever and summed up everything. It was entirely naive af, for sure. Probably because I assumed that my future self wouldn't essentially sell off everything in 30 minutes.

Also, I still know of at least two projects that I wrote, running since 2012 with very little maintenance ... knowing how to write resilient software and being clairvoyant aren't mutually exclusive.

I call BS
If it makes you feel any better the money was never actually there in the first place.

If $11,000,000 turned into $700 then the "market cap" was bullshit and the coin was bullshit and whatever "price" it had was bullshit. Maybe you could have done a little better than you did but there wasn't any there there, in the sense that there were actually eleven million real greenback dollars in the hands of people that had any interest at all in owning that coin.

This dynamic completely underpins the entire concept of crypto, with the possible exception of a couple big ones. It's just market manipulation and people trading with each other. Turns out nobody wanted to own digital apes either it was grift all the way down.

Sounds like your bot hit some edge case and was min-maxing on long tail shitcoins with no liquidity on Uniswap. You maybe could have done a bit better than $700 via TWAP but likely not much more than $10k or so. It's just not that possible to turn $100 into $11M via arbitrage.
It was literally only working due to an improper implementation of standard deviations, IIRC. When I fixed the implementation, it didn't make any money, so I kept the bug. I've used this 'buggy' implementation on a couple of other projects as well, because it does a fantastic job -- a "secret sauce" of sorts.
Wait... I'm very much academically interested in the math you did. Particularly, how a standard deviation calculation being wrong can give you an edge. Do you understand the bug enough to know how it changed things and why it worked? I'm not asking you what the edge is, it's just that from my understanding of how these things work something like that shouldn't be possible.
Take what he's saying with a grain of salt. This post activated my spidey sense from another thread a year back, about SHA hashes being poorly distributed compared to MD5, and sure enough, it's the same dude.

https://news.ycombinator.com/item?id=32409168

Yes, and at the risk of this sounding like a personal attack, why even bring this up? Did you read the thread you linked to?

> soooo basically there is no bias

> Looks like it. Though I think md5 is faster, which is maybe what I’m remembering, now that I think about it. This was years ago, funny how memory gets tainted.

I brought it up because without remembering the name from that exchange a year ago, the similarly casual misunderstanding-proffered-as-fact in the post here led me to guess it would be the same person, and it was. Which is just to say that I suspect you have the details wrong in this case, too. That's all.
Looking at the code, the purpose was to locate the nearest resistance by analyzing current orders in the market, and the slope of the orders around each resistance point, over time. This was used as one signal on whether or buy/sell. Std Deviation was calculated with this code:

    public static decimal StdDeviation(IEnumerable<decimal> data, decimal mean)
    {
         var sumOfSquares = data.Select(x => (x - mean) * (x - mean)).Sum();
         return (decimal) Math.Sqrt((double) sumOfSquares / (data.Count() - 1));
    }
It was written at 1:30am, according to git blame ... there's even a potential division by 0 hiding in there, so this is some shit code 'just to see what happens'. Anyway, that `data.Count() - 1` is the part that is "wrong" and tbh, I have no idea how it changes things.

The mean passed to it wasn't even a true mean either, it was a sliding window mean, of a specific area of resistance multiplied by reciprocal of an "influence" coefficient. Yeah... I have no idea how this shit worked. This is nearly 5 years old at this point and hasn't run in 3+ years.

It used to output a realtime graph that was visible from the web, it would show the output of all this math. From what I remember, this signal shows as a line on the buy side, sloping up/down. That slope indicated whether a specific resistance line was at risk of dissolving or a new one being created with the idea being to buy as much as possible before the resistance line actually dissolved.

Can you explain what it did? Or why an improper standard deviation would change the profitability of your bot?
The algorithm was pretty simple, but required access to all standing orders. It would look for resistance building/degrading and capitalize on it, making a bet that it would or wouldn't fully form/degrade based on how fast it was doing so. To do that, it needed to know if new orders were just part of the current resistance or potentially part of a new resistance. The standard deviation helped inform that decision since pretty much anything within a standard deviation of the edge is probably part of the same resistance.

It also monitored the buy/sell gap, and took some notes from that (large gaps mean new resistances while a small gap means waiting for a big order to break through and cause volatility).

11,000,000 to ~700? -- I'd call that more than a "small crash".
Just run the arbitrage bot again. Or better yet, if you can prove to me that this was true I'd be willing to buy your arbitrage bot for $10k. Serious offer
Contact information is in my profile. The bot is actually MIT licensed and available on GH, it's just tucked away on a random branch in a totally unrelated repo.
I don't think the APIs I was using still exist (this was ~3-4 years ago), so I suspect that it just won't work any more.
The guy can pay me $5k and I'll hook it up to new APIs. Semi-serious offer.
Sorry to hear that! I am being pretty cautious when trading lately whilst the website is pure independent analytics and doesn't require me to risk any funds.
Ouch. I do hope you don‘t miss the millions. Still: 700 bucks could feed some people on this planet for at least one year, if not even two.

And another upside: the valuable lessons you learned are probably worth… well… millions of dollars!

Back to topic: How did the crash lead to losing the money technically? What happened here? How did too many requests of selling lead to „devaluation“?

You should definitely write a longer form story about this and include some code.

> How did too many requests of selling lead to „devaluation“?

This is not specific to cryptography, it's a feature of all markets: if there's a scarce resource that a lot of people want, people will pay more for it. Parent flooded the market with whatever cryptocurrency instruments they held, suddenly making them a lot less scarce and so reducing their value. They could have avoided losing that by selling much more slowly (as they intended) or refusing to sell below a certain fixed price. In either case, they would probably not get quite as much as they had hoped for the whole lot due to a lesser version of the same effect.

lol you had $700 in liquidity because the team found your dumb bot and saddled you with their illiquid asset for your liquid eth

its one of the easiest trades

Language designers not having meaningful number type aliases (e.g. NanoSeconds instead of int) is a, well ... $11m mistake.
How exactly did 11 million dollars turn to 600?
Easy, you have 1000s of some shit-coins, where if you sell it off slowly, you'll get a reasonable value for it. However, if you try to sell it quickly ... you'll eat through any reasonable value in minutes. For example, say you have 100 coins. There are 20 people willing to give you 100 bucks, so you sell them to those people, then there are 50 people willing to give you 50 bucks, and the rest are willing to give you 10 bucks. We'd call the 50 people willing to give you 50 bucks 'resistance' (at least that is what it is called in FTX-land). So, I cash out for (20 * 100)+(50 * 50)+(30 * 10) = $4,800. A nice slow sell-off could result in selling the whole 100 coins for $100, or $1,000,000, whereas dumping it, like in this example, can result in "losing" a ton of "potential cash." I was dealing with volatile coins, so often there was very little resistance (if any) to retain any kind of value.