Skip to content

Commit 33ab860

Browse files
committed
Make api::v2::asset::Asset serializable
This change makes objects of the type api::v2::asset::Asset serializable, so that we are not only able to parse them from an upstream source but can also emit them ourselves.
1 parent c5c9c7d commit 33ab860

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/api/v2/asset.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl FromStr for Exchange {
314314

315315

316316
/// The representation of an asset as used by Alpaca.
317-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
317+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
318318
#[non_exhaustive]
319319
pub struct Asset {
320320
/// The asset's ID.
@@ -499,6 +499,20 @@ mod tests {
499499
assert_eq!(asset.exchange, Exchange::Unknown);
500500
}
501501

502+
/// Check that we can serialize and deserialize an `Asset` object.
503+
#[test(tokio::test)]
504+
async fn serialize_deserialize_asset() {
505+
let api_info = ApiInfo::from_env().unwrap();
506+
let client = Client::new(api_info);
507+
let asset = client
508+
.issue::<Get>(&Symbol::try_from("SPY").unwrap())
509+
.await
510+
.unwrap();
511+
512+
let json = to_json(&asset).unwrap();
513+
assert_eq!(from_json::<Asset>(&json).unwrap(), asset);
514+
}
515+
502516
/// Check that we can retrieve information about an asset.
503517
#[test(tokio::test)]
504518
async fn retrieve_asset() {

0 commit comments

Comments
 (0)