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