use std::sync::Arc;
use axum::{extract::State, http::StatusCode, response::Json, extract::Path};
use bitcoin_de::bitcoin_de_trading_api_sdk_v4::TradingApiSdkV4; use bitcoin_de::enums::TradingPair; use bitcoin_de::bitcoin_de_trading_api_sdk_v4::responses::account::ShowAccountInfoResponse; use bitcoin_de::bitcoin_de_trading_api_sdk_v4::responses::misc::ShowRatesResponse; use bitcoin_de::bitcoin_de_trading_api_sdk_v4::errors::ApiErrorDetail;
#[axum::debug_handler]
pub async fn handle_show_account_info(
State(sdk): State<Arc<TradingApiSdkV4>>,
) -> Result<Json<ShowAccountInfoResponse>, StatusCode> { let result = sdk.show_account_info().await;
match result {
Ok(response) => {
Ok(Json(response))
}
Err(e) => {
eprintln!("Error in showAccountInfo handler: {}", e);
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
}
}
#[axum::debug_handler]
pub async fn handle_show_rates(
State(sdk): State<Arc<TradingApiSdkV4>>,
Path(trading_pair_str): Path<String>,
) -> Result<Json<ShowRatesResponse>, StatusCode> {
let trading_pair = match TradingPair::from_str(&trading_pair_str) {
Ok(pair) => pair,
Err(_) => {
eprintln!("Invalid trading pair received in handler: {}", trading_pair_str);
return Err(StatusCode::BAD_REQUEST);
}
};
let result = sdk.show_rates(trading_pair).await;
match result {
Ok(response) => {
Ok(Json(response))
}
Err(e) => {
eprintln!("Error in showRates handler for {}: {}", trading_pair_str, e);
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
}
}