1use simulator_api::AccountModifications;
2
3use crate::{BacktestClientError, BacktestClientResult};
4
5pub async fn modify_accounts(
9 rpc_url: &str,
10 modifications: &AccountModifications,
11) -> BacktestClientResult<usize> {
12 let count = modifications.0.len();
13 let body = serde_json::json!({
14 "jsonrpc": "2.0",
15 "id": 1,
16 "method": "modifyAccounts",
17 "params": [modifications],
18 });
19
20 let resp: serde_json::Value = reqwest::Client::new()
21 .post(rpc_url)
22 .json(&body)
23 .send()
24 .await
25 .map_err(|e| BacktestClientError::Http {
26 url: rpc_url.to_string(),
27 source: Box::new(e),
28 })?
29 .json()
30 .await
31 .map_err(|e| BacktestClientError::Http {
32 url: rpc_url.to_string(),
33 source: Box::new(e),
34 })?;
35
36 if let Some(error) = resp.get("error") {
37 return Err(BacktestClientError::Http {
38 url: rpc_url.to_string(),
39 source: format!("modifyAccounts RPC error: {error}").into(),
40 });
41 }
42
43 Ok(count)
44}