python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

FuturesDepthCacheManager parameters: limit is invalid

Open 1163849662 opened this issue 2 years ago • 4 comments

Describe the bug FuturesDepthCacheManager parameters: limit is invalid

To Reproduce

import asyncio from binance import AsyncClient, DepthCacheManager from binance.depthcache import FuturesDepthCacheManager

async def main(): client = await AsyncClient.create() # dcm = DepthCacheManager(client, 'BTCUSDT', limit=1000, ws_interval=0) dcm = FuturesDepthCacheManager(client, 'BTCUSDT', limit=100)

async with dcm as dcm_socket:
    while True:
        depth_cache = await dcm_socket.recv()
        print(len(depth_cache.get_asks()))

if name == "main": loop = asyncio.get_event_loop() loop.run_until_complete(main())

2022-08-24 1 54 07

1163849662 avatar Aug 23 '22 17:08 1163849662

I can't find out where is the limit is invalid bug. The code seems work as expected.

halfelf avatar Aug 24 '22 01:08 halfelf

I can't find out where is the limit is invalid bug. The code seems work as expected.

Using 'depth_cache.get_asks()' I want to get 100 asks depth data, but there are only 10. I need any configuration. thanks

1163849662 avatar Aug 24 '22 05:08 1163849662

The limit parameter is not what you think. It is used to specify how many levels are got when initializing the order book.

Besides that, one needs to continue receiving incremental depth message to keep one's local order book updated. Binance has a detailed instruction about this in their document.

Back to python-binance, IMHO (I may be wrong about this), the coroutine stream it is not implemented correctly for this, since the incremental depth message has a hard-coded default depth argument of 10, which is used by FuturesDepthCacheManager directly. That's why your codes keep printing 10.

For a fix, one has to inherit FuturesDepthCacheManager and override _get_socket method to correctly subscribe wss://fstream.binance.com/stream?streams=btcusdt@depth incremental depth stream, without any depth limit.

halfelf avatar Aug 24 '22 06:08 halfelf

限制参数不是你想的那样。它用于指定初始化订单簿时获得多少级别。

除此之外,需要继续接收增量深度消息以保持本地订单簿的更新。Binance 在他们的文档中对此有详细说明。

回到python-binance,恕我直言(我可能错了),协程流没有正确实现,因为增量深度消息有一个硬编码的默认深度参数10,FuturesDepthCacheManager直接使用。这就是您的代码不断打印的原因10

对于修复,必须继承FuturesDepthCacheManager和覆盖_get_socket方法才能正确订阅wss://fstream.binance.com/stream?streams=btcusdt@depth增量深度流,没有任何深度限制。

The limit parameter is not what you think. It is used to specify how many levels are got when initializing the order book.

Besides that, one needs to continue receiving incremental depth message to keep one's local order book updated. Binance has a detailed instruction about this in their document.

Back to python-binance, IMHO (I may be wrong about this), the coroutine stream it is not implemented correctly for this, since the incremental depth message has a hard-coded default depth argument of 10, which is used by FuturesDepthCacheManager directly. That's why your codes keep printing 10.

For a fix, one has to inherit FuturesDepthCacheManager and override _get_socket method to correctly subscribe wss://fstream.binance.com/stream?streams=btcusdt@depth incremental depth stream, without any depth limit.

Does this mean that I need to modify the source code? Can you give a minimum strength, sorry I'm a rookie

1163849662 avatar Aug 26 '22 08:08 1163849662