Skip to main content

Simple trading for AI agents on Orderly Network

Project description

Arthur SDK

The easiest way for AI agents to trade crypto perpetuals.

3 lines of Python. No complex signatures. No confusing structs. Just trade.

from orderly_agent import Arthur
client = Arthur.from_credentials_file("credentials.json")
client.buy("ETH", usd=100)  # Done.

Why Arthur?

  • 🚀 Dead simple - Trade in 3 lines of code
  • 🤖 Built for agents - Clean API, no boilerplate
  • Fast execution - Powered by Orderly Network
  • 📊 50+ markets - BTC, ETH, SOL, ARB, and more
  • 🔒 Non-custodial - Your keys, your coins

Installation

pip install agent-trading-sdk

Quick Start

from orderly_agent import Arthur

# Load credentials
client = Arthur.from_credentials_file("credentials.json")

# Trade
client.buy("ETH", usd=100)      # Long $100 of ETH
client.sell("BTC", size=0.01)   # Short 0.01 BTC
client.close("ETH")             # Close position
client.close_all()              # Close everything

# Check status
print(client.balance())         # Available USDC
print(client.pnl())             # Total unrealized PnL
print(client.positions())       # All open positions

Strategy Examples

RSI Strategy

# Buy oversold, sell overbought
if rsi < 30:
    client.buy("ETH", usd=100)
elif rsi > 70:
    client.sell("ETH", usd=100)

👉 Full RSI example

Momentum Strategy

# Trend following with trailing stops
if price > recent_high:
    client.buy("BTC", usd=200)

👉 Full momentum example

Grid Trading

# Profit from sideways markets
for level in grid_levels:
    client.buy(symbol, price=level, usd=50)

👉 Full grid example

AI Agent

# Let your LLM make decisions
context = get_market_context(client, ["BTC", "ETH"])
decision = llm.chat(TRADING_PROMPT, context)
execute_trade(client, decision)

👉 Full AI agent example

Portfolio Rebalancer

# Maintain target allocations
targets = {"BTC": 50, "ETH": 30, "SOL": 20}
rebalance_portfolio(client, targets)

👉 Full rebalancer example

API Reference

Trading

# Market orders
client.buy("ETH", usd=100)      # Buy by USD value
client.buy("BTC", size=0.01)    # Buy by size

# Limit orders
client.buy("ETH", size=0.1, price=2000)

# Close positions
client.close("ETH")             # Close all of symbol
client.close("ETH", size=0.05)  # Partial close
client.close_all()              # Close everything

Position Management

# Get all positions
for pos in client.positions():
    print(f"{pos.symbol}: {pos.side} {pos.size}")
    print(f"  Entry: ${pos.entry_price}")
    print(f"  PnL: ${pos.unrealized_pnl} ({pos.pnl_percent}%)")

# Get specific position
eth_pos = client.position("ETH")

# Total PnL
total_pnl = client.pnl()

Market Data

# Get price
btc_price = client.price("BTC")

# Get all prices
prices = client.prices()

Account Info

balance = client.balance()    # Available USDC
equity = client.equity()      # Total value
summary = client.summary()    # Full details

Withdrawals

# Initialize with wallet for withdrawals
client = Arthur(
    api_key="...",
    secret_key="...",
    account_id="...",
    wallet_private_key="...",  # Required for withdrawals!
    chain_id=42161,  # Arbitrum One
)

# Withdraw 100 USDC to your wallet
result = client.withdraw(100)
print(f"Withdrawal ID: {result['withdraw_id']}")

# Withdraw to a different chain
client.withdraw(50, to_chain_id=10)  # Optimism

# Check withdrawal history
for w in client.withdrawal_history():
    print(f"{w['id']}: {w['amount']} USDC - {w['status']}")

👉 Full withdrawal example

Risk Management

client.set_leverage("ETH", 10)
client.set_stop_loss("ETH", price=1900)
client.set_stop_loss("ETH", pct=5)  # 5% stop

Credentials

Create a credentials.json:

{
    "api_key": "ed25519:xxx",
    "secret_key": "ed25519:xxx",
    "account_id": "0x..."
}

Get credentials from Arthur DEX or any Orderly-powered DEX.

Supported Markets

Short symbols work automatically:

Short Full Symbol
BTC PERP_BTC_USDC
ETH PERP_ETH_USDC
SOL PERP_SOL_USDC
ARB, OP, AVAX, LINK... PERP_*_USDC

50+ perpetual markets available.

Testnet

client = Arthur(..., testnet=True)

Error Handling

from orderly_agent import Arthur, OrderError, InsufficientFundsError

try:
    client.buy("ETH", usd=100)
except InsufficientFundsError:
    print("Not enough balance")
except OrderError as e:
    print(f"Order failed: {e}")

Links

License

MIT


Built by Arthur 🤖 for AI agents, powered by Orderly Network.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

arthur_sdk-0.4.1-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file arthur_sdk-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: arthur_sdk-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for arthur_sdk-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca81d41c959a918efe2e2343852bab41528f5d0cfed216035e2c7a05fed15f5b
MD5 efd6fe6dd79d1ea43a352f2764a030c6
BLAKE2b-256 6b6d637324d7bc2103318b9218e8df95ee79f201b876f12f67ff9e26120b4aac

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