PowerBot Client
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.
Common errors
-
ModuleNotFoundError: No module named 'powerbot_client'
cause The `powerbot-client` package is not installed in the current Python environment.fixRun `pip install powerbot-client` to install the library. -
TypeError: object asyncio.Future can't be used in 'await' expression
cause You are calling an asynchronous method (which returns a Future) without `await`.fixPrepend `await` to the async method call, e.g., `markets = await client.get_markets()`. -
TypeError: PowerBotClient.__init__ missing 1 required positional argument: 'api_key'
cause The `api_key` argument was not provided when initializing `PowerBotClient`.fixPass your API key during initialization, e.g., `client = PowerBotClient(api_key="YOUR_API_KEY")` or load it from environment variables. -
RuntimeError: An asyncio event loop is already running
cause `asyncio.run()` was called when an event loop was already active. This is common in interactive environments or when nesting `asyncio.run()` calls.fixIf 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`.
Warnings
- breaking 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.
- gotcha 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`.
- gotcha 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.
- gotcha 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`.
Install
-
pip install powerbot-client
Imports
- PowerBotClient
from powerbot_client.client import PowerBotClient
- Market
from powerbot_client.models import Market
Quickstart
import asyncio
import os
from powerbot_client.client import PowerBotClient
from powerbot_client.models import Market
async def main():
api_key = os.environ.get('POWERBOT_API_KEY', '')
if not api_key:
print("Error: POWERBOT_API_KEY environment variable not set.")
return
client = PowerBotClient(api_key=api_key)
try:
print("Fetching markets...")
markets = await client.get_markets()
for m in markets[:3]: # Print first 3 markets
print(Market.model_dump(m, exclude_unset=True))
except Exception as e:
print(f"An error occurred: {e}")
finally:
await client.close()
print("Client closed.")
if __name__ == "__main__":
# Ensure the event loop is run properly
asyncio.run(main())