使用python-binance获取订单深度,但代码未完成

问题描述 投票:0回答:3

我正在运行一个Python脚本来获取所有以USDT结尾的符号的当前订单簿。

每当我尝试运行它时,它都会获取前三个交易品种的订单簿(在本例中为 BTCUSDT、ETHUSDT 和 BNBUSDT)。有人知道我在这里搞砸了什么吗?

我正在使用这个逻辑来获取交易品种和订单簿的列表;

import asyncio
import config as c #from config.py
import infinity as inf #userdefined function for infinity (probably not needed)

from binance import AsyncClient, DepthCacheManager, Client


client = Client(c.API_KEY, c.API_SECRET, tld = 'com')

info = client.get_exchange_info()
symbols = info['symbols']

ls = []

for s in symbols:
    if 'USDT' in s['symbol']:
            #if 'BUSD' not in s['symbol']:
            ls.append(s['symbol'])

async def main():
    
    # initialise the client
    client = await AsyncClient.create()

    for i in ls:
        async with DepthCacheManager(client, symbol= i, limit = 10000) as dcm_socket:
                depth_cache = await dcm_socket.recv()
                symbol = i
                asks = depth_cache.get_asks()[:5]
                bids = depth_cache.get_bids()[:5]
                full = [symbol, asks, bids]
                print(full)
            
    
if __name__ == "__main__":

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
python asynchronous python-asyncio binance
3个回答
0
投票

它不会完成,因为它不应该完成。 DepthCacheManager 旨在建立连接 (WebSockets),获取订单信息的快照,然后订阅其在“DepthCache”中本地应用的当前未完成订单的更新流。每次更新时,它都会提供更新的当前要价/出价集,如您所见。
交易和订单永远不会停止,那为什么会停止呢?


0
投票

也许你想尝试:https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache

import unicorn_binance_local_depth_cache

ubldc = unicorn_binance_local_depth_cache.BinanceLocalDepthCacheManager(exchange="binance.com")
ubldc.create_depth_cache("LUNABTC")

asks = ubldc.get_asks("LUNABTC")
bids = ubldc.get_bids("LUNABTC")

就是这样:)


0
投票

我创建了一个解决方案,理论上可以在 Kubernetes 集群中操作和检索任意数量的 DepthCache。 DepthCache 可以冗余创建,然后支持负载平衡和故障转移。

币安 API 权重成本已考虑在内且不超过。

我们目前仍在测试中,暂时仅提供测试许可证,直到我们知道我们的工具有多可靠为止。

GitHub:https://github.com/LUCIT-Systems-and-Development/unicorn-depthcache-cluster-for-binance

这是一个演示视频,其中 298 个 Binance Futues DepthCache 每个启动两次: https://youtu.be/LTWeBNcpIp4

如果有人想免费测试,请联系我: https://www.lucit.tech/get-support.html

致以诚挚的问候,

奥利弗

© www.soinside.com 2019 - 2024. All rights reserved.