sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.16k stars 2.23k forks source link

Streams API docs dysfunctional #805

Open adrianmay opened 3 years ago

adrianmay commented 3 years ago

The suggested code:

from binance.websockets import BinanceSocketManager
bm = BinanceSocketManager(client)
# start any sockets here, i.e a trade socket
ts = bm.trade_socket('BNBBTC')
# then start receiving messages
async with ts as tscm:
    res = await tscm.recv()
    print(res)

does not compile because the module is now called "streams" and because async can't be used outside of a functoin. Following python's async docs suggests:

 async def x():                        
        async with ts as tscm:
            res = await tscm.recv()
            print(res)

loop = asyncio.get_event_loop()
loop.run_until_complete(x())

but this prints only one trade, then times out and exits.

Please provide a working sample.

sammchardy commented 3 years ago

@adrianmay you were close. The examples in the main README may help you more.

async def x():                        
        async with ts as tscm:
            while True:
                res = await tscm.recv()
                print(res)

loop = asyncio.get_event_loop()
loop.run_until_complete(x())
Angus-Less commented 3 years ago

You should probably update the documentation to this new system as it's rather confusing with the sudden library structure and having to refactor the codebase to fit this. I just understand why this was changed, when there was no apparent issue with the system.

adrianmay commented 3 years ago

I tried it with 'while true' too. Same result. Python's websocket docs don't have a 'while true'.

sammchardy commented 3 years ago

Also created a longer blog post with asyncio basics and examples

https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html

adrianmay commented 3 years ago

Got a 404 for that. You say "blog". Is that where people would look? Is the main doc being updated?

Thanks tho! Adrian.

On Tue, 4 May 2021 at 10:59, Sam McHardy @.***> wrote:

Also created a longer blog post with asyncio basics and examples

https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/805#issuecomment-831823328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAARMR6TO7SZHSBCDTUQG3LTL7AO3ANCNFSM436APPOQ .

sammchardy commented 3 years ago

There are examples in the repo README https://github.com/sammchardy/python-binance

The websockets documentation had been updated https://github.com/sammchardy/python-binance/blob/master/docs/websockets.rst

The depth cache documentation had also been updated https://github.com/sammchardy/python-binance/blob/master/docs/depth_cache.rst

It seems these docs aren't updating on rtd.

The blog link is fixed now. https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html

Let me know what that's missing.

sammchardy commented 3 years ago

https://python-binance.readthedocs.io/ is now up to date

sammchardy commented 3 years ago

As an alternative to the new asyncio websocket class you can now use the ThreadedWebsocketManager class which abstracts away any asyncio requirements for you.

some examples here in the docs https://python-binance.readthedocs.io/en/latest/websockets.html

Angus-Less commented 3 years ago

I Appreciate the updates and the timely responses. Thanks