How to get LIVE cryptocurrency data with Python using the Binance API / ERROR FIXING

Поделиться
HTML-код
  • Опубликовано: 12 окт 2021
  • This video is about getting live cryptocurrency data via Python using the Binance Socket Manager. It is just a solution to an error message a lot of you have experienced.
    Please provide me feedback if this is solving your error message! I would highly appreciate it!
    Source:
    python-binance.readthedocs.io...
    #Python #Crypto #Live

Комментарии • 102

  • @Algovibes
    @Algovibes  2 года назад +9

    Hi bois and girls,
    PLEASE READ:
    I dedicated some time to further investigate on this issue. Before you apply the createframe function you have to make sure you really received a message.
    You can do that easily by just applying a simple if condition after res = await tscm.recv()
    Please provide me feedback, if it works for you.
    Example:
    async def main():
    client = await AsyncClient.create()
    bm = BinanceSocketManager(client)
    ts = bm.trade_socket('BTCUSDT')
    async with ts as tscm:
    while True:
    res = await tscm.recv()
    if res:
    print(createframe(res))
    await client.close_connection()
    if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

    • @V0kai
      @V0kai 2 года назад

      Sorry but this doesn't solve the "queue overflow" error, I still have it. I'm python dev, we can talk about this?

    • @tayaamme9954
      @tayaamme9954 2 года назад

      First of all thank you for all you do. It has been a great help to me, I only started learning programming 1 month ago. This solution fixed the download problem, but now I want to upload it in the sql db. But it doesn't work. I'm trying to implement some steps from your video "How To Build a Simple Cryptocurrency Live Trading Bot with Python using the Binance API" but that doesn't work for me. I watched different video from you about SQL, but that also didn't work. Under the code I added the lines: createframe(msg) and engine = sqlalchemy.create_engine('sqlite:///BTCUSDTstream.db'), this didn't work. Then I added the lines: frame = createframe(msg) and frame.to_sql('BTCUSDT', engine, if_exists='append', index=False) after while True: in the async def main():. This also didn't work. Could you please help me fix this problem? Keep up the great work 👍

    • @agungharyanto3168
      @agungharyanto3168 2 года назад

      What is your version python sir?

  • @cactodancante1636
    @cactodancante1636 2 года назад +1

    I LOVE u and ur Cripto series! 🌵 Thanks !

  • @Anzeljaeg
    @Anzeljaeg 2 года назад +2

    6 Days ago, i woke up, saw on of your videos, today i have a bot and i keep adding layers for optimizing, and im trading , earned 2 usd and just runing test, prob was just luck , but in 3 or 4 das more , this thing will help me a lot.
    Thank you for inspiring and been a good mentor,
    Thank you bro, muchas gracias hermano, has cambiado una vida.

    • @Algovibes
      @Algovibes  2 года назад

      That's great to hear! Would be interested if you were able to make profits over the longer term.

  • @davidmanuntag
    @davidmanuntag 2 года назад +3

    Thank you for providing an update to your tutorial. I’ve tried this approach and the data stream loads perfectly. I appreciate that you are providing support and great content to the community.

    • @Algovibes
      @Algovibes  2 года назад

      Thanks for you feedback! Highly appreciated.

  • @johnharadean3078
    @johnharadean3078 2 года назад +3

    Thank you! This works for me. It prevents the error I was getting with the sqlalchemy data base. Where it'd generate frames for nearly a minute, but then stop and give me KeyError: "None of [Index(['s', 'E', 'p'], dtype='object')] are in the [columns]"

    • @Algovibes
      @Algovibes  2 года назад +1

      Hi buddy, please check my new pinned comment. That should finally solve the issue.

  • @andersonwhittle7685
    @andersonwhittle7685 2 года назад +1

    Thanks for the update - the data loads perfectly now.

    • @Algovibes
      @Algovibes  2 года назад

      Awesome. Thanks for your feedback! :-)

  • @christopherchen416
    @christopherchen416 2 года назад +3

    Thank you for providing such good content and addressing feedback/issues of your viewers! I think the topics you've made content on is really captivating and has given me the motivation to start learning python. Really like how you started with videos on fundamental mechanics and have progressed to adding more analysis.

    • @Algovibes
      @Algovibes  2 года назад +1

      Thank you so much for the feedback. That's awesome to hear!

  • @paulslacknoise
    @paulslacknoise 2 года назад +1

    Thanks a lot for the great content. I am looking into your stuff now for 6 days straight and am quite amazed by my own learning curve given your videos. I am a python beginner with some knowledge in data structures and "hndling" only so this is great

    • @Algovibes
      @Algovibes  2 года назад

      Thanks a lot for checking out my stuff man. Really appreciate it!

  • @DebugDiaries4327
    @DebugDiaries4327 2 года назад +1

    Hey Algovibes, habe erst vor kurzem deinen Kanal entdeckt und finde die Videos echt super lehrreich und interessant! Auf diese Art und Weiße funktioniert der Datastream wieder einwandfrei, nur bekommt man die Daten in viel zu hoher Frequenz. Hast du da schon eine Methode rausgefunden, wie man das regeln könnte? :) Außerdem würde mich mal interessieren, ob du schon eine Trading Strategie gefunden hast, welche wirklich dauerhaft besser performed als die Performance des Assets? Wenn nicht, werde ich auf alle Fälle selber weitersuchen :D

    • @Algovibes
      @Algovibes  2 года назад +1

      Danke Dir :-)
      Mich stört die Frequenz nicht. Du kannst aber einfach ein sleep einbauen (from time import sleep) und dann im while loop ein oder mehrere Sekunden einbauen. Dauerhaft besser performed -> nein. Ich spiele damit rum und lass ab und an mal bots laufen - einige laufen gut, andere weniger.
      Ich investiere (nicht trade) seit Jahren in cryptos. Es sind Spielereien - mehr nicht.

    • @DebugDiaries4327
      @DebugDiaries4327 2 года назад

      @@Algovibes ach ja so werde ich das mal ausprobieren. Von deinen Spielereien kann man aber auf alle Fälle viel lernen, danke dir! :)

  • @MultiXing
    @MultiXing 2 года назад +2

    I've been looking into using RL in a testing environment with a live data stream. I was curious about your opinion or insight into that. Great videos!

    • @Algovibes
      @Algovibes  2 года назад

      Awesome. Thanks a lot for your feedback :-)

  • @olivierdefosse5956
    @olivierdefosse5956 2 года назад +1

    Excellent !
    Thx a lot !!!!!
    Work without any errors for me ;-)

    • @Algovibes
      @Algovibes  2 года назад

      awesome, thanks a lot for your feedback!

  • @eduardogbarri
    @eduardogbarri 2 года назад +2

    Hello men, i got some issues when i try to run it with:
    def createframe(msg):
    df = pd.DataFrame([msg])
    df = df.loc[:,['s','E','p']]
    df.columns = ['symbol', 'Time', 'Price']
    df.Price = df.Price.astype(float)
    df.Time = pd.to_datetime(df.Time, unit='ms')
    i just put it and appears
    NONE
    NONE
    NONE...
    i[m using VSC and also a question should not be res instead msg in createframe function?

    • @Algovibes
      @Algovibes  2 года назад

      Hi buddy,
      this comment didn't show up for me. Sorry!
      msg is just the argument of the function. If you put in res that's perfectly fine.
      Were you able to solve the problem?

  •  2 года назад +2

    Some great videos, very nice, subbed!
    Can you do a video on how to detect (hidden) divergence in Python?

    • @Algovibes
      @Algovibes  2 года назад

      Thank you man! Appreciate your support. Also thanks for the suggestion!

  • @romeogaming6424
    @romeogaming6424 2 года назад +1

    Thanks! it work for me :)

    • @Algovibes
      @Algovibes  2 года назад

      Thanks again for your feedback.

  • @rokjurse340
    @rokjurse340 2 года назад +1

    Hi mate! awesome channel! New suscriber here. I've done two bots from your "guides" with no problems, but the third one altcoin one is bugging me!
    I have an error like some of the comments there and you directed them here, but I cant figure it out how to implement this in to that code... Some help would be apreciated!
    Btw I love all of your videos, keep it up man!

    • @Algovibes
      @Algovibes  2 года назад

      Hi man, thank you very much. Did you check out the approach using the Unicorn library in one of my newer videos?
      E.g. here:
      ruclips.net/video/Ml6LUH2wxgc/видео.html

  • @HyperCactus
    @HyperCactus 2 года назад +2

    Thank you sooo much

    • @Algovibes
      @Algovibes  2 года назад +2

      Thanks for watching mate :-)

  • @ZiZaK2
    @ZiZaK2 2 года назад +1

    It worked for me, thank you bro

    • @Algovibes
      @Algovibes  2 года назад

      Nice :-) Thanks for your feedback buddy.

  • @adri4150
    @adri4150 2 года назад +1

    The code works fine, thanks for the video.

    • @Algovibes
      @Algovibes  2 года назад

      Awesome. Thanks for the feedback!

  • @michaelkvopka4699
    @michaelkvopka4699 2 года назад +1

    Great video. Do you know if it's possible to add a SL or TP to a futures order on binance?

    • @Algovibes
      @Algovibes  2 года назад

      Thanks mate. On the platform Binance itself? I am not quite sure.

  • @TerraFirmaFactoids
    @TerraFirmaFactoids 2 года назад +1

    useful video, thanks for posting!

    • @Algovibes
      @Algovibes  2 года назад

      Thanks for your feedback! :-)

  • @edouglas1143
    @edouglas1143 2 года назад +1

    When running the code I received a ImportError. The code could not import name AsyncClient from Binance

    • @Algovibes
      @Algovibes  2 года назад +1

      But did you install the python-binance lib?

  • @eliotharreau7627
    @eliotharreau7627 2 года назад +1

    Hi Bro, I have two error -module 'asyncio' has no attribute 'apply' ?? And the same probleme when I try to run the last loop : RuntimeError: This event loop is already running ?? I use Python 3.7. Any sugestions ? Thnx.

    • @eliotharreau7627
      @eliotharreau7627 2 года назад +1

      Sorry it s just working now. wrong usage !!! 😉

  • @alfredart6822
    @alfredart6822 2 года назад +1

    Thank you, this is working great for me. No errors.
    I am uncertain now how to leverage this to use it on the RSI, stoic, MACD code. I have been at it for 2 weeks. Yes, I have never seen code before November 2021.
    Also, I was thinking that the RSI, stoic, MACD could benefit from the MTF EMA, where one line is 15 minutes 50, the second line is 60 minutes 50. Any documentation I can use. Thanks.

    • @Algovibes
      @Algovibes  2 года назад

      Hi Alfred, thanks a lot for your feedback.
      I am planning on release a video on trading technicals with this approach. I have covered it already here:
      ruclips.net/video/g04GeHe-dJw/видео.html
      and in specific here:
      ruclips.net/video/nQkaJ207xYI/видео.html
      Let me know if this is helpful for you or what you are still missing.

  • @Durtle02
    @Durtle02 2 года назад +1

    Works great! However it requests much faster than once per second. What is the best way to limit the rate of requests?

    • @Durtle02
      @Durtle02 2 года назад +1

      I've tried using the "user_timeout=1" parameter in the Socket Manager function but it doesnt seem to change anything but I may be misunderstanding how the parameter works. The other thing I've tried, and seems to work well enough, is on each message recieve taking the current date time and the last time I recorded data and checking to see if the difference is 1. That seems to work well but does add some discrepancies. Thank you for the videos!

  • @alexeyfilippov8924
    @alexeyfilippov8924 2 года назад +1

    thank you, yes, that's how it works

    • @Algovibes
      @Algovibes  2 года назад

      Thanks for watching mate. I have shown another more handy approach in my newer vids btw. Be kindly invited to check them out!

  • @nitrixpendragon2908
    @nitrixpendragon2908 2 года назад +1

    Hello, I have the error message:
    As of 3.10, the *loop* parameter was removed from Queue() since it is no longer necessary
    Are you using Python 3.10 in the above video? If so are there any fixes to this?

    • @Algovibes
      @Algovibes  2 года назад +1

      Fixes on that would be to use Websocket. I have covered it e.g. here:
      ruclips.net/video/mDNIAkEZChg/видео.html
      and here:
      ruclips.net/video/8p240qonj0E/видео.html
      Let me know if this was helpful!

    • @nitrixpendragon2908
      @nitrixpendragon2908 2 года назад

      @@Algovibes okay thanks so much! keep up the great content :)

  • @intyelcapo
    @intyelcapo 2 года назад +1

    Thank you, Can you try to do a pairs trading strategy on python ?

    • @Algovibes
      @Algovibes  2 года назад +1

      Thanks for watching and also thanks for the suggestion :-)

  • @nnaryna2824
    @nnaryna2824 9 месяцев назад +1

    How much time you need for getting live data about around 300 crypto? in seconds/minutes

    • @Algovibes
      @Algovibes  9 месяцев назад

      not more than some seconds

  • @bernert23
    @bernert23 2 года назад +1

    Hello, I tried to apply this solution to the tutorial on the other video, but i still get the following error:
    {'e': 'error', 'm': 'Queue overflow. Message not filled'}
    KeyError: "None of [Index(['s', 'E', 'p'], dtype='object')] are in the [columns]"
    Can you please give me some help?
    Thanks!

    • @Algovibes
      @Algovibes  2 года назад +2

      Could you try the following (I am referring to the while Loop in THIS video not the one in the strategy video)
      After while True:
      put in a sleep function -> time.sleep(2) or any other number of seconds.
      Could you do that and try it again and give me feedback? Much appreciated!

    • @bernert23
      @bernert23 2 года назад

      @@Algovibes Thanks for the reply, I tried to add the time.sleep but i keep getting the same issue, I am trying to merge both solutions in order to have it working, but not sure why i just can't make this work.

  • @gia6701
    @gia6701 11 месяцев назад +1

    Work!!!

    • @Algovibes
      @Algovibes  11 месяцев назад

      nice, thanks for watching :-)

  • @OursIslam
    @OursIslam 2 года назад

    I have noted that after some time the loop somehow stops and we get no msg. I wonder what is the solution to automatically restart the socket perhaps providing custom time out to close connection and restart. Could you please explain how to do this way?

    • @Algovibes
      @Algovibes  2 года назад

      Could you provide more details? When does the stream stop exactly? It disconnects after 24 hours automatically btw.

  • @user-eo1jo8dh4t
    @user-eo1jo8dh4t 2 года назад +1

    Thank you for your videos. I have some issues with this code before. With this fix it working. Can you show live candlestick stream with dataframe.

    • @Algovibes
      @Algovibes  2 года назад +1

      Awesome. Thanks for your Feedback, Spasibo :-) The Kline stream is pretty straightforward. You just change the socket to:
      ks = bm.kline_socket('BNBBTC', interval=KLINE_INTERVAL_30MINUTE)
      source: python-binance.readthedocs.io/en/latest/websockets.html

  • @fredcastro2645
    @fredcastro2645 Год назад

    Hello friend! Its been a long time since you posted this content but surely i had to give you a feddback. It worked just fine for me. I had issue with the previous approach but this one is working.
    So, i want very much to thank you. First for sharing such a great knowledge for free, and also for keeping it alive by clearing the eventual issue that may occur. God bless you!

    • @Algovibes
      @Algovibes  Год назад

      Thank you for your kind comment Fred. Appreciate it! BTW I actually recommend using the unicorn - super easy to use and works well on multiple coins - check it out here (and the linked videos below the vid):
      ruclips.net/video/hope9jJICRs/видео.html

  • @maximilianrepstat3716
    @maximilianrepstat3716 2 года назад +1

    in python 3.9 I don't have any problem to run the socket stream, but in 3.10 I get the error that there is no running loop. I already tried your fixes in this video. Can you help me to solve this? Thanks for your great videos!!

    • @Algovibes
      @Algovibes  2 года назад +1

      hmmm...do you have more details on your setup (which IDE,...)?

    • @maximilianrepstat3716
      @maximilianrepstat3716 2 года назад +1

      @@Algovibes I use PyCharm and a virtual environment for the interpreter... I know that something has changed in asyncio with 3.10 but I don't know what and how to fix

  • @boteliotbot5431
    @boteliotbot5431 2 года назад +1

    Hi nice vid. How to split the frame minute by minute ? Thnx.

    • @Algovibes
      @Algovibes  2 года назад +1

      Can you check out the videos in the cryptobot playlist please? I was using data manipulations and stuff like that there.

  • @TomFilmHUN
    @TomFilmHUN 2 года назад +2

    Great videos! I'm getting a "loop.stop ()" problem and I'm getting an error message:
    ----> 1 loop.stop ()
    NameError: name 'loop' is not defined
    If I take out the line then the code will run.

    • @Algovibes
      @Algovibes  2 года назад +1

      Thanks mate. This is not part of the code. Just delete it. I just wanted to check if I can stop the Loop without crashing the kernel (which is another loop running) but I couldn't. Just ignore that.

    • @TomFilmHUN
      @TomFilmHUN 2 года назад

      @@Algovibes ohhh, right!
      Thanks!

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +1

    Thank you, you did so much good work, you never had a desire to create a graphical application so that everything is already in place and a database of quotes for quick analysis and your candlestick charts, and baсktesting strategies and a robot for trading

    • @Algovibes
      @Algovibes  2 года назад

      Thank you mate! Of course I have the desire to build nice stuff. Anyhow I probably wouldn't benefit much of a GUI like you described. Or where do you see the advantages?

  • @Mhgmusicvideos
    @Mhgmusicvideos 2 года назад +1

    Thanks for all your videos! Very helpful and clearly explained!
    I've tried this new code and I don't get an error I just get the >>> cursor!! That is all!!
    Any idea why that may be?
    Running 3.9 and the IDLE on a Mac....
    Thanks in advance!

    • @Algovibes
      @Algovibes  2 года назад

      Very welcome!
      Not quite sure but I am showing how you are doing it in an IDE here somewhere around minute 9:
      ruclips.net/video/nQkaJ207xYI/видео.html

  • @alpsgrin4501
    @alpsgrin4501 2 года назад +2

    how to draw incoming bitcoin prices in real time on a chart in colab or IDE with different timeframes? Please show it

  • @polkobra5455
    @polkobra5455 Год назад +1

    Does anyone else get the problem that 'DataFrame' has no attribute 'Time'?

    • @Algovibes
      @Algovibes  Год назад

      No, where did you deviate from the code?

    • @polkobra5455
      @polkobra5455 Год назад +1

      @@Algovibes haha i deviated you are right. I already fixed it. Thanks for answering though!

  • @neXib
    @neXib 2 года назад

    Loving your content, but I must say my first thoughts as a web programmer by profession when watching your videos was that you are also teaching a lot of people how to hammer the binance api, which I guess could lead to people being temporarily blocked. But I wasn't sure if there was some built-in throttling as I don't use Python much daily. Still, your content is great and I'm learning a lot. I'm trying to get up to speed, but still on your early crypto/python tutorials.
    I'd love to see an example of creating a strategy and not creating orders, but actually pretend to do the orders, add them to a sql database, and then being able to simulate how your strategy works on live data, if it made loss or profit, or maybe trying it on a different coin, different time etc. . So you can adjust it, and just duplicate it and make it do the orders after being satisfied.

    • @Algovibes
      @Algovibes  2 года назад

      Thanks for your comment! The streams are the recommended way to pull the data. I did some examples to show the main concepts. Where do you see hammering api calls in this video?
      BTW also thanks a lot for your suggestion!

    • @neXib
      @neXib 2 года назад

      @@Algovibes It wasn't meant as criticising as I'm not sure how it works. Does the socket actually control how many requests are sent to the API? The reason I ask is that I figured a while loop would ask hundreds of times per millisecond otherwise, like it would process as fast as it possibly can and start over :)

    • @danielqian8899
      @danielqian8899 2 года назад +2

      @@neXib The way I understand it is that a Binance Client is a persistent TCP connection. From network security perspective, if the script created numerous new connections in the while loop( too many requests per second) Binance API server would consider it as a DOS attack and block the IP the script runs from. it is probably not an issue in this case if all the requested data by while loop is transferred within that single one established TCP connection. Please correct me if I am wrong here about the Binance Client concept

  • @magnodeniro6121
    @magnodeniro6121 2 года назад +1

    OI muito prazer curti de mais esse tutorial me ajudou muito a esclarece o erro do asyncio, mais eu agora estou com dificuldades de fazer esse mesmo processo em múltiplas moedas 🤖🤖🤖🤦‍♂

    • @Algovibes
      @Algovibes  2 года назад

      Hey buddy, thanks for your comment. Was using a translator as I am not fluent in Portuguese. You are invited to check out my cryptobot playlist, in specific the newer videos. I am using a livestream on multiple cryptos there - so exactly what you are looking for.

  • @thechoosen4240
    @thechoosen4240 Год назад

    Good job bro, JESUS IS COMING BACK VERY SOON;WATCH AND PREPARE