SIMPLEST POSSIBLE Trading Bot with Python using the Binance API
HTML-код
- Опубликовано: 1 июн 2024
- Happy New Year all! :-)
Based on some feedback I built probably the simplest form of a trading bot and tried my best to make it accessible for beginners.
The Bot is holding coins which fulfill the condition of the Fast SMA (7 time step window) being above the Slow SMA (25 time step window). I am considering hourly data here.
Get the Notebook/Source code by becoming a Tier-2 Channel member:
/ algovibes
Please watch the mentioned video beforehand:
• HUGE SCALE Backtest of...
Please also watch the linked videos below that video. I am assuming some knowledge on the Binance API in this video.
Set up Binance API video:
• Introduction To Automa...
Video on setting up Cronjobs:
• Schedule Python script...
Check out my GCP playlist to execute scripts on a Virtual Machine:
• Python in the Cloud
If you want to support me you can register for Binance with this link, but don't feel forced to:
www.binance.com/en/register?r...
Disclaimer: This video is not an investment advice and is for educational and entertainment purposes only! Cryptocurrency and automated trading is bearing a high amount of risk which might result in a total loss of your invested capital.
00:00 - 01:58 General Explanation / Prerequisites / Disclaimer
01:58 - 02:58 Creating the initial csv file
02:58 - 03:32 Libraries
03:32 - 06:10 Position frame and Position Change
06:10 - 08:04 Pulling (hourly) price data from Binance
08:04 - 09:45 Calculate technical indicators and last row relevance
09:45 - 15:40 Main Trading function
15:40 - 17:08 Recap of how the Trading function works
17:08 - 18:14 Running the Trading function
18:14 - 18:15 RIP Headphone users (sorry)
18:15 - 18:38 How to deploy this script (covered in linked videos)
18:38 - 19:02 My promise!
#Python #Tradingbot #Crypto #Binance
Hi Algo, I just wanted to say huge thanks for what you are doing on this channel, you helped me a great deal!
Awesome to hear man. Thanks a lot for your comment!
You started this new year with a supreme video! My congratulations to you, and happy new year! Your fan!! 😁
Thanks a lot for your support and a Happy New Year to you as well :))
Hey man!
I really enjoy your videos! You have very good ideas and the way you explain it is easy to understand.
Keep going, your videos are great!😁
Thanks a lot for your kind words mate. That's great to hear!
I'll send this video to my mate. Btw, he's a hodler of $SAFEPLUS. Is it a good coin or rubbish? He tells its highly valuable, but it sounds too wonderful…
Happy new year man. Be healthy and keep impressing us :D
Same to you mate.
I am glad i found your channel, Algo. Thanks.
Thanks for checking out my stuff man
keeping it simple is a signature of your perfection, thanks for the nice video...
Thanks for your appreciative words and your support man
great video , always waiting for the next. Thank you much , I have really improved skills
Thank you very much for your support Kipkosgei! That's awesome to hear.
Thank you very much for sharing this knowledge. I am watching your video and studying in detail each step you wrote. Its been very helpfull for me. I had some minor issues to run the code, which i believe has to do with the jupyter version i am using. Anyway fixing this issues drove me to learn even more. I was able to make it work fine on picharm as well.
Thanks again!
Thanks a lot Fred, super happy to read that!
With each video, u inspire me to keep learning, thank you very much👍🏼
Super happy to read! Thanks a lot :-)
Watch n watch again keep spirit bro, detail n clearly, i m new, thank for make it easy
Thankful for your support mate :-)
How to convert to future usdt-m
finally cleaner code :) you improved
lol
Love your video mate, really helpful for code my algo trading myself. If I could request, can you make video about making long short index pair trade? Like long sol short srm algo bot for example
Love the name, would choose DPS all the time as well :D Pair trading is on my list but not planned in the near future. Anyhow I noted that.
great videos! I'm completely new to any programming language but would like to watch your videos in a more logical "learning" sequence. Do you have any suggestions on which one to start with? A great new year from a friend from Brazil
Obrigado my mate! :-) Probably start with the Python Introduction playlist, then the Python for finance list and then the Cryptobot playlist. Or just sort my videos from oldest to newest. Hope that is helpful!
Hello Algo. Thanks for your share. it is perfect😊
Hello mate, thanks a lot
Thank you for sharing, this is very usefull.
Thanks for watching and happy to read that!
Hi Algo, great video. Btw, I just wanna know whether the script is fetching data from Binance futures or spot. Trying to create a script for Binance futures and it can only trade whole number contracts/symbols but not fractions. I keep getting “-4003 error, quantity less than zero”. I employ leverage. Any idea how to go about it? Thanks man
I discovered your channel and I can say that I enjoy your videos. Just a question, what is the code to exchange your coins with stable coins instead of selling them?
I looked at API documentation but can’t find the information. Thanks a lot and happy new year, by the way.
Thanks man, same for you! Can you elaborate on your question please? E.g. with an example. I don't really get it - sorry.
THANK YOU
Thanks for watching :-)
Thank you for this, very well explained. One question please, how to change get_historical_klines parameters to get the values for the Futures, instead of SPOT as it is by default?
Thanks mate. client.futures_historical_klines would be the syntax change.
Thanks!
Thanks Thomas for the monetary appreciation :-)
Thanks very cool.
Still a very good source of learning
Thanks buddy :-)
Happy New Year man!
What do you use if you want to deploy your scripts to run continuously instead of using your PC?
Thanks!
Edit: Checked out your video on GCP
ruclips.net/video/mDNIAkEZChg/видео.html
Happy New Year both and thanks a lot for watching. Yes, I am using GCP for that but you could also use the other cloud provides.
Hi Algo.
Thanks for the video.
I have done a small bot for bybit, and now I will check to do something to connect with binance. So these videos will be appreciated.
Quick question, I am using btbyt testnet for my initial tests.
Is there something similar for binance?
Hi man, thanks a lot for watching. I know that there is the binance testnet.
Hi Algovibes, cool video!
Which Python IDE are you using in this video? Seems pretty nice.
Hi man, thank you very much. Using Jupyter Notebook here.
Hi Algo!! Great video and thank you a lot for that! Do you believe that trading with Heiken Ashi candes is a good idea?
Hi buddy, thank you very much. Well I don't have any experience with that but might be interesting to check that out.
thank you for such wonderful content! I spent hours trying to understand what you are doing. Can I ask you how to make the trade? I run the code thoroughly but it is not placing trades in Binance. any help?
Welcome mate! The trade is executed via the API. Can you go through the cryptobot playlist pls? Should be clear after that. Let me know if you need any further support.
Thank you for all the videos about python tradng. For this one how would you update it so that it would not hit the binance api limits?
# Prevent exceeding rate limit:
if int(client.response.headers['x-mbx-used-weight-1m']) > 1_000:
print('Pausing for 30 seconds...')
time.sleep(30)
Source:
stackoverflow.com/questions/69300571/get-historical-klines-for-multiple-pair-combination-with-a-base-usdt
BTW thanks for watching :-)
Hey. Thanks for sharing your example. Did you deploy it to trade with real money? What was your result?
Hi man,
please check out my community post from last week. I was actually posting the trading logs but I did some amendments.
I saw many algo trading programmers in youtube channel are doing the code using price lagging indicators to create a trading strategy it often worst strategy gives loss only, can you please do some price action trading strategies at least so that many are eagerly waiting guys like you to explain price action coding using paython.
That's a great tutorial for beginner algo makers like me. Can you please make a tutorial where two different symbol will be considered. One will take only long positions and another will take only short positions and obviously will maintain a csv file record so that if the algo off suddenly and need to rerun that then it will not trade same symbol again if already in position. Thanks in advance.
Thanks a lot Arunava. Appreciate your comment!
@@Algovibes but I have already solved my problem.
@@Algovibes I want to share my code with you by mail. Can you please check?
One more question please. Looking closely at the data for one coin, I observed that the values for FastSMA and SlowSMA calculated from the python code are not the same with the ones displayed by Binance. As you already stated, the formula in the bot simply takes last n values and makes an average. But the MA values displayed in Binance are calculated diferently. Is there any function that calculates the values as displayed in Binance? (maybe this is somehow intended, pretty new to crypto not sure if the indicator you use (SMA) is the same as MA used in Binance, sorry if this is the case). Thanks!
Sure man. But the values are actually the exact same. I am even showing it in this video here:
ruclips.net/video/8p240qonj0E/видео.html
What could be is that you are considering another timeframe or maybe another form of moving averages (e.g. EMAs). Can you please double check?
If I wanted to do this on FTX instead of Binance, what alterations would I need to make?
Didn't have exposure to FTX yet.
Great video ! i have a question is why my client.create_order did not work
Thanks mate, can you elaborate on what's not working?
Hello,
Nice video, sir! I would like to ask can does anyone know how to use this bot but with smoothed moving average?
Also is ther a github repo or I have to re-write it on my own?
Hi,
there is an even better option than GitHub! Becoming an Algovibes channel member. You will get access to the code and also have a huge impact supporting this channel:
ruclips.net/channel/UC87aeHqMrlR6ED0w2SVi5nwjoin
Tnx !!!
🌵❤️
It you need suggestions for new simple strategies i have one for you.
A simple two ema strategy, a short and long one (ie 5 candle for short and 13 for long). But for the long ema, if in buy mode use the hourly low candle values and for sell use the hourly high candle values.
In buy mode if short ema crosses below long ema activate trailing price buy and only buy if price increases a trailing buy percentage ie 0.4% from the lowest price and in sell mode if short ema crosses up long ema activate trailing price sell and sell when price drops x% from the highest price.
Using multiple currency in a csv file and then automate it with os scheduler is brilliant imo so you should include code to prevent hitting the binance api limits.
I hope you find this strategy intriguing and hope to see a video about it. Thanks.
Thanks a lot for your suggestion man! Cannot promise anything but have noted that.
I'd like to code a spot-futures arbitrage bot but haven't got a clue where to begin
Any ideas?
Sounds interesting. I would start with the probably most important part: Where do you get the relevant data and which manipulations do you have to do to run a proper backtest if your ideas work out.
im working on it too but i going to include more strategies and ore indicators for boosting the win potential, right doing the rsi and bb strategie but im working on more, how about we discuss and share our knowledge in a discord group ?
Sure, go ahead! Setting up a discord is on my list for this year.
Is there a way to get the binance data faster? For me it takes over a second to request 125 lines of data. Not practical for a real time strategy.
Sure. For using a bot you need a live data stream. I have covered that it other videos. Be invited to check out the cryptobot playlist.
Hi nice video but this bot only open long spot positions, it buys a currency and when the condition changes it sells that currency which means it closes the long position. My question is how you can edit this code so the bot also opens short positions?
Hi man, thanks a lot for your comment. That's right as it is spot trading. For entering short positions you would need either leveraged tokens, futures or options.
@Algovibes, Can I get the complete code to download and reuse (tweak) ?
Hey buddy, yea sure. You can just click the Join button and become a channel member and I'll add you to the Drive. Looking forward to hear from you!
please cover momentum ranking of stocks, as many small cases charging hefty fees for this in india, like ranking in NSE 500(S&P500) with 12 month look back period, % down from All time high ranking. it will be immense help for retail investors. Thank you very much for sharing your wisdom.
Hi buddy, did you already check out my momentum videos?Actually did one on the Indian market here. Let me know what you think about it below the vid:
ruclips.net/video/YIsKSQh1xpY/видео.html
@@Algovibes thank you
What IDE are you using to write the Python code?
Just Jupyter Notebook in this video.
Hi, thanks for your share.
I got an error message :
"BinanceAPIException: APIError(code=-1013): Filter failure: LOT_SIZE"
Can someone help me please ?
Lot size is order size.. this may happen either because it is lower than minimal order allowed or it can be also because you are using incorrect precision that is not allowed for this market. For example if you trade BNB, it allows you only buy/sell integer values - and when you try to set up order with more decimals - you could have same type of error.
Hi, thanks a lot for watching and big thanks to Wicked Gummy Bear (the name tho :D)
Hi! How did your bot do with the 600 dollars? :)
Posted the trading logs in the community tab!
@@Algovibes Oh cool! Didn't check there yet :) Sounds nice! Love what you're doing, I tried doing autotrading myself using NodeJS though I have a quite different strategy.
👌
:-)
How do you connect this code to a trading platform?
Not quite sure if I got your question. This is using the Binance API and thereby is connected to Binance. Or what do you mean?
would you mind working for iotA?
Can you elaborate?
Ich stoße bei festen Quantitäts Angaben früher oder später auf einen Error, aufgrund der Gebühr. Warum du nicht?
Weil ich mein Commission Asset auf BNB gesetzt hab. So spart man auch bei jedem Trade und hat das Problem nicht.
I already have a question and is that if... Do you have earnings from actually doing this?
I'm from Mexico and I have the idea to pull between $10 and $15 dollars per day, like $200 or $300 mexican pesos... Do you see this a reality?
That's a good question. There are times when bots are working pretty nicely and there are times when bots are working bad. I personally think (no investment advice) the faster the timeframe - the more hard it is to make money.
Hi. Thanks for the video. It was useful for me. But, I also checked the volume and i realized that volume sometimes is equal to volume in binance or trading view, but something is lower than it is expected. This is normal? Do you know the reason?
How to calculate ema 13 and 50 into binance API data python
Got a lot of videos on that one. Be invited to browse through my channel and let me know if you don't find anything. Cheers!
can u help makin a algo trading bot for India Banknifty option?
Hi man, thanks for watching!
Sure. I have a lot of content both in my cryptobot playlist and python for finance playlist. You will surely find something valuable there!
@@Algovibes yea i can find content on stock bot trading but not on options
does anyone else has this type of error APIError(code=-1100): Illegal characters found in parameter 'symbol'
Seems like you are passing something wrong to the function. symbol must be looking like this : "BTCUSDT"
can someone tell me what ide is he using (is it on mac?)
I will: It's Jupyter notebook (it's not an IDE tho in case someone is asking)
@@Algovibes is it paid
@@user-hu5du4yw5g Comes with the Anaconda distribution. It's free.
@@Algovibes could u give me a link, i think i have downloaded smth else
Do i need math...if it is what math should i learn.. please reply...btw...nice video
Hi mate,
Math always helps in my opinion. Video is a bit over enthusiastic but I am covering the necessary fields in detail here:
ruclips.net/video/wkU3QElFgVs/видео.html
FileNotFoundError: [Errno 2] No such file or directory: 'position'
Hi Reynold, that's an easy to solve error. You need to set up the position file in the folder where your Python script is running.
Did this exact code helped anyone earn anything so far?
Of course not. This is a coding tutorial and not an investment advice.
Can you please provide the source code ?
+1
Why you don't make a paper trading simulation ??
Is it bad ?and don't give real analytics?
No it isn't bad, I just think it's more interesting taking real prices.
But paper trading is on my list for future content!
@@Algovibes thank you
Can you make a paper trading video
How much can we earn using this?
Try it yourself and you will see
Create a paper trading account before you start trading so you don't lose real money. I can tell by your question that you aren't that experienced.
@@FreeDumb101 yes I'm not.
Well it depends. I backtested and shared my thoughts in this video, be invited to check it out:
ruclips.net/video/HB1CLz0Z1NY/видео.html
H bro i want to replica my trading idea in bot plz help me.
How can I help?
@@Algovibes i want whole class or predefine functions which i use for trading like put order , cancel order , etc in python and guidance to making bot step by step (how to make bot for beginners)
@@Algovibes plz
Great strategy. To quickly lose your money.
Haha :D Anyhow: Video is not about the strategy at all. It's a tutorial on how you could construct a trading bot based on a simple TA indicator.
ییب
Good job bro, JESUS IS COMING BACK VERY SOON;WATCH AND PREPARE
SCAM
How can a tutorial video be a scam? Can you elaborate?
Hi and thanks!
BTCUSDT and ETHUSDT working fine, ADAUSDT started throwing 'BinanceAPIException: APIError(code=-1121): Invalid symbol' (on Binance testnet).
Welcome man. Well I don't know but maybe ADAUSDT is not available on the testnet? Anyhow it works with the "real" API.
You are the best Sir, how may I contact you?
Just a random decision. The bot is just a promise I made in one of my videos. Check out the end here: ruclips.net/video/PYW4AIMEvsU/видео.html
Sir you have telegram sir?
Nope, sorry!
i just subscribed and i ll like the source code. Sent an email and still waiting for a reply
Thanks a lot! :-) Just added you!
@@Algovibes Thanks, i got it. Quick question. What will be the syntax to shorting the pair? Say market going down and i want to short the asset. I notice that was not accounted for. Thanks