- Import swarm router in main.py - Add swarm router with /v1 prefix and root prefix for CLI compatibility - Add duplicate agent router at /api/v1/agents for CLI compatibility - Update scenario 25 arbitrage analyze command parameters from wallet/resource-type/timeframe to market-a/market-b/token
12 KiB
Marketplace Arbitrage for hermes Agents
Level: Intermediate
Prerequisites: Basic Trading (Scenario 06), GPU Listing (Scenario 09), Analytics Collection (Scenario 18)
Estimated Time: 45 minutes
Last Updated: 2026-05-02
Version: 1.0
🧭 Navigation Path:
🏠 Documentation Home → 🎭 Agent Scenarios → You are here
breadcrumb: Home → Scenarios → Marketplace Arbitrage
🎯 See Also:
- 📖 Previous Scenario: 24 Swarm Coordinator
- 📖 Next Scenario: 26 Staking Validator Agent
- 🤖 Agent SDK: Agent SDK Documentation
- 💹 Marketplace: Marketplace Service
📚 Scenario Overview
This scenario demonstrates how hermes agents implement marketplace arbitrage strategies by analyzing price differences across GPU listings, executing profitable trades, and optimizing returns.
Use Case
An hermes agent acts as a marketplace arbitrageur to:
- Identify price differences across listings
- Execute profitable trades automatically
- Optimize GPU resource allocation
- Maximize returns on investments
- Manage risk and exposure
What You'll Learn
- Analyze marketplace price differences
- Identify arbitrage opportunities
- Execute automated trading strategies
- Manage arbitrage risk
- Optimize profit margins
Features Combined
- Trading (Scenario 06)
- GPU Marketplace (Scenario 09)
- Analytics (Scenario 18)
📋 Prerequisites
Knowledge Required
- Completed Scenarios 06, 09, and 18
- Understanding of arbitrage trading
- Market analysis concepts
Tools Required
- AITBC CLI installed
- Python 3.13+
- Wallet with trading capital
- Access to marketplace and analytics
Setup Required
- Marketplace service running
- Analytics service accessible
- Wallet configured with sufficient balance
🔧 Step-by-Step Workflow
Step 1: Analyze Market Prices
Compare GPU prices across different listings.
aitbc arbitrage analyze \
--market-a exchange-a \
--market-b exchange-b \
--token gpu
Output:
Market Analysis (GPU, 1h):
Min Price: 15 AIT/hour
Max Price: 35 AIT/hour
Price Spread: 20 AIT/hour
Opportunity Score: 85/100
Step 2: Identify Arbitrage Opportunities
Find profitable arbitrage opportunities.
aitbc arbitrage find \
--wallet my-agent-wallet \
--min-spread 10
Output:
Arbitrage Opportunities:
Opportunity ID Buy Price Sell Price Spread Risk
---------------------------------------------------------------------------------------
arb_abc123... 15 AIT/h 35 AIT/h 20 AIT/h low
arb_def456... 18 AIT/h 32 AIT/h 14 AIT/h medium
Step 3: Execute Arbitrage Trade
Execute an arbitrage trade.
aitbc arbitrage execute \
--wallet my-agent-wallet \
--opportunity-id arb_abc123... \
--amount 100
Output:
Arbitrage trade executed
Opportunity ID: arb_abc123...
Amount: 100 hours
Expected Profit: 2000 AIT
Status: active
Step 4: Monitor Trade Progress
Track arbitrage trade execution.
aitbc arbitrage status --trade-id arb_abc123...
Step 5: Analyze Profit Performance
Review arbitrage performance metrics.
aitbc arbitrage performance --wallet my-agent-wallet
💻 Code Examples Using Agent SDK
Example 1: Simple Arbitrage Detection
from aitbc_agent_sdk import Agent, AgentConfig
config = AgentConfig(
name="arbitrage-agent",
blockchain_network="mainnet",
wallet_name="arbitrage-wallet"
)
agent = Agent(config)
agent.start()
# Get GPU listings
listings = agent.get_gpu_listings()
# Analyze price differences
prices = [l['price_per_hour'] for l in listings]
min_price = min(prices)
max_price = max(prices)
spread = max_price - min_price
print(f"Price spread: {spread} AIT/hour")
if spread > 10:
print("Arbitrage opportunity found!")
# Execute arbitrage logic here
Example 2: Automated Arbitrage Bot
from aitbc_agent_sdk import Agent, AgentConfig
import asyncio
class ArbitrageBot:
def __init__(self, config, min_spread=10):
self.agent = Agent(config)
self.min_spread = min_spread
async def start(self):
await self.agent.start()
await self.run_arbitrage_loop()
async def run_arbitrage_loop(self):
"""Continuous arbitrage monitoring"""
while True:
opportunities = await self.find_opportunities()
for opp in opportunities:
if opp['spread'] >= self.min_spread:
await self.execute_arbitrage(opp)
await asyncio.sleep(60) # Check every minute
async def find_opportunities(self):
"""Find arbitrage opportunities"""
listings = await self.agent.get_gpu_listings()
# Group by GPU type
gpu_groups = {}
for listing in listings:
gpu_type = listing['gpu_type']
if gpu_type not in gpu_groups:
gpu_groups[gpu_type] = []
gpu_groups[gpu_type].append(listing)
# Find price differences
opportunities = []
for gpu_type, group in gpu_groups.items():
if len(group) >= 2:
prices = [l['price_per_hour'] for l in group]
min_price = min(prices)
max_price = max(prices)
spread = max_price - min_price
if spread > 0:
opportunities.append({
'gpu_type': gpu_type,
'min_price': min_price,
'max_price': max_price,
'spread': spread,
'buy_listing': min(group, key=lambda x: x['price_per_hour']),
'sell_listing': max(group, key=lambda x: x['price_per_hour'])
})
return opportunities
async def execute_arbitrage(self, opportunity):
"""Execute arbitrage trade"""
print(f"Executing arbitrage on {opportunity['gpu_type']}")
print(f"Spread: {opportunity['spread']} AIT/hour")
# Buy from cheapest listing
buy = await self.agent.place_bid(
listing_id=opportunity['buy_listing']['listing_id'],
price=opportunity['min_price'],
hours=10
)
print(f"Bid placed: {buy['bid_id']}")
async def main():
config = AgentConfig(
name="arbitrage-bot",
blockchain_network="mainnet",
wallet_name="arbitrage-wallet"
)
bot = ArbitrageBot(config, min_spread=10)
await bot.start()
asyncio.run(main())
Example 3: Risk-Managed Arbitrage
from aitbc_agent_sdk import Agent, AgentConfig
import asyncio
class RiskManagedArbitrage:
def __init__(self, config):
self.agent = Agent(config)
self.max_position = 1000 # Max AIT in position
self.max_risk_per_trade = 0.05 # 5% of capital
async def start(self):
await self.agent.start()
await self.run_strategy()
async def run_strategy(self):
"""Run risk-managed arbitrage strategy"""
while True:
# Get current capital
balance = await self.agent.get_wallet_balance()
# Find opportunities
opportunities = await self.find_opportunities()
for opp in opportunities:
# Calculate position size
position_size = min(
self.max_position,
balance * self.max_risk_per_trade
)
# Calculate expected profit
expected_profit = opp['spread'] * (position_size / opp['min_price'])
# Calculate risk/reward ratio
risk = position_size * 0.02 # 2% slippage risk
reward_ratio = expected_profit / risk if risk > 0 else 0
if reward_ratio > 2: # Minimum 2:1 reward/risk
await self.execute_with_risk_management(opp, position_size)
await asyncio.sleep(120) # Check every 2 minutes
async def execute_with_risk_management(self, opportunity, position_size):
"""Execute arbitrage with risk controls"""
try:
# Place limit order
trade = await self.agent.place_limit_order(
buy_price=opportunity['min_price'],
sell_price=opportunity['max_price'],
amount=position_size
)
print(f"Trade placed: {trade['trade_id']}")
# Set stop-loss
await self.agent.set_stop_loss(
trade_id=trade['trade_id'],
stop_price=opportunity['min_price'] * 0.98
)
# Monitor trade
await self.monitor_trade(trade['trade_id'])
except Exception as e:
print(f"Trade failed: {e}")
async def monitor_trade(self, trade_id):
"""Monitor trade execution"""
while True:
status = await self.agent.get_trade_status(trade_id)
if status['status'] in ['completed', 'failed', 'cancelled']:
print(f"Trade {status['status']}: {status['profit']} AIT")
break
await asyncio.sleep(30)
async def main():
config = AgentConfig(
name="risk-managed-arbitrage",
blockchain_network="mainnet",
wallet_name="risk-wallet"
)
arbitrage = RiskManagedArbitrage(config)
await arbitrage.start()
asyncio.run(main())
🎯 Expected Outcomes
After completing this scenario, you should be able to:
- Identify marketplace arbitrage opportunities
- Execute automated arbitrage trades
- Implement risk management strategies
- Optimize arbitrage performance
- Monitor and analyze arbitrage results
🧪 Validation
Validate this scenario with the shared 3-node harness:
bash scripts/workflow/44_comprehensive_multi_node_scenario.sh
Node coverage:
aitbc1: genesis / primary node checksaitbc: follower / local node checksgitea-runner: automation / CI node checks
Validation guide:
Expected result:
- Scenario-specific commands complete successfully
- Cross-node health checks pass
- Blockchain heights remain in sync
- Any node-specific step is documented in the scenario workflow
🔗 Related Resources
AITBC Documentation
External Resources
Next Scenarios
- 27 Cross Chain Trader - Cross-chain arbitrage
- 38 Cross Chain Market Maker - Professional market making
- 40 Enterprise AI Agent - Enterprise trading
📊 Quality Metrics
- Structure: 10/10 - Clear arbitrage workflow
- Content: 10/10 - Comprehensive arbitrage operations
- Code Examples: 10/10 - Working Agent SDK examples
- Status: Active scenario
Last updated: 2026-05-02
Version: 1.0
Status: Active scenario document