schwab-developer 0.1.0

A library for Charles Schwab API.
Documentation
use crate::{auth::provider::Provider, market::parameter::{InstrumentsParam, MoversParam, OptionChainParam, PriceHistoryParam, QuotesParam}};

#[tokio::test]
async fn test_quotes() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let param = QuotesParam {
        symbols: "AAPL".into(),
        ..Default::default()
    };
    let result = client.quotes(param).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_single_quote() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let symbol = "AAPL";
    let result = client.single_quote(symbol, None).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_option_chain() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let param = OptionChainParam {
        symbol: "AAPL".into(),
        ..Default::default()
    };
    let result = client.option_chains(param).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_option_expiration_chain() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let symbol = "AAPL";
    let result = client.option_expiration_chain(symbol).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_price_history() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let param = PriceHistoryParam {
        symbol: "AAPL".into(),
        ..Default::default()
    };
    let result = client.price_history(param).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_movers() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let param = MoversParam {
        symbol_id: "OPTION_ALL".into(),
        sort: Some("VOLUME".into()),
        frequency: Some(10)
    };
    let result = client.movers(param).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_market_hours() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let markets = vec!["equity".to_string(), "option".to_string()];
    let result = client.market_hours(markets, None).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_single_market_hours() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let market_id = "equity";
    let result = client.single_market_hours(market_id, None).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_instruments() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let param = InstrumentsParam {
        symbol: "AAPL".into(),
        projection: "fundamental".into()
    };
    let result = client.instruments(param).await?;
    println!("{:#?}", result);
    Ok(())
}

#[tokio::test]
async fn test_single_instrument() -> anyhow::Result<()> {
    let provider = Provider::new();
    provider.login().await?;

    let client = provider.client().await?;
    let cusip_id = "037833100";
    let result = client.single_instrument(cusip_id).await?;
    println!("{:#?}", result);
    Ok(())
}