feat: migrate exchange_island CLI buy command to use centralized aitbc package HTTP client
Some checks failed
CLI Tests / test-cli (push) Failing after 2s
Security Scanning / security-scan (push) Failing after 14m33s
Multi-Node Blockchain Health Monitoring / health-check (push) Has been cancelled

- Replace httpx.Client with aitbc.AITBCHTTPClient in buy command
- Remove async context manager in favor of direct AITBCHTTPClient usage
- Replace status code checks with NetworkError exception handling
- Remove httpx import (no longer needed)
- Simplify error handling with separate NetworkError and generic Exception catches
This commit is contained in:
aitbc
2026-04-24 23:59:03 +02:00
parent ca07a1c670
commit e60aa70da9

View File

@@ -101,43 +101,32 @@ def buy(ctx, ait_amount: float, quote_currency: str, max_price: Optional[float])
# Submit transaction to blockchain
try:
import httpx
with httpx.Client() as client:
response = client.post(
f"{rpc_endpoint}/transaction",
json=buy_order_data,
timeout=10
)
if response.status_code == 200:
result = response.json()
success(f"Buy order created successfully!")
success(f"Order ID: {order_id}")
success(f"Buying {ait_amount} AIT with {quote_currency}")
if max_price:
success(f"Max price: {max_price:.8f} {quote_currency}/AIT")
order_info = {
"Order ID": order_id,
"Pair": pair,
"Side": "BUY",
"Amount": f"{ait_amount} AIT",
"Max Price": f"{max_price:.8f} {quote_currency}/AIT" if max_price else "Market",
"Status": "open",
"User": user_id[:16] + "...",
"Island": island_id[:16] + "..."
}
output(order_info, ctx.obj.get('output_format', 'table'))
else:
error(f"Failed to submit transaction: {response.status_code}")
if response.text:
error(f"Error details: {response.text}")
raise click.Abort()
except Exception as e:
http_client = AITBCHTTPClient(base_url=rpc_endpoint, timeout=10)
result = http_client.post("/transaction", json=buy_order_data)
success(f"Buy order created successfully!")
success(f"Order ID: {order_id}")
success(f"Buying {ait_amount} AIT with {quote_currency}")
if max_price:
success(f"Max price: {max_price:.8f} {quote_currency}/AIT")
order_info = {
"Order ID": order_id,
"Pair": pair,
"Side": "BUY",
"Amount": f"{ait_amount} AIT",
"Max Price": f"{max_price:.8f} {quote_currency}/AIT" if max_price else "Market",
"Status": "open",
"User": user_id[:16] + "...",
"Island": island_id[:16] + "..."
}
output(order_info, ctx.obj.get('output_format', 'table'))
except NetworkError as e:
error(f"Network error submitting transaction: {e}")
raise click.Abort()
except Exception as e:
error(f"Error submitting transaction: {e}")
raise click.Abort()
except Exception as e:
error(f"Error creating buy order: {str(e)}")