use simulator_api::AccountModifications;
use crate::{BacktestClientError, BacktestClientResult};
pub async fn modify_accounts(
rpc_url: &str,
modifications: &AccountModifications,
) -> BacktestClientResult<usize> {
let count = modifications.0.len();
let body = serde_json::json!({
"jsonrpc": "2.0",
"id": 1,
"method": "modifyAccounts",
"params": [modifications],
});
let resp: serde_json::Value = reqwest::Client::new()
.post(rpc_url)
.json(&body)
.send()
.await
.map_err(|e| BacktestClientError::Http {
url: rpc_url.to_string(),
source: Box::new(e),
})?
.json()
.await
.map_err(|e| BacktestClientError::Http {
url: rpc_url.to_string(),
source: Box::new(e),
})?;
if let Some(error) = resp.get("error") {
return Err(BacktestClientError::Http {
url: rpc_url.to_string(),
source: format!("modifyAccounts RPC error: {error}").into(),
});
}
Ok(count)
}