Created
February 5, 2024 15:15
-
-
Save MtkN1/430952f642440778d597b376e79957b8 to your computer and use it in GitHub Desktop.
Rate limit test for GMO Coin WebSocket
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 json | |
import logging | |
from contextlib import AsyncExitStack | |
import websockets | |
logger = logging.getLogger("websockets.client") | |
logger.setLevel(logging.DEBUG) | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.DEBUG) | |
ch.setFormatter( | |
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | |
) | |
logger.addHandler(ch) | |
async def main(): | |
public_uri = "wss://api.coin.z.com/ws/public/v1" | |
public_message = {"command": "subscribe", "channel": "ticker", "symbol": "BTC_JPY"} | |
public_message = json.dumps(public_message) | |
private_uri = "wss://api.coin.z.com/ws/private/v1/xxxxxxxxxxxxxxxxxxxx" | |
private_message = {"command": "subscribe", "channel": "positionSummaryEvents"} | |
private_message = json.dumps(private_message) | |
async with AsyncExitStack() as stack: | |
async with asyncio.TaskGroup() as tg: | |
t_public_ws = tg.create_task( | |
stack.enter_async_context(websockets.connect(public_uri)) | |
) | |
t_private_ws = tg.create_task( | |
stack.enter_async_context(websockets.connect(private_uri)) | |
) | |
public_ws, private_ws = t_public_ws.result(), t_private_ws.result() | |
async with asyncio.TaskGroup() as tg: | |
tg.create_task(public_ws.send(public_message)) | |
tg.create_task(private_ws.send(private_message)) | |
await asyncio.Future() | |
try: | |
asyncio.run(main()) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subscriptions have successfully... 🤔