How To Build a Simple Cryptocurrency Trading Bot with Python and the Binance API



Hi everyone, I made some simplifications and further amendments to the already covered trading bot on the Slow / Fast SMA …


47 Comments

  1. Thanks so much my friend !
    BTW, I'd love to join binance and reference you in whatever way possible but the binance is way over-strict in their acceptance of new customers. I mean, I turned myself into a darn monkey in front of the web cam, nodding, smiling, opening my mouth, holding the IDs and still got rejected. I tried my passport, drivers license, id… No… I think I just have to put my xrays showing my bones (MRI scan results might do better idk) to prove I have no intention to rob them.

  2. Hi! and thank you for the video it is very helpful and I learned so much from it. I noticed that this bot can trigger buy orders in the middle of the bullish run (especially when starting it for the first time or after a restart) and I think I might have figured a way to prevent this by using an AND condition when checking fastSMA and slowSMA in the BUYING for loop. We need to use an AND condition to check that the row before the last row is the inverse, and i believe this will ensure that it will trigger a buy order only at the begining of the bullish run. I would love your comment on this and I have included my coded solution below. also is the data request rates within binance's limit?

    lastrow = df.iloc[-1]

    beforelastrow = df.iloc[-2]
    if lastrow.FastSMA > lastrow.SlowSMA and beforelastrow.SlowSMA > beforelastrow.FastSMA:

  3. Thanks a lot man ! I have a question: Do these two lines below serve the same purpose for reaching quantity value ? posframe.loc[posframe.Currency==curr, 'quantity'] /// posframe[posframe.Currency==coin].quantity.values[0]

  4. Hi Algo, thanks for the great video!
    Is the posframe updated automatically in its notebook while the trader function runs in a separate notebook?
    How do we make the posframe reflect changes in quantity and position automatically while the bot is running?
    Thanks a ton for your help!

  5. Hi Algovibes , this framework is great , how can it be improved further , in a situation where the cloud service( I am using pythonanywhere) stops and restarts , the data held in the posframe is lost , so when they restart the bot after a few seconds, the bot forgets about the assets already held in the posframe, any solution to this? a situation where after a restart the bought checks the assets already in the posframe. Thanks for the great work

  6. Thank you very much for sharing your vast knowledge with everybody!
    I´m trying to do a similar script (using a CSV file) and I´d like to run it in the cloud 24/7, should I create a Windows VM in GPC?
    Thanks in advance!

  7. Could a simpler trading bot be made where you enter in the first order and the bot goes off of that. Say the stock is at .0125 and you buy. Could you design the bot to simply sell if it goes to .0126? Then when it goes back down to 0.125 buy again? And if it doesn't reach that in an allocated amount of time, cancel the bot and wait for the user to initiate a trade again. And at a stop loss, the user has to re-initiate the trades. Rather than using indicatiors, databases, etc…

  8. Cool! I like that. I know this is a proof of concept, but there is room for improvement. Let me point out the most obvious. You need run the trade function only once per candle. In this case as the bot is trading based on the hourly timeframe, the trade function should run only once per hour. If it simply runs in an endless loop without a break, it would open positions on the first iteration and then on the further iterations do nothing except logging until the next candle. I do this even more optimized by subscribing to the chart data via WebSocket. When the exchange pushes a new candle to my bot, the trade funtion is triggered.

  9. Thank you so much for the content. One question though. If we want to get a ticker for a certain coin, should we use a WebSocket or just (I'm trading in futures market) futures_klines(…) inside an infinite loop? I am asking cause a lot of times I have encountered a timeout exception that terminates my program and after a lot of research, I haven't found a clean solution around it so now I'm thinking to refactor most of my code (i'm using the second way).

  10. Hey, that's a great video! I think it's possible to create some mock instead of real binance client and try this bot in "test mode", right ? Just run it for a month in some cloud and see the actual profit. Has anyone tried it ?

  11. I would likt to build a live trading simulation for Binance. So unlike backtesting i would like to use live data to test an algorithm without actually having to spend money. Do you know how i could use the Binance API for that? Would that maybe qualify as a Idea idea for you? Would love to see that. Great Videos, you really show that it's not that hard to build your own trading bots!

  12. Thank you very much, but I would like to ask you if I am going to not open a simple one that if the % goes down that the first purchase action takes when it goes down 2% that I buy, for example, and if the price that I sell increases by 2%.
    And every few seconds or minutes thereafter you can execute the next buy order on that pair or other crypto pairs at the same time on Binance spot.

    So it takes time to go down or up, that process will be automatic, without indicators or anything, just adjusting the percentage of purchase and sales.

  13. I've tried doing this, but for a different strategy. Will run this overnight and see how it goes. Thank you for sharing this! I've just learned python just to create a bot lol. Question tho, I'm just wondering, since our trigger is FMA > SMA, what if when we ran the code, we're at an all-time-high, then the bot would execute a trade, right? but then it dips and trigger our sell condition, wouldn't that be instantly a loss? Should I be too concerned with that? What is the best way to go about that? Just wait until I recover that initial loss through the succeeding trades?

  14. Nice video! Please keep it up! I am currently learning on how to make a trading bot in python. Your video inspired me a lot!
    btw, I have difficulty on calculating the EMA. I want to use same EMA value as what binance shown.
    If I use the live data to calculate it, it takes really long time to let the bot's EMA converge to binance's EMA.
    Can you make a video on this? (calculating the indicator involving history and live data)

  15. Hi, you tend to use the top 50 market cap coins in your symbol list. I use the full symbols available to trade. I wonder if using the best 50 performers may work better than market cap. That way each time it runs, it get new symbols and the best preforming ones. Great video, have really enjoyed playing about with this.

  16. hello Man,

    thank you for the great content and for making things way simple.

    i tried using the code but it doesnt run, actually the trader function doesnt enter the first for loop. dont know why? can you help me with that?

  17. How did you create the CSV file? I never seen that program before. What are you using? I just see Local Host and that is all. Thank you again for teaching me how powerful Python is.

  18. Sure a stupid question, but I've been running this code for 4 days and it's not selling. I find that a little strange. Can you help why it does not sell ;/

  19. Where are my comments ?? Twice deleted 🙁
    Here are they… again:
    Great!

    I've only been a fan for a few weeks, and you changed my whole outlook! Your clear and precise explanations, your ideas, and the way you implement them so easily in Python have shed a lot of light in the long dark tunnel where I have been for so long :-))))) So just: THANK YOU !!

    1. I keep all your buying strategies handy, and for selling I apply the following rule: SL at x% of my buy price, then a trailing stop at y%.

    2. I am looking for an algorithm on the Volume: DeltaVolume for 1m gives peak values ​​10, 100 (and sometimes more) higher just before a nice climb (example GALA tonight on 03.13.2022 from 0:30 to 2:45) … you may have already covered this topic? What do you think ?

    3. Would it be possible to make a video with Binance Future? and adaptation of a lever for example when switching to BreakHeaven?

    4. I saw that you have a private channel… what are the possibilities and advantages of being a member?

    5. …. lots of things in your head with each new video … so again THANK YOU THANK YOU THANK YOU … and keep it up, you're on TOP 🙂

  20. dude, first of all Thank you for your time and effort and for sharing your knowledge.. Ive been learning python 3 for data analysis, ai, machine learning and obviously automated trading on API level.. As time progresses I would like to analyze vast amounts of data on crypto and other commodities to get a better understanding of the market psychology of any asset through data points gathered… and hopefully train my Ai to make more informative trades.. I am still a beginner in all of this.. But Ive subscribed to you, So I could learn more towards my medium term goals.. Thanks again for sharing, and please keep up!

Comments are closed.