I am trying to turn a object into json with serde so I can post it reqwest. However, it doesn't seem to turn into proper json when I do what I believe I have to do.
I have the struct Order:
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Order {
#[serde(rename = "Uic")]
uic: i64,
#[serde(rename = "BuySell")]
buy_sell: String,
#[serde(rename = "AssetType")]
asset_type: String,
#[serde(rename = "Amount")]
amount: i64,
#[serde(rename = "OrderType")]
order_type: String,
#[serde(rename = "OrderRelation")]
order_relation: String,
#[serde(rename = "ManualOrder")]
manual_order: bool,
#[serde(rename = "AccountKey")]
account_key: String,
}
that I serialize and try to post to an api. When I either try to send it to the API I can see on the API (The live one gives a invalid body return, so I use Postman Mock Server to test the API call) that the body that is being sent is
{
{
key: "{"Uic":16,"BuySell":"Buy","AssetType":"FxSpot","Amount":1000,"OrderType":"Market","OrderRelation":"StandAlone","ManualOrder":false,"AccountKey":"GfCSX|cXT0uDkDakbet8NQ"
value: "="}"
}
}
This is how I send it:
let body = serde_json::to_string(&order).unwrap();
let order_id = client
.post(url)
.headers(headers)
.bearer_auth(access_token)
.body(body)
.send()
.await?
.text()
//.json::<OrderPlacementResponse>()
.await?
;
let mut file = std::fs::File::create("order.json")?;
serde_json::to_writer_pretty(&mut file, &order)?;
At the end I save it to a file and it looks like:
{
"Uic": 16,
"BuySell": "Buy",
"AssetType": "FxSpot",
"Amount": 1000,
"OrderType": "Market",
"OrderRelation": "StandAlone",
"ManualOrder": false,
"AccountKey": "GfCSX|cXT0uDkDakbet8NQ=="
}
Which is how it should look. If I send this body to the url using Postman I get the correct response. So the error is definitely in how I make the body. I just can't figure out how to fix it.