Quick Start
Place your first trade on AFX DEX in 5 minutes.
Last updated
from afx import AfxClient
client = AfxClient.from_env(testnet=True)result = client.exchange.faucet_claim()
print(result) # {"code": 0, "message": "success", ...}result = client.exchange.approve_agent(
agent_name="my-bot",
validity_seconds=604800,
)
print(result)products = client.info.get_products()
for p in products["data"]["perpProducts"][:3]:
print(f"{p['symbol']} (code: {p['code']}, leverage: {p['maxLeverage']}x)")btc = next(p for p in products["data"]["perpProducts"] if p["symbol"] == "BTCUSDC")
result = client.exchange.place_order(
symbol_code=int(btc["code"]),
px="50000.0", # limit price
qty="0.001", # quantity in BTC
side="BUY",
ord_type="LIMIT",
tif="GTC", # Good Till Cancelled
)
print(f"txHash: {result['data']['txHash']}")import asyncio
async def main():
message = await client.websocket.subscribe_order_book(
symbol="BTCUSDC",
depth=5,
timeout=10,
)
book = message["data"]["book"]
print(f"Best bid: {book['bids'][0]}, Best ask: {book['asks'][0]}")
asyncio.run(main())