tradier 0.1.2

This project involves the development of a Rust library for managing trades and market data using the Tradier broker API. The main objective is to provide an efficient and secure interface for executing trades, retrieving real-time quotes, managing portfolios, and accessing historical market data. The library focuses on leveraging Rust's performance and concurrency advantages, enabling integration into high-frequency trading applications and data-intensive financial processing.
Documentation
use serde::Serialize;

use crate::{common::test_support::AccountTypeWire, utils::tests::DateTimeUtcWire};

/// This is a class that's used to model the over-the-wire response of the GetUserProfile API
/// operation. This is used to generate valid JSON to use for testing deserialization of data
/// over the wire.
#[derive(Debug, Serialize, proptest_derive::Arbitrary)]
pub struct GetUserProfileResponseWire {
    profile: UserProfileWire,
}

#[derive(Debug, Serialize, proptest_derive::Arbitrary)]
pub struct UserProfileWire {
    id: String,
    name: String,
    account: Vec<AccountWire>,
}

#[derive(Debug, Serialize, proptest_derive::Arbitrary)]
pub struct AccountWire {
    account_number: String,
    classification: ClassificationWire,
    #[serde(rename = "date_created")]
    date_created: DateTimeUtcWire,
    day_trader: bool,
    option_level: u8,
    status: AccountStatusWire,
    #[serde(rename = "type")]
    account_type: AccountTypeWire,
    #[serde(rename = "last_update_date")]
    last_update_date: DateTimeUtcWire,
}

#[derive(Debug, Serialize, proptest_derive::Arbitrary)]
#[serde(rename_all = "lowercase")]
pub enum ClassificationWire {
    Individual,
    Corporate,
    Joint,
    Ira,
    RothIra,
    Entity,
}

#[derive(Debug, Serialize, proptest_derive::Arbitrary)]
#[serde(rename_all = "lowercase")]
pub enum AccountStatusWire {
    Active,
    Closed,
}

#[cfg(test)]
mod test {
    use super::*;
    use proptest::prelude::*;
    use serde_json::{json, Value};
    use std::fs::OpenOptions;
    use tracing::debug;

    static PATH: &str = "src/user/get_user_profile_schema.json";

    #[test]
    fn should_fail_to_process_an_empty_object() {
        let reader = OpenOptions::new()
            .read(true)
            .open(PATH)
            .expect("schema file to exist and be readable");
        let reader = std::io::BufReader::new(reader);
        let schema: Value =
            serde_json::from_reader(reader).expect("parsing the schema as a Value object to work");
        let validator =
            jsonschema::validator_for(&schema).expect("validator in test to work as expected");
        assert!(!validator.is_valid(
            &serde_json::to_value(json!({})).expect("serde to serialize the object correctly")
        ));
    }
    proptest! {

        #[test]
        fn serialized_wire_objects_should_conform_to_schema(wire_object in any::<GetUserProfileResponseWire>()) {
            let reader = OpenOptions::new().read(true).open(PATH).expect("schema file to exist and be readable");
            let reader = std::io::BufReader::new(reader);
            let schema: Value = serde_json::from_reader(reader)
                .expect("parsing the schema as a Value object to work");
            let validator = jsonschema::validator_for(&schema)
                .expect("validator in test to work as expected");
            let actual_serialized_value = serde_json::to_value(&wire_object)
                .expect("serde to serialize the object correctly");
            debug!("{:#?}", &actual_serialized_value);
            prop_assert!(validator.is_valid(&actual_serialized_value));
        }
    }
}