twmarket
操作指南

非同步查詢

非同步查詢

AsyncClient 的查詢方法與 Client 同名,呼叫時使用 await,連線以 async with 管理。獨立查詢可用 asyncio.gather 並行;多筆同類報價使用 quote_many 保留逐筆錯誤。

import asyncio
from twmarket import AsyncClient

async def main():
    async with AsyncClient() as market:
        listed, otc = await asyncio.gather(
            market.twse.quote("2330"),
            market.tpex.quote("6488"),
        )
        print(listed.last, otc.last)

asyncio.run(main())

一般非同步 HTTP 查詢不需要 stream 延伸。asyncio.gather 中任一查詢失敗時會拋出例外;逐筆成功/失敗結果見 批次查詢。Client 參考