python-binance
python-binance copied to clipboard
FuturesDepthCacheManager parameters: limit is invalid
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())
I can't find out where is the limit is invalid
bug. The code seems work as expected.
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
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.
限制参数不是你想的那样。它用于指定初始化订单簿时获得多少级别。
除此之外,需要继续接收增量深度消息以保持本地订单簿的更新。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 printing10
.For a fix, one has to inherit
FuturesDepthCacheManager
and override_get_socket
method to correctly subscribewss://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