#![cfg(feature = "backend")]
mod handler;
use handler::{handle_show_account_info, handle_show_rates};
use {
bitcoin_de::bitcoin_de_trading_api_sdk_v4::TradingApiSdkV4,
bitcoin_de::enums::TradingPair::*,
axum::{
extract::FromRequest,
response::IntoResponse,
routing::get,
},
futures_util::stream::StreamExt,
tokio::net::TcpListener,
std::sync::Arc,
};
#[tokio::main] async fn main() { use axum::{routing::get, Router}; use std::net::SocketAddr; dotenv::dotenv().ok(); async fn hello_world() -> &'static str {
"Hello from the Bitcoin.de Axum Backend!"
}
let api_key = std::env::var("API_KEY").expect("API_KEY not set for backend"); let api_secret = std::env::var("API_SECRET").expect("API_SECRET not set for backend"); let sdk_client = TradingApiSdkV4::new(api_key, api_secret);
let sdk_client = Arc::new(sdk_client);
let app = Router::new()
.route("/", get(hello_world)) .route("/api/v4/account/info", get(handle_show_account_info)) .route("/api/v4/rates/{trading_pair}", get(handle_show_account_info)) .with_state(sdk_client);
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("Axum backend listening on {}", addr);
let listener = TcpListener::bind(&addr).await.unwrap();
println!("Starting server at http://{}", addr);
axum::serve(listener, app.into_make_service()).await.expect("Server error");
}
#[cfg(not(feature = "backend"))]
fn main() {
println!("Backend binary is not enabled in this build configuration.");
}