fix: replace hardcoded 8001 URLs with config values in CLI commands
Some checks failed
CLI Tests / test-cli (push) Failing after 14s
Cross-Node Transaction Testing / transaction-test (push) Successful in 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m10s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
Security Scanning / security-scan (push) Successful in 31s

- Add exchange_service_url to config.py (default: http://localhost:8001/api/v1)
- Fix exchange.py to use config.exchange_service_url instead of hardcoded 8001
- Fix cross_chain.py to use config.exchange_service_url instead of hardcoded 8001
- Fix monitor.py to use config.exchange_service_url instead of hardcoded 8001
- Fix agent_sdk.py to use config.coordinator_url instead of hardcoded 8001
- Fixes bug where CLI commands used wrong default ports (8001 vs correct service ports)
- Marketplace service is on 8102, Exchange API is on 8001, Coordinator API is on 8011
This commit is contained in:
aitbc
2026-05-08 22:31:19 +02:00
parent 3735cd35a7
commit b49472f3b8
5 changed files with 103 additions and 99 deletions

View File

@@ -65,7 +65,7 @@ def create_agent(name: str, agent_type: str, capabilities: dict, coordinator_url
"address": agent.identity.address,
"agent_type": agent_type,
"capabilities": capabilities,
"coordinator_url": coordinator_url or "http://localhost:8001"
"coordinator_url": coordinator_url or config.coordinator_url
}
with open(config_file, 'w') as f:
@@ -84,8 +84,11 @@ def create_agent(name: str, agent_type: str, capabilities: dict, coordinator_url
return {"error": str(e)}
async def register_agent(agent_id: str, coordinator_url: str = "http://localhost:8001") -> dict:
async def register_agent(agent_id: str, coordinator_url: str = None) -> dict:
"""Register an agent with the coordinator"""
if coordinator_url is None:
config = get_config()
coordinator_url = config.coordinator_url
if Agent is None:
return {"error": "Agent SDK not available"}

View File

@@ -35,7 +35,7 @@ def rates(ctx, from_chain: Optional[str], to_chain: Optional[str],
with AITBCHTTPClient() as client:
# Get rates from cross-chain exchange
response = client.get(
f"http://localhost:8001/api/v1/cross-chain/rates",
f"{config.exchange_service_url}/cross-chain/rates",
timeout=10
)
@@ -103,7 +103,7 @@ def swap(ctx, from_chain: str, to_chain: str, from_token: str, to_token: str,
try:
with AITBCHTTPClient() as client:
response = client.get(
f"http://localhost:8001/api/v1/cross-chain/rates",
f"{config.exchange_service_url}/cross-chain/rates",
timeout=10
)
if response.status_code == 200:
@@ -128,7 +128,7 @@ def swap(ctx, from_chain: str, to_chain: str, from_token: str, to_token: str,
}
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1/cross-chain", timeout=30)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=30)
swap_result = http_client.post("/swap", json=swap_data)
success("Cross-chain swap created successfully!")
output({
@@ -158,7 +158,7 @@ def swap(ctx, from_chain: str, to_chain: str, from_token: str, to_token: str,
def status(ctx, swap_id: str):
"""Check cross-chain swap status"""
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
swap_data = http_client.get(f"/cross-chain/swap/{swap_id}")
success(f"Swap Status: {swap_data.get('status', 'unknown')}")
@@ -231,7 +231,7 @@ def swaps(ctx, user_address: Optional[str], status: Optional[str], limit: int):
params['status'] = status
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
swaps_data = http_client.get("/cross-chain/swaps", params=params)
swaps = swaps_data.get('swaps', [])
@@ -296,7 +296,7 @@ def bridge(ctx, source_chain: str, target_chain: str, token: str,
}
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=30)
http_client = AITBCHTTPClient(base_url="{config.exchange_service_url}", timeout=30)
bridge_result = http_client.post("/cross-chain/bridge", json=bridge_data)
success("Cross-chain bridge created successfully!")
output({
@@ -325,7 +325,7 @@ def bridge(ctx, source_chain: str, target_chain: str, token: str,
def bridge_status(ctx, bridge_id: str):
"""Check cross-chain bridge status"""
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
bridge_data = http_client.get(f"/cross-chain/bridge/{bridge_id}")
success(f"Bridge Status: {bridge_data.get('status', 'unknown')}")
@@ -371,40 +371,40 @@ def bridge_status(ctx, bridge_id: str):
def pools(ctx):
"""Show cross-chain liquidity pools"""
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
response = client.get(
f"http://localhost:8001/api/v1/cross-chain/pools",
timeout=10
)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
response = http_client.get(
f"/cross-chain/pools",
timeout=10
)
if response.status_code == 200:
pools_data = response.json()
pools = pools_data.get('pools', [])
if response.status_code == 200:
pools_data = response.json()
pools = pools_data.get('pools', [])
if pools:
success(f"Found {len(pools)} cross-chain liquidity pools:")
if pools:
success(f"Found {len(pools)} cross-chain liquidity pools:")
# Create table
pool_table = []
for pool in pools:
pool_table.append([
pool.get('pool_id', ''),
pool.get('token_a', ''),
pool.get('token_b', ''),
pool.get('chain_a', ''),
pool.get('chain_b', ''),
f"{pool.get('reserve_a', 0):.2f}",
f"{pool.get('reserve_b', 0):.2f}",
f"{pool.get('total_liquidity', 0):.2f}",
f"{pool.get('apr', 0):.2%}"
])
table(["Pool ID", "Token A", "Token B", "Chain A", "Chain B",
"Reserve A", "Reserve B", "Liquidity", "APR"], pool_table)
else:
success("No cross-chain liquidity pools found")
# Create table
pool_table = []
for pool in pools:
pool_table.append([
pool.get('pool_id', ''),
pool.get('token_a', ''),
pool.get('token_b', ''),
pool.get('chain_a', ''),
pool.get('chain_b', ''),
f"{pool.get('reserve_a', 0):.2f}",
f"{pool.get('reserve_b', 0):.2f}",
f"{pool.get('total_liquidity', 0):.2f}",
f"{pool.get('apr', 0):.2%}"
])
table(["Pool ID", "Token A", "Token B", "Chain A", "Chain B",
"Reserve A", "Reserve B", "Liquidity", "APR"], pool_table)
else:
error(f"Failed to get pools: {response.status_code}")
success("No cross-chain liquidity pools found")
else:
error(f"Failed to get pools: {response.status_code}")
except Exception as e:
error(f"Network error: {e}")
@@ -414,51 +414,51 @@ def pools(ctx):
def stats(ctx):
"""Show cross-chain trading statistics"""
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
response = client.get(
f"http://localhost:8001/api/v1/cross-chain/stats",
timeout=10
)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
response = http_client.get(
f"/cross-chain/stats",
timeout=10
)
if response.status_code == 200:
stats_data = response.json()
if response.status_code == 200:
stats_data = response.json()
success("Cross-Chain Trading Statistics:")
# Show swap stats
swap_stats = stats_data.get('swap_stats', [])
if swap_stats:
success("Swap Statistics:")
swap_table = []
for stat in swap_stats:
swap_table.append([
stat.get('status', ''),
stat.get('count', 0),
f"{stat.get('volume', 0):.2f}"
])
table(["Status", "Count", "Volume"], swap_table)
# Show bridge stats
bridge_stats = stats_data.get('bridge_stats', [])
if bridge_stats:
success("Bridge Statistics:")
bridge_table = []
for stat in bridge_stats:
bridge_table.append([
stat.get('status', ''),
stat.get('count', 0),
f"{stat.get('volume', 0):.2f}"
])
table(["Status", "Count", "Volume"], bridge_table)
# Show overall stats
success("Overall Statistics:")
output({
"Total Volume": f"{stats_data.get('total_volume', 0):.2f}",
"Supported Chains": ", ".join(stats_data.get('supported_chains', [])),
"Last Updated": stats_data.get('timestamp', '')
}, ctx.obj['output_format'])
else:
error(f"Failed to get stats: {response.status_code}")
success("Cross-Chain Trading Statistics:")
# Show swap stats
swap_stats = stats_data.get('swap_stats', [])
if swap_stats:
success("Swap Statistics:")
swap_table = []
for stat in swap_stats:
swap_table.append([
stat.get('status', ''),
stat.get('count', 0),
f"{stat.get('volume', 0):.2f}"
])
table(["Status", "Count", "Volume"], swap_table)
# Show bridge stats
bridge_stats = stats_data.get('bridge_stats', [])
if bridge_stats:
success("Bridge Statistics:")
bridge_table = []
for stat in bridge_stats:
bridge_table.append([
stat.get('status', ''),
stat.get('count', 0),
f"{stat.get('volume', 0):.2f}"
])
table(["Status", "Count", "Volume"], bridge_table)
# Show overall stats
success("Overall Statistics:")
output({
"Total Volume": f"{stats_data.get('total_volume', 0):.2f}",
"Supported Chains": ", ".join(stats_data.get('supported_chains', [])),
"Last Updated": stats_data.get('timestamp', '')
}, ctx.obj['output_format'])
else:
error(f"Failed to get stats: {response.status_code}")
except Exception as e:
error(f"Network error: {e}")

View File

@@ -373,7 +373,7 @@ def status(ctx, exchange_name: str):
config = ctx.obj['config']
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
rates_data = http_client.get(f"/exchange/rates")
success("Current exchange rates:")
output(rates_data, ctx.obj['output_format'])
@@ -409,7 +409,7 @@ def create_payment(ctx, aitbc_amount: Optional[float], btc_amount: Optional[floa
# Get exchange rates to calculate missing amount
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
rates = http_client.get("/exchange/rates")
btc_to_aitbc = rates.get('btc_to_aitbc', 100000)
@@ -449,7 +449,7 @@ def payment_status(ctx, payment_id: str):
config = ctx.obj['config']
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
status_data = http_client.get(f"/exchange/payment-status/{payment_id}")
status = status_data.get('status', 'unknown')
@@ -477,7 +477,7 @@ def market_stats(ctx):
config = ctx.obj['config']
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
stats = http_client.get("/exchange/market-stats")
success("Exchange market statistics:")
output(stats, ctx.obj['output_format'])
@@ -500,7 +500,7 @@ def balance(ctx):
config = ctx.obj['config']
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
balance_data = http_client.get("/exchange/wallet/balance")
success("Bitcoin wallet balance:")
output(balance_data, ctx.obj['output_format'])
@@ -517,7 +517,7 @@ def info(ctx):
config = ctx.obj['config']
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
wallet_info = http_client.get("/exchange/wallet/info")
success("Bitcoin wallet information:")
output(wallet_info, ctx.obj['output_format'])
@@ -547,7 +547,7 @@ def register(ctx, name: str, api_key: str, api_secret: Optional[str], sandbox: b
exchange_data["api_secret"] = api_secret
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
result = http_client.post("/exchange/register", json=exchange_data)
success(f"Exchange '{name}' registered successfully!")
success(f"Exchange ID: {result.get('exchange_id')}")
@@ -587,7 +587,7 @@ def create_pair(ctx, pair: str, base_asset: str, quote_asset: str,
pair_data["max_order_size"] = max_order_size
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
result = http_client.post("/exchange/create-pair", json=pair_data)
success(f"Trading pair '{pair}' created successfully!")
success(f"Pair ID: {result.get('pair_id')}")
@@ -617,7 +617,7 @@ def start_trading(ctx, pair: str, exchange: Optional[str], order_type: tuple):
trading_data["exchange"] = exchange
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
result = http_client.post("/exchange/start-trading", json=trading_data)
success(f"Trading started for pair '{pair}'!")
success(f"Order types: {', '.join(order_type)}")
@@ -646,7 +646,7 @@ def list_pairs(ctx, pair: Optional[str], exchange: Optional[str], status: Option
params["status"] = status
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
pairs = http_client.get("/exchange/pairs", params=params)
success("Trading pairs:")
output(pairs, ctx.obj['output_format'])

View File

@@ -110,7 +110,7 @@ def metrics(ctx, period: str, export_path: Optional[str]):
}
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
# Coordinator metrics
try:
resp = http_client.get(
@@ -235,7 +235,7 @@ def alerts(ctx, action: str, name: Optional[str], alert_type: Optional[str],
return
if alert.get("webhook"):
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
resp = client.post(alert["webhook"], json={
"alert": name,
"type": alert["type"],
@@ -270,7 +270,7 @@ def history(ctx, period: str):
}
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
try:
resp = http_client.get(
f"{config.coordinator_url}/jobs",
@@ -355,7 +355,7 @@ def webhooks(ctx, action: str, name: Optional[str], url: Optional[str], events:
error(f"Webhook '{name}' not found")
return
try:
http_client = AITBCHTTPClient(base_url="http://localhost:8001/api/v1", timeout=10)
http_client = AITBCHTTPClient(base_url=config.exchange_service_url, timeout=10)
resp = client.post(wh["url"], json={
"event": "test",
"source": "aitbc-cli",

View File

@@ -25,6 +25,7 @@ class CLIConfig(BaseAITBCConfig):
app_version: str = Field(default="2.1.0", description="CLI version")
# Service URLs
exchange_service_url: str = Field(default="http://localhost:8001/api/v1", description="Exchange Service URL")
gpu_service_url: str = Field(default="http://localhost:8101", description="GPU Service URL")
marketplace_service_url: str = Field(default="http://localhost:8102", description="Marketplace Service URL")
trading_service_url: str = Field(default="http://localhost:8104", description="Trading Service URL")