99//!
1010//! Run: `TIGER_CONFIG_PATH=~/.tigeropen/tiger_openapi_config.properties cargo run --example quote_example`
1111
12- use tigeropen:: client:: http_client:: HttpClient ;
1312use tigeropen:: config:: ClientConfig ;
1413use tigeropen:: model:: quote:: {
15- CorporateActionRequest , FinancialDailyRequest , FinancialReportRequest , FutureKlineRequest ,
16- MarketScannerRequest ,
14+ Brief , CorporateActionRequest , FinancialDailyRequest , FinancialReportRequest , FutureKlineRequest ,
15+ MarketScannerRequest , MarketState ,
1716} ;
1817use tigeropen:: model:: quote_requests:: {
1918 AllFutureContractsRequest , BarsRequest , BriefRequest , DepthQuoteRequest ,
@@ -96,8 +95,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9695 } ;
9796 println ! ( "tiger_id={} account={}\n " , config. tiger_id, config. account) ;
9897
99- let http = HttpClient :: with_quote_server ( config) ;
100- let qc = QuoteClient :: new ( & http) ;
98+ let qc = QuoteClient :: from_config ( config) ;
10199
102100 let mut results: Vec < RunResult > = Vec :: new ( ) ;
103101
@@ -133,7 +131,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
133131 Err ( e) => fail ( & mut results, "GetBrief" , e) ,
134132 }
135133
136- match qc. get_kline ( "AAPL" , "day" ) . await {
134+ match qc. get_kline ( & [ "AAPL" ] , "day" ) . await {
137135 Ok ( klines) if !klines. is_empty ( ) => ok (
138136 & mut results,
139137 "GetKline(AAPL day)" ,
@@ -346,7 +344,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
346344 let mut expiry_date = String :: new ( ) ;
347345 let mut opt_identifier = String :: new ( ) ;
348346
349- match qc. get_option_expiration ( "AAPL" ) . await {
347+ match qc. get_option_expiration ( & [ "AAPL" ] ) . await {
350348 Ok ( exps) if !exps. is_empty ( ) && !exps[ 0 ] . dates . is_empty ( ) => {
351349 ok (
352350 & mut results,
@@ -365,7 +363,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
365363 skip ( & mut results, "GetOptionBrief" , "no expiry available" ) ;
366364 skip ( & mut results, "GetOptionKline" , "no expiry available" ) ;
367365 } else {
368- match qc. get_option_chain ( "AAPL" , & expiry_date) . await {
366+ match qc. get_option_chain ( & [ ( "AAPL" , & expiry_date) ] ) . await {
369367 Ok ( chain) if !chain. is_empty ( ) && !chain[ 0 ] . items . is_empty ( ) => {
370368 ok (
371369 & mut results,
@@ -401,7 +399,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
401399 Err ( e) => fail ( & mut results, "GetOptionBrief" , e) ,
402400 }
403401
404- match qc. get_option_kline ( & opt_identifier, "day" ) . await {
402+ match qc. get_option_kline ( & [ opt_identifier. as_str ( ) ] , "day" ) . await {
405403 Ok ( ks) if !ks. is_empty ( ) => ok (
406404 & mut results,
407405 "GetOptionKline" ,
@@ -852,6 +850,74 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
852850 Err ( e) => fail ( & mut results, "GetQuoteOvernight(AAPL)" , e) ,
853851 }
854852
853+ // ── low-level call_* API ──────────────────────────────────────────────
854+ println ! ( "\n === Low-level call_* API ===" ) ;
855+
856+ // call_into: raw method name + params, deserializes data directly into T
857+ match qc
858+ . call_into :: < Vec < MarketState > , _ > ( "market_state" , serde_json:: json!( { "market" : "US" } ) )
859+ . await
860+ {
861+ Ok ( states) if !states. is_empty ( ) => ok (
862+ & mut results,
863+ "call_into(market_state)" ,
864+ format ! ( "market={} status={}" , states[ 0 ] . market, states[ 0 ] . market_status) ,
865+ ) ,
866+ Ok ( _) => ok ( & mut results, "call_into(market_state)" , "(empty)" ) ,
867+ Err ( e) => fail ( & mut results, "call_into(market_state)" , e) ,
868+ }
869+
870+ // call_into_versioned: same as call_into but with explicit API version
871+ match qc
872+ . call_into_versioned :: < Vec < MarketState > , _ > (
873+ "market_state" ,
874+ serde_json:: json!( { "market" : "US" } ) ,
875+ Some ( "2.0" ) ,
876+ )
877+ . await
878+ {
879+ Ok ( states) => ok (
880+ & mut results,
881+ "call_into_versioned(market_state, v2.0)" ,
882+ format ! ( "count={}" , states. len( ) ) ,
883+ ) ,
884+ Err ( e) => fail ( & mut results, "call_into_versioned(market_state, v2.0)" , e) ,
885+ }
886+
887+ // call_into_items: unwraps {"items":[...]} envelope
888+ match qc
889+ . call_into_items :: < Brief , _ > (
890+ "brief" ,
891+ serde_json:: json!( { "symbols" : [ "AAPL" ] , "level" : "basic" } ) ,
892+ )
893+ . await
894+ {
895+ Ok ( briefs) if !briefs. is_empty ( ) => ok (
896+ & mut results,
897+ "call_into_items(brief)" ,
898+ format ! ( "symbol={} price={:?}" , briefs[ 0 ] . symbol, briefs[ 0 ] . latest_price) ,
899+ ) ,
900+ Ok ( _) => ok ( & mut results, "call_into_items(brief)" , "(empty)" ) ,
901+ Err ( e) => fail ( & mut results, "call_into_items(brief)" , e) ,
902+ }
903+
904+ // call_optional: returns None when data is absent
905+ match qc
906+ . call_optional :: < Brief , _ > (
907+ "brief" ,
908+ serde_json:: json!( { "symbols" : [ "AAPL" ] , "level" : "basic" } ) ,
909+ )
910+ . await
911+ {
912+ Ok ( Some ( b) ) => ok (
913+ & mut results,
914+ "call_optional(brief)" ,
915+ format ! ( "symbol={}" , b. symbol) ,
916+ ) ,
917+ Ok ( None ) => ok ( & mut results, "call_optional(brief)" , "(no data)" ) ,
918+ Err ( e) => fail ( & mut results, "call_optional(brief)" , e) ,
919+ }
920+
855921 print_summary ( & results) ;
856922 Ok ( ( ) )
857923}
0 commit comments