feat: migrate exchange_island CLI buy command to use centralized aitbc package HTTP client
- 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:
@@ -101,16 +101,8 @@ 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()
|
||||
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}")
|
||||
@@ -128,15 +120,12 @@ def buy(ctx, ait_amount: float, quote_currency: str, max_price: Optional[float])
|
||||
"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}")
|
||||
except NetworkError as e:
|
||||
error(f"Network error submitting transaction: {e}")
|
||||
raise click.Abort()
|
||||
except Exception as e:
|
||||
error(f"Network error submitting transaction: {e}")
|
||||
error(f"Error submitting transaction: {e}")
|
||||
raise click.Abort()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user