比较两个命令列表中的字符串:python-binance

发布于 2025-02-09 11:04:59 字数 716 浏览 2 评论 0原文

Python -Binance-找到具有USDT和BUSD市场的货币。

我想使我的代码比较USDT和BUSD市场书籍,并且只有两个市场中的回报货币。

search_busd/search_usdt函数返回字典列表。

'''

[{'symbol': 'BNBBUSD', 'bidPrice': '213.00000000', 'bidQty': '111.38000000', 'askPrice': '213.10000000', 'askQty': '65.38800000'}, .......

'''

market_book = client.get_orderbook_tickers()

def search_USDT(market_book):
    return [element for element in market_book if element['symbol'].endswith('USDT')]

def search_BUSD(market_book):
    return [element for element in market_book if element['symbol'].endswith('BUSD')]

for element in search_USDT(market_book):
    print(element['symbol'], element['symbol'][:-4])

Python-binance - find currencies that have both USDT and BUSD markets.

I want to make my code compare the USDT and BUSD market books and only return currencies that are in both markets.

The search_BUSD/search_USDT functions return a list of dictionaries.

'''

[{'symbol': 'BNBBUSD', 'bidPrice': '213.00000000', 'bidQty': '111.38000000', 'askPrice': '213.10000000', 'askQty': '65.38800000'}, .......

'''

market_book = client.get_orderbook_tickers()

def search_USDT(market_book):
    return [element for element in market_book if element['symbol'].endswith('USDT')]

def search_BUSD(market_book):
    return [element for element in market_book if element['symbol'].endswith('BUSD')]

for element in search_USDT(market_book):
    print(element['symbol'], element['symbol'][:-4])

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽蝶幻影 2025-02-16 11:04:59

尝试以下操作:

usdt = search_USDT(market_book)
busd = search_busd(market_book)
result = set()

for currency in usdt:
    if currency != 'symbol' and currency in busd.keys():
       result.add(currency)

Try this:

usdt = search_USDT(market_book)
busd = search_busd(market_book)
result = set()

for currency in usdt:
    if currency != 'symbol' and currency in busd.keys():
       result.add(currency)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文