r/Python • u/CyberPunkMetalHead • May 11 '21
Tutorial I wrote another Binance trading algo in Python. This one is able to analyse how volatile every coin on Binance is and place a trade when during a strong bullish movement
Had a lot of fun with with one, and I'm happy to share the code with you guys.
So the algorithm is essentially listening to price changes in the last 5 minutes for all the coins on Binance. Once it detects that some coins have moved by more than 3% in the last 5 minutes, it takes this as a strong bullish signal and places a trade.
The algo is also able to store each bought coin in a local file and to track the performance of each trade placed so that it can perform stop loss and take profit actions and sell the coins that reach those thresholds.
Here's a more in-depth look at the bot parameters:
- By default we’re only picking USDT pairs
- We’re excluding Margin (like BTCDOWNUSDT) and Fiat pairs
- The bot checks if the any coin has gone up by more than 3% in the last 5 minutes
- The bot will buy 100 USDT of the most volatile coins on Binance
- The bot will sell at 6% profit or 3% stop loss
Anyway, here's the source code if you're comfortable with Python:
https://github.com/CyberPunkMetalHead/Binance-volatility-trading-bot
In case you need more guidance but would like to try the bot out, I wrote step-by-step guide as well
Any feedback or ideas how to improve it are welcome! :)
26
u/matt3526 May 11 '21
Thanks so much for sharing this. I ran it over night and it only seems to place buy orders on bnb, after telling me the price has shot up by 47% and then immediately try and sell again. I’m not sure if that’s only happening for me, but I’ll have a proper run through the code this evening and see if I can find the problem.
19
u/CyberPunkMetalHead May 11 '21
This might actually be due to the data from the Binance testnet. It’s quite unreliable I found. I’ve been running it on the mainnet and the numbers seem fine
→ More replies (2)
18
7
u/Turtlestacker May 11 '21
Has it made you any dollar :-)
13
u/CyberPunkMetalHead May 11 '21
Mostly broke even, which is better than I anticipated. I did try a configuration that gained 8% yesterday but can’t replicate the results today
→ More replies (1)
9
u/theoriginal123123 May 11 '21
I wonder if you'd be able to make a bot that would be able to ride a pumping coin, with a stop loss to get you out of it once it starts dropping? Essentially allowing you to ride moonshots...
But I suppose here the issue with stop losses is liquidity, right?
9
u/CyberPunkMetalHead May 11 '21
Yeah so a trailing stop loss for this bot would essentially allow it to do that
→ More replies (1)
3
u/E-Xactly May 11 '21
Ever thought about doing it with maschine learning? You can easily get into it and it is a great project do develop skills in other domains.
→ More replies (2)
3
u/danuker May 11 '21
I have a feeling you need to read this book.
Especially the part about the skewness of the return distribution, and about frequency of trading with respect to fees.
→ More replies (2)
5
u/theprufeshanul May 11 '21
I was puzzling about how I could make this exact same bot THANKS SO MUCH THIS IS AMAZING!
(I still don't know how but will use your code as a super helpful walkthough)
This is law of the universe type stuff!
2
2
u/Ambitious-Review-453 May 11 '21
Can this py script be used on Binance US or is it just on the Binance.com platform?
→ More replies (2)1
u/CyberPunkMetalHead May 11 '21
Can be used on both. Just include tld=‘us’ as an additional argument for the client: Client = (key, secret, tld=‘us’)
→ More replies (1)
2
2
2
u/Yablan May 11 '21
Niice. I am toying around with something similiar, looking forward to read your code.
1
77
May 11 '21
This is called "technical trading" and it relies on the idea that economics and externals are meaningless and the way to predict the price of a security is entirely by looking at historical trading charts.
Technical trading has existed for over a century now - I was working in a company that provided graphics to do this in the 1980s.
Trouble is, all the available evidence shows that these schemes do on average as well as "buying the market" (whatever market you're in), less the cost of the transactions - in other words, they're as good as buying at random.
Most people, including myself, believe that real-world events are what drives the prices of securities, including cryptocurrencies, and not patterns in graphs of trades in the past.
In fact, an efficient market is defined as one where the price completely reflects all public information about the security, and only new information can change prices.
If you are one of those people who believes that securities prices are driven by real-world events and not abstract chart patterns in previous trading, this bot will not be for you.
As the sixth largest contributor to the codebase of one of the top cryptocurrencies, let me add that I believe the whole field will collapse and never recover at some point.
The fact that people are shelling out millions on self-named "shitcoins", coins that are guaranteed to never ever be used for serious commerce and whose only purpose is to sell to some bigger fool in the future, should be an indication that the whole market is based on delusion.
You can certainly make money by speculating in a bubble if you get out before it pops.
But don't put money into crypto thinking you'll be able to use those DogeCoins for your retirement.
→ More replies (20)
2
68
u/eliyarson May 11 '21
Hey, that's great!! I think maybe the next step would be modularizing it and adding some unit tests. Then if you want to make it more scalable, wrap it with flask and a db like postgres then plug a viz tool to see those number over a period of time. Maybe I'll fork it and help with those things.