LangChain tools for Arthur DEX - Trade perpetuals with any AI agent
Project description
Arthur LangChain Tools 🤖⚡
Trade perpetual futures with any LangChain agent. Built on Arthur DEX - the exchange for AI agents.
Installation
pip install arthur-langchain
Quick Start
from arthur_langchain import ArthurToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain import hub
# Initialize toolkit with your credentials
toolkit = ArthurToolkit(
account_id="your_account_id",
api_key="ed25519:your_api_key",
secret_key="ed25519:your_secret_key"
)
# Create an agent with trading capabilities
llm = ChatOpenAI(model="gpt-4")
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, toolkit.get_tools(), prompt)
executor = AgentExecutor(agent=agent, tools=toolkit.get_tools(), verbose=True)
# Let your agent trade!
executor.invoke({"input": "Buy 0.01 BTC if the price is under $100k"})
Tools Included
🔄 ArthurTradeTool
Execute market and limit orders.
# Market buy
agent.invoke({"input": "Buy 0.5 ETH at market price"})
# Limit sell
agent.invoke({"input": "Place a limit sell for 1 SOL at $150"})
📊 ArthurPortfolioTool
Check positions, balance, and P&L.
agent.invoke({"input": "What are my current positions and P&L?"})
agent.invoke({"input": "How much margin do I have available?"})
📈 ArthurMarketTool
Get prices, orderbook, and funding rates.
agent.invoke({"input": "What's the current BTC price?"})
agent.invoke({"input": "Show me the ETH orderbook"})
agent.invoke({"input": "What's the funding rate on SOL?"})
📋 ArthurOrdersTool
Manage open orders.
agent.invoke({"input": "List my open orders"})
agent.invoke({"input": "Cancel all my orders"})
Example: Trading Agent
Here's a complete trading agent that follows a simple strategy:
from arthur_langchain import ArthurToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain_core.prompts import PromptTemplate
# Setup
toolkit = ArthurToolkit(
account_id="your_account_id",
api_key="ed25519:your_api_key",
secret_key="ed25519:your_secret_key"
)
llm = ChatOpenAI(model="gpt-4", temperature=0)
# Custom trading prompt
prompt = PromptTemplate.from_template("""You are a crypto trading agent with access to Arthur DEX.
Your trading rules:
1. Never risk more than 10% of portfolio on a single trade
2. Always check current price before trading
3. Set reasonable position sizes
Available tools:
{tools}
Tool names: {tool_names}
Question: {input}
Think step by step:
{agent_scratchpad}
""")
agent = create_react_agent(llm, toolkit.get_tools(), prompt)
executor = AgentExecutor(agent=agent, tools=toolkit.get_tools(), verbose=True)
# Run the agent
result = executor.invoke({
"input": "Check if BTC is under $95k. If so, buy $100 worth."
})
print(result)
Example: CrewAI Integration
from crewai import Agent, Task, Crew
from arthur_langchain import ArthurToolkit
toolkit = ArthurToolkit(
account_id="your_account_id",
api_key="ed25519:your_api_key",
secret_key="ed25519:your_secret_key"
)
trader = Agent(
role="Crypto Trader",
goal="Execute profitable trades on Arthur DEX",
backstory="Expert perpetual futures trader",
tools=toolkit.get_tools(),
verbose=True
)
task = Task(
description="Analyze BTC market and decide whether to open a position",
agent=trader
)
crew = Crew(agents=[trader], tasks=[task])
result = crew.kickoff()
Supported Markets
80+ perpetual futures including:
- Majors: BTC, ETH, SOL, BNB
- L2s: ARB, OP, MATIC
- DeFi: UNI, AAVE, LINK, MKR
- Memes: DOGE, SHIB, PEPE, WIF
- AI: FET, RNDR, TAO
Getting Credentials
- Go to Arthur DEX
- Connect your wallet
- Generate API keys in Settings
Or use the Arthur SDK directly:
from arthur_sdk import Arthur
client = Arthur.create_account() # Creates new account
print(client.account_id, client.api_key, client.secret_key)
Links
- 🌐 Arthur DEX
- 📦 Arthur SDK
- 🐦 @Arthur_Orderly
- 💬 Discord
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arthur_langchain-0.1.0.tar.gz.
File metadata
- Download URL: arthur_langchain-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83a6742f7515b395019d1cfff620021a2ce1cefeb7fc1048e6d74679a14a8883
|
|
| MD5 |
651f06a34d97541ea450c0dfeab02ae3
|
|
| BLAKE2b-256 |
70e3a4c8849133d0855561dfa81a5f3a4ce595f29dfb9efbbdf7da023d744a78
|
File details
Details for the file arthur_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: arthur_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c03471a302b6b840aa8093bd74ec427284f3e0021c3c90323a8a2254af9c9a
|
|
| MD5 |
648880f483451182c55453e4f2deb87d
|
|
| BLAKE2b-256 |
74a05d92a1d39ed5a4151e787ec0d4a58e1b9f23a8bf61f717a0e82135cd24f3
|