{"id":10054,"library":"powerbot-client","title":"PowerBot Client","description":"The powerbot-client library provides an asynchronous Python client for interacting with the PowerBot API. It allows users to fetch market data, manage orders, and access other platform functionalities. The current version is 2.30.6 and it maintains a relatively frequent release cadence, often aligning with API updates.","status":"active","version":"2.30.6","language":"en","source_language":"en","source_url":"https://github.com/PowerBotApp/powerbot-client-python","tags":["async","api-client","trading","bot","cryptocurrency"],"install":[{"cmd":"pip install powerbot-client","lang":"bash","label":"Install PowerBot Client"}],"dependencies":[{"reason":"HTTP client for making API requests.","package":"aiohttp"},{"reason":"Used for rate-limiting API calls to prevent exceeding limits.","package":"asyncio-throttle"},{"reason":"For data validation and parsing API responses into models.","package":"pydantic"},{"reason":"Optional: For loading environment variables (like API keys) from a .env file.","package":"python-dotenv"},{"reason":"For WebSocket connections to stream real-time data.","package":"websockets"}],"imports":[{"symbol":"PowerBotClient","correct":"from powerbot_client.client import PowerBotClient"},{"symbol":"Market","correct":"from powerbot_client.models import Market"}],"quickstart":{"code":"import asyncio\nimport os\nfrom powerbot_client.client import PowerBotClient\nfrom powerbot_client.models import Market\n\nasync def main():\n    api_key = os.environ.get('POWERBOT_API_KEY', '')\n    if not api_key:\n        print(\"Error: POWERBOT_API_KEY environment variable not set.\")\n        return\n\n    client = PowerBotClient(api_key=api_key)\n    try:\n        print(\"Fetching markets...\")\n        markets = await client.get_markets()\n        for m in markets[:3]: # Print first 3 markets\n            print(Market.model_dump(m, exclude_unset=True))\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        await client.close()\n        print(\"Client closed.\")\n\nif __name__ == \"__main__\":\n    # Ensure the event loop is run properly\n    asyncio.run(main())\n","lang":"python","description":"This quickstart initializes the PowerBotClient with an API key from an environment variable, fetches a list of markets, prints the first three, and ensures the client connection is properly closed. It demonstrates the basic asynchronous usage pattern required by the library."},"warnings":[{"fix":"Refer to the v2.0.0+ documentation and examples. A full migration of existing v1.x code is required.","message":"Version 2.0.0 introduced a complete rewrite of the client, making it entirely incompatible with v1.x. All imports, class names, method signatures, and data models changed significantly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always prepend `await` when calling methods that are `async def`.","message":"Forgetting to `await` asynchronous methods (e.g., `client.get_markets()`, `client.close()`) will result in `TypeError: object asyncio.Future can't be used in 'await' expression` or `RuntimeWarning`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure `await client.close()` is called, ideally within a `finally` block or an `async with` statement (if supported, current version uses explicit close).","message":"The client uses an aiohttp session and websockets connection. Failing to call `await client.close()` can leave open connections and potentially lead to resource leaks or unexpected behavior, especially in long-running applications.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If an event loop is already running, use `asyncio.create_task()` or `loop.run_until_complete()` instead of `asyncio.run()` for new coroutines. For simple scripts, ensure `asyncio.run()` is only called once at the top level.","message":"Attempting to call `asyncio.run()` in an environment where an event loop is already running (e.g., in some IDEs, Jupyter notebooks, or nested async contexts) will raise a `RuntimeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install powerbot-client` to install the library.","cause":"The `powerbot-client` package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'powerbot_client'"},{"fix":"Prepend `await` to the async method call, e.g., `markets = await client.get_markets()`.","cause":"You are calling an asynchronous method (which returns a Future) without `await`.","error":"TypeError: object asyncio.Future can't be used in 'await' expression"},{"fix":"Pass your API key during initialization, e.g., `client = PowerBotClient(api_key=\"YOUR_API_KEY\")` or load it from environment variables.","cause":"The `api_key` argument was not provided when initializing `PowerBotClient`.","error":"TypeError: PowerBotClient.__init__ missing 1 required positional argument: 'api_key'"},{"fix":"If an event loop is running, avoid `asyncio.run()`. Instead, get the current loop and schedule your coroutine: `loop = asyncio.get_event_loop(); loop.run_until_complete(main())` or `task = loop.create_task(main()); await task`.","cause":"`asyncio.run()` was called when an event loop was already active. This is common in interactive environments or when nesting `asyncio.run()` calls.","error":"RuntimeError: An asyncio event loop is already running"}]}