Skip to main content

Python SDK for agentCrab — turn any AI agent into a Polymarket assistant

Project description

agentcrab

Python SDK for agentCrab — turn any AI agent into a Polymarket assistant with 3 lines of code.

Install

pip install agentcrab

Quick Start

from agentcrab import AgentCrab

client = AgentCrab("https://api.agentcrab.ai/polymarket", "0xYOUR_PRIVATE_KEY")

# Search markets
markets = client.search("bitcoin")
for m in markets:
    print(m.title, m.outcomes)

# Check balance
balance = client.get_balance()
print(f"{balance.calls_remaining} API calls remaining")

Trading

# One-time setup (deploys Safe + approvals + L2 credentials)
setup = client.setup_trading()
print(f"Safe: {setup.safe_address}")

# Buy shares
result = client.buy(token_id="TOKEN_ID", size=5.0, price=0.65)
print(f"Order {result.status}: {result.order_id}")

# Sell shares
result = client.sell(token_id="TOKEN_ID", size=5.0, price=0.70)

# View positions
for pos in client.get_positions():
    print(f"{pos.outcome}: {pos.size} shares, PnL: {pos.pnl}")

Full API

Balance & Payment

Method Description Cost
get_balance() Prepaid balance Free
deposit(amount_usdt) Deposit to agentCrab Free
deposit_to_polymarket(amount_usdt) Deposit to Polymarket 0.01 USDT

Market Data

Method Description Cost
search(query, tag, category) Search events 0.01 USDT
browse(category, mood) Browse events 0.01 USDT
get_event(event_id) Get single event 0.01 USDT
get_market(market_id) Get single market 0.01 USDT
get_orderbook(token_id) Get orderbook 0.01 USDT
get_price(token_id) Get price 0.01 USDT

Positions & History

Method Description Cost
get_positions() Your positions 0.01 USDT
get_trades(limit, offset) Your trades 0.01 USDT
get_leaderboard(limit, offset) Leaderboard 0.01 USDT

Trading (requires setup_trading() first)

Method Description Cost
setup_trading() Deploy Safe + approvals + creds 0.01-0.03 USDT
set_credentials(key, secret, passphrase) Manual cred set Free
buy(token_id, size, price) Buy shares 0.01 USDT
sell(token_id, size, price) Sell shares 0.01 USDT
cancel_order(order_id) Cancel order 0.01 USDT
cancel_all_orders() Cancel all 0.01 USDT
get_open_orders(market) Open orders 0.01 USDT

Wallet

Method Description
AgentCrab.create_wallet(api_url) Create new wallet (static)

Typed Responses

All methods return typed dataclasses with a .raw escape hatch:

balance = client.get_balance()
print(balance.calls_remaining)   # typed field
print(balance.raw)               # full server response dict

Error Handling

from agentcrab import AgentCrabError, InsufficientBalance, SetupRequired

try:
    result = client.buy(token_id, size=5.0, price=0.65)
except SetupRequired:
    client.setup_trading()
    result = client.buy(token_id, size=5.0, price=0.65)
except InsufficientBalance as e:
    print(f"Top up: {e.message}")
except AgentCrabError as e:
    print(f"Error [{e.error_code}]: {e.message}")

Dependencies

Minimal — no web3 required:

  • eth-account — EIP-191, EIP-712, tx signing
  • httpx — Sync HTTP
  • hexbytes — SafeTx hash signing

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentcrab-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentcrab-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file agentcrab-0.1.0.tar.gz.

File metadata

  • Download URL: agentcrab-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agentcrab-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ace5dffb831c130f26d8023974b8012b89544521071033163bb9968642a69968
MD5 570c3d6e0c05a15f79a0c9240bb89344
BLAKE2b-256 ddc0354386f9448e78dcf27dfa49f1505df83837370ccc4990ca8652ab12f5b2

See more details on using hashes here.

File details

Details for the file agentcrab-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentcrab-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agentcrab-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58319bbca4d381b3b68c32ce52ad7783761b39c013053b53c082d4243895e69a
MD5 a292239efd4ffa674af98f7c49d88634
BLAKE2b-256 1f812f9118a005a9c897e31db1824c3592e74f9795bf73f82d7cc10bdce5d2ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page