Created
September 5, 2023 05:36
-
-
Save MtkN1/3f74f0963c71044b8936a8c02c57a636 to your computer and use it in GitHub Desktop.
Asynchronous request to bitFlyer using HTTP/2 with HTTPX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import time | |
import httpx | |
async def main(): | |
for use_http2 in (False, True): | |
async with httpx.AsyncClient( | |
base_url="https://api.bitflyer.com", http2=use_http2 | |
) as client: | |
# open connection | |
await client.get("") | |
# asynchronous request | |
sta = time.monotonic() | |
await asyncio.gather( | |
client.get("/v1/getboard?product_code=BTC_JPY"), | |
client.get("/v1/getboard?product_code=XRP_JPY"), | |
client.get("/v1/getboard?product_code=ETH_JPY"), | |
client.get("/v1/getboard?product_code=XLM_JPY"), | |
client.get("/v1/getboard?product_code=MONA_JPY"), | |
client.get("/v1/getboard?product_code=ETH_BTC"), | |
client.get("/v1/getboard?product_code=BCH_BTC"), | |
client.get("/v1/getboard?product_code=FX_BTC_JPY"), | |
client.get("/v1/getboard?product_code=BTCJPY08SEP2023"), | |
client.get("/v1/getboard?product_code=BTCJPY15SEP2023"), | |
client.get("/v1/getboard?product_code=BTCJPY29SEP2023"), | |
) | |
end = time.monotonic() | |
print(f"{use_http2=:}: {end - sta:.6f} sec") | |
"""STDOUT | |
use_http2=False: 0.133507 sec | |
use_http2=True: 0.028044 sec | |
""" | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment