NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Show HN: 400-Line Binance CryptoCurrency Bot (github.com)
klhugo 1601 days ago [-]
The Money Maker Machine - Monker

This was a hobby project of myself to create the simplest Cryptocurrency bot possible. It was written in Python, operates on Binance, and stores all logging and trading information into a MongoDB database. The trading strategy is extremely simple:

- Assume that crypto prices will fluctuate, but eventually be restored to its original quote - Buy small quantities every time the price falls below a threshold, keeping track of the amount purchased and the price payed - Sell those exact quantities when the price is above what was payed for it

It was a lot of fun developing it, and I guess I made something around 3 dollars before shutting it down. It is my first contribution to opensource world, and I hope others can benefit from it :)

eerikkivistik 1601 days ago [-]
Hi

So first of all, thank you for sharing your work, I'm sure it was a lot of fun building it and making it work!

If you'll indulge me, I'll point out a few thoughts about application logic that handles money.

First of all, money related logic should be using fixed point mathematics in all places. In the case of EUR/USD fixed to 2 points behind the decimal point and in case of BTC and others, somewhere around 9-16 (can't be bothered to look it up atm). There is a cumulative error that is produced when using floating point variables. I'll be happy to share a link to a discussion, if you want!

The second thought I had was about using MongoDB for this use case. While it is great for getting started and MongoDB has made great strides at improving safety, it is still a suboptimal choice for handling financial transactions (logs or otherwise). I will also be happy to clarify why, if someone wants to discuss the matter further.

nayuki 1601 days ago [-]
Bitcoin has exactly 8 decimal places. The terminology is 0.00000001 BTC = 1 satoshi.
eerikkivistik 1601 days ago [-]
Right you are, consider me corrected.
squeaky-clean 1601 days ago [-]
> While it is great for getting started and MongoDB has made great strides at improving safety, it is still a suboptimal choice for handling financial transactions (logs or otherwise).

Would you mind clarifying this last bit? The default settings are not ideal and you need to do some configuration, but if you know what you're doing MongoDB has been capable of safe data storage since 3.6? What else would make it suboptimal?

Admittedly I'd probably choose postgres on a new project, given the many features. But in my dayjob I use MongoDB because of Org/Historical reasons and am not really aware of any problems that can't be mitigated. Is it just because you have to waste time mitigating common problems?

eerikkivistik 1601 days ago [-]
Sure thing.

So most of the problems I have with using NoSQL type databases for financial data is related to the default settings and examples encouraging a model of programming, that will result in data loss, migration problems, race conditions, duplicate transactions. It's a bit like PHP in my mind, where you can write solid software, but in order to do so, you have to have very good discipline. I would rather choose a more constrained model, that forces you think about these problems and provides some safety out of the box. So in that sense you are right in your observation that my main issue with it is, that you have to mitigate problems, that shouldn't be problems. Then again MongoDB was never designed with those kinds of problems in mind and targets a completely different set of problems, which in itself is fine.

Edit: I'll add a few more thoughts. Financial data in essence is relational. It is also well shardable if scaling is an issue. There are many constraints that need to be validated and it is a natural fit in my mind.

bastawhiz 1601 days ago [-]
What are your thoughts on Stripe using Mongo almost exclusively?
eerikkivistik 1601 days ago [-]
Not sure about the stack Stripe uses, but if they do use Mongo, then they I presume they made it work well enough with a sheer force of will and reimplemented many ACID guarantees in the application layer themselves. That is of course assuming, that they started with Mongo early on, when it was still a bit wonky. I would love for a Stripe developer to jump in and share some background!
zajd 1601 days ago [-]
What makes you think Stripe uses Mongo almost exclusively?
Benichmt1 1601 days ago [-]
Just as an FYI you have old commits that look like you accidentally left secret keys in there. I'd suggest you remove those just in case.
woodrowbarlow 1601 days ago [-]
just as a follow-up FYI, on github (and most git servers) rewriting history and force-pushing is not entirely sufficient to actually delete something that you accidentally pushed. commits that have been rewritten out of history can usually still be referenced and viewed directly by their hash. (they may eventually get garbage-collected, but there is no guarantee.)

still a good idea to remove it from commit history if possible, but those secrets should be considered compromised and should be changed.

bhaak 1601 days ago [-]
> It was a lot of fun developing it, and I guess I made something around 3 dollars before shutting it down.

And now you even get internet karma points for it.

Seems you came out ahead. Not many people who went down the crypto rabbit hole can claim that. :-D

eerikkivistik 1601 days ago [-]
Read and laughed. I was going to say as well, 3$ in the green is already better than most people!
andreygrehov 1601 days ago [-]
I quickly glanced through the code, couldn't find anything related to fees, do you take it into account?
klhugo 1601 days ago [-]
Hi, thanks for having a look at the code! I did not put lots of effort in developing the trading strategy itself. So you need to make sure you provide a `proft` param to the function `bd_insert_buy` which is large enough so you don't loose money. Currently, the `maestro` function sets the `DTHR` variable which is used both as dip threshold for buying, and as profit value.
haolez 1601 days ago [-]
Nice! It's very simple, but has a few interesting qualities, like not using any third-party library to interact with Binance, giving the bot more flexibility to make use of Binance-specific features in a future extension of this work. For example: Binance's margin trading works a little different from other exchanges.

I would use order book data instead of ticker data, though, since you have more control of your risks regarding the exchange's liquidity.

Well done!

1996 1601 days ago [-]
Orderbook can be tricky. Also third party libraries are dangerous.

If all you need is ticker data, but you want separate bid/ask, and do not want 3rd party library, you can augment your results with market average from http://cmplot.com/api.json

It also come with all the fiat pairs. No TOS, no login, no nothing, it lives on XMR donation.

justaguyhere 1601 days ago [-]
This site's FAQ is a charming and a delightful read! Thanks for sharing
1996 1600 days ago [-]
Share the goodness!
klhugo 1601 days ago [-]
Thanks, I really appreciate your comment! :D

I did test the order book support, it indeed works and would be a nice to have feature.

glofish 1601 days ago [-]
I have a feeling that the vast majority of transactions are from bots like this, from the naive "moneymakers" (like this one with a $3 return) to ones with extreme sophistication.

The naivete here is that it only makes money if the market is rising long term. If it is falling over the long term then you'll get stuck with a bunch of losses.

The results it generates are no different than buying at random times and selling random bets at random times.

1996 1601 days ago [-]
I think you are mistaken- the bots is based on means reverting. Rising or failing will not work. Oscillations will work.
hmate9 1601 days ago [-]
(It’s called “market making”)

It doesn’t necessarily require long term trends to be profitable. It just requires the short term trend to be mean reverting, which is usually the case for markets.

Of course, you need a little more sophistication, stop losses and parameter tuning before you can be confident of long term profitability.

studio816 1601 days ago [-]
If you like crypto bots, check out our project called https://quadency.com We have common strategies you can deploy to all major exchanges. You can also code your own real-time strategy in python using https://support.quadency.com/en/articles/3459678-strategy-co...
zigzaggy 1600 days ago [-]
Very cool. I’ll have to check this out.

Do you know of any stock trading sites that have bots?

studio816 1600 days ago [-]
Crypto is a little different as you have direct access to exchanges whereas in stocks typically you’re trading with a broker. This opens up a lot of opportunities for individual traders that traditionally are only available to institutions, such as strategies based on order book (market making, arbitrage etc)
csomar 1601 days ago [-]
I think there should be a big (maybe red?) disclaimer at the very top explaining that this should only be used for fun, experimental and learning purposes. No real money should be invested into it too.

Just in case somebody thinks it's real and go full retard with it.

mmanfrin 1601 days ago [-]
> and go full retard with it.

Please don't use language like this.

wesammikhail 1601 days ago [-]
Policing speech when someone is trying to make a point tongue in cheek about protecting the end user is 100x more insulting than him using the word retard.

Hence: Please don´t be anal like this.

cmcd 1601 days ago [-]
That is the accepted terminology for wallstreetbets style trading, is it not?
itake 1601 days ago [-]
wallstreetbets would say "full autist"
mocha_nate 1601 days ago [-]
Haha and much much worse
majortennis 1600 days ago [-]
I appreciate you calling it out it bothers me too. The way I see it people have enough problems having say cancer or HIV, without those terms becoming a popular adjective for belittling
csomar 1600 days ago [-]
I'm not certain about the sensitivity in this context. Going full-retard in trading means betting all your funds on one trade.
faeyanpiraat 1601 days ago [-]
It’s common internet terminology.
tuesdayrain 1601 days ago [-]
If someone randomly comes across a trading bot on the internet and loses their money, I think they got what was coming. I don't feel that it's necessary to cater to the bottom percentage of users who might do that. As if a disclaimer would stop them anyway.
Akababa 1601 days ago [-]
Very cool! I might try to pick this up later and test some stuff out. Why did you choose to stop it? Did you find a more profitable algorithm ;)

I wonder how much of the volume on cryptocurrency exchanges are due to bots.

klhugo 1601 days ago [-]
A lot is due to bots.

I stoped mainly because I need to work on my PhD. But the code there was very solid on my tests. I hope I can get back at it early next year :)

pearjuice 1601 days ago [-]
Your code doesn't seem to have any tests?
alimbada 1601 days ago [-]
I assumed he was talking about his manual tests.
gmm1990 1601 days ago [-]
Looks pretty cool! I'm always unsure of separating my buy and sell side logic. Was there a deliberate decision to separate those functions, rather than passing the side as an argument?
shelune 1600 days ago [-]
How much did you put in the bot initially and how long have you kept it running before shutting it down?
mocha_nate 1601 days ago [-]
Great idea. Thank you for sharing! I’ve had this same thought with Tesla’s stock
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 15:09:56 GMT+0000 (Coordinated Universal Time) with Vercel.