sammchardy / python-binance

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

FuturesDepthCacheManager parameters: limit is invalid #1237

Open 1163849662 opened 1 year ago

1163849662 commented 1 year ago

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

halfelf commented 1 year ago

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

1163849662 commented 1 year ago

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

halfelf commented 1 year ago

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.

1163849662 commented 1 year ago

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

除此之外,需要继续接收增量深度消息以保持本地订单簿的更新。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