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 :)
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.
> 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?
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.
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!
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.
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.
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.
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.
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.
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.
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)
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.
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.
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
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.
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?
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 :)