from polyhush import PolyhushClient, PolyhushAPIErrorclient = PolyhushClient(api_key="your-api-key")try: result = client.buy( token_id="your-token-id", shares=10, price=0.55 ) print(f"Order placed: {result['order_id']}")except PolyhushAPIError as e: print(f"Failed to place order: {e.message}")
try: client.buy(token_id=token_id, shares=1000, price=0.50)except PolyhushAPIError as e: if "insufficient" in e.message.lower(): balance = client.get_balance() print(f"Need more funds. Available: ${balance['available_balance']:.2f}")
Invalid Token ID
Copy
try: client.buy(token_id="invalid-token", shares=10, price=0.50)except PolyhushAPIError as e: if e.status_code == 404: print("Token not found - check the token ID")
Order Already Cancelled
Copy
try: client.cancel_order(order_id=order_id)except PolyhushAPIError as e: if "already" in e.message.lower(): print("Order was already cancelled or filled")
Rate Limiting
Copy
import timetry: for token in tokens: client.get_ticker(token)except PolyhushAPIError as e: if e.status_code == 429: print("Rate limited - waiting 60 seconds") time.sleep(60)