Struct longport::quote::QuoteContext
source · pub struct QuoteContext { /* private fields */ }
Expand description
Quote context
Implementations§
source§impl QuoteContext
impl QuoteContext
sourcepub async fn try_new(
config: Arc<Config>
) -> Result<(Self, UnboundedReceiver<PushEvent>)>
pub async fn try_new( config: Arc<Config> ) -> Result<(Self, UnboundedReceiver<PushEvent>)>
Create a QuoteContext
sourcepub fn quote_level(&self) -> &str
pub fn quote_level(&self) -> &str
Returns the quote level
sourcepub async fn subscribe<I, T>(
&self,
symbols: I,
sub_types: impl Into<SubFlags>,
is_first_push: bool
) -> Result<()>
pub async fn subscribe<I, T>( &self, symbols: I, sub_types: impl Into<SubFlags>, is_first_push: bool ) -> Result<()>
Subscribe
Reference: https://open.longportapp.com/en/docs/quote/subscribe/subscribe
§Examples
use std::sync::Arc;
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, mut receiver) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::QUOTE, false)
.await?;
while let Some(msg) = receiver.recv().await {
println!("{:?}", msg);
}
sourcepub async fn unsubscribe<I, T>(
&self,
symbols: I,
sub_types: impl Into<SubFlags>
) -> Result<()>
pub async fn unsubscribe<I, T>( &self, symbols: I, sub_types: impl Into<SubFlags> ) -> Result<()>
Unsubscribe
Reference: https://open.longportapp.com/en/docs/quote/subscribe/unsubscribe
§Examples
use std::sync::Arc;
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::QUOTE, false)
.await?;
ctx.unsubscribe(["AAPL.US"], SubFlags::QUOTE).await?;
sourcepub async fn subscribe_candlesticks<T>(
&self,
symbol: T,
period: Period
) -> Result<()>
pub async fn subscribe_candlesticks<T>( &self, symbol: T, period: Period ) -> Result<()>
Subscribe security candlesticks
§Examples
use std::sync::Arc;
use longport::{
quote::{Period, QuoteContext},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, mut receiver) = QuoteContext::try_new(config).await?;
ctx.subscribe_candlesticks("AAPL.US", Period::OneMinute)
.await?;
while let Some(msg) = receiver.recv().await {
println!("{:?}", msg);
}
sourcepub async fn unsubscribe_candlesticks<T>(
&self,
symbol: T,
period: Period
) -> Result<()>
pub async fn unsubscribe_candlesticks<T>( &self, symbol: T, period: Period ) -> Result<()>
Unsubscribe security candlesticks
sourcepub async fn subscriptions(&self) -> Result<Vec<Subscription>>
pub async fn subscriptions(&self) -> Result<Vec<Subscription>>
Get subscription information
§Examples
use std::sync::Arc;
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::QUOTE, false)
.await?;
let resp = ctx.subscriptions().await?;
println!("{:?}", resp);
sourcepub async fn static_info<I, T>(
&self,
symbols: I
) -> Result<Vec<SecurityStaticInfo>>
pub async fn static_info<I, T>( &self, symbols: I ) -> Result<Vec<SecurityStaticInfo>>
Get basic information of securities
Reference: https://open.longportapp.com/en/docs/quote/pull/static
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx
.static_info(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
.await?;
println!("{:?}", resp);
sourcepub async fn quote<I, T>(&self, symbols: I) -> Result<Vec<SecurityQuote>>
pub async fn quote<I, T>(&self, symbols: I) -> Result<Vec<SecurityQuote>>
Get quote of securities
Reference: https://open.longportapp.com/en/docs/quote/pull/quote
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx
.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
.await?;
println!("{:?}", resp);
sourcepub async fn option_quote<I, T>(&self, symbols: I) -> Result<Vec<OptionQuote>>
pub async fn option_quote<I, T>(&self, symbols: I) -> Result<Vec<OptionQuote>>
Get quote of option securities
Reference: https://open.longportapp.com/en/docs/quote/pull/option-quote
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.option_quote(["AAPL230317P160000.US"]).await?;
println!("{:?}", resp);
sourcepub async fn warrant_quote<I, T>(&self, symbols: I) -> Result<Vec<WarrantQuote>>
pub async fn warrant_quote<I, T>(&self, symbols: I) -> Result<Vec<WarrantQuote>>
Get quote of warrant securities
Reference: https://open.longportapp.com/en/docs/quote/pull/warrant-quote
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.warrant_quote(["21125.HK"]).await?;
println!("{:?}", resp);
sourcepub async fn depth(&self, symbol: impl Into<String>) -> Result<SecurityDepth>
pub async fn depth(&self, symbol: impl Into<String>) -> Result<SecurityDepth>
Get security depth
Reference: https://open.longportapp.com/en/docs/quote/pull/depth
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.depth("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn brokers(
&self,
symbol: impl Into<String>
) -> Result<SecurityBrokers>
pub async fn brokers( &self, symbol: impl Into<String> ) -> Result<SecurityBrokers>
Get security brokers
Reference: https://open.longportapp.com/en/docs/quote/pull/brokers
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.brokers("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn participants(&self) -> Result<Vec<ParticipantInfo>>
pub async fn participants(&self) -> Result<Vec<ParticipantInfo>>
Get participants
Reference: https://open.longportapp.com/en/docs/quote/pull/broker-ids
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.participants().await?;
println!("{:?}", resp);
sourcepub async fn trades(
&self,
symbol: impl Into<String>,
count: usize
) -> Result<Vec<Trade>>
pub async fn trades( &self, symbol: impl Into<String>, count: usize ) -> Result<Vec<Trade>>
Get security trades
Reference: https://open.longportapp.com/en/docs/quote/pull/trade
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.trades("700.HK", 10).await?;
println!("{:?}", resp);
sourcepub async fn intraday(
&self,
symbol: impl Into<String>
) -> Result<Vec<IntradayLine>>
pub async fn intraday( &self, symbol: impl Into<String> ) -> Result<Vec<IntradayLine>>
Get security intraday lines
Reference: https://open.longportapp.com/en/docs/quote/pull/intraday
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.intraday("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn candlesticks(
&self,
symbol: impl Into<String>,
period: Period,
count: usize,
adjust_type: AdjustType
) -> Result<Vec<Candlestick>>
pub async fn candlesticks( &self, symbol: impl Into<String>, period: Period, count: usize, adjust_type: AdjustType ) -> Result<Vec<Candlestick>>
Get security candlesticks
Reference: https://open.longportapp.com/en/docs/quote/pull/candlestick
§Examples
use std::sync::Arc;
use longport::{
quote::{AdjustType, Period, QuoteContext},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx
.candlesticks("700.HK", Period::Day, 10, AdjustType::NoAdjust)
.await?;
println!("{:?}", resp);
sourcepub async fn history_candlesticks_by_offset(
&self,
symbol: impl Into<String>,
period: Period,
adjust_type: AdjustType,
forward: bool,
time: PrimitiveDateTime,
count: usize
) -> Result<Vec<Candlestick>>
pub async fn history_candlesticks_by_offset( &self, symbol: impl Into<String>, period: Period, adjust_type: AdjustType, forward: bool, time: PrimitiveDateTime, count: usize ) -> Result<Vec<Candlestick>>
Get security history candlesticks by offset
sourcepub async fn history_candlesticks_by_date(
&self,
symbol: impl Into<String>,
period: Period,
adjust_type: AdjustType,
start: Option<Date>,
end: Option<Date>
) -> Result<Vec<Candlestick>>
pub async fn history_candlesticks_by_date( &self, symbol: impl Into<String>, period: Period, adjust_type: AdjustType, start: Option<Date>, end: Option<Date> ) -> Result<Vec<Candlestick>>
Get security history candlesticks by date
sourcepub async fn option_chain_expiry_date_list(
&self,
symbol: impl Into<String>
) -> Result<Vec<Date>>
pub async fn option_chain_expiry_date_list( &self, symbol: impl Into<String> ) -> Result<Vec<Date>>
Get option chain expiry date list
Reference: https://open.longportapp.com/en/docs/quote/pull/optionchain-date
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.option_chain_expiry_date_list("AAPL.US").await?;
println!("{:?}", resp);
sourcepub async fn option_chain_info_by_date(
&self,
symbol: impl Into<String>,
expiry_date: Date
) -> Result<Vec<StrikePriceInfo>>
pub async fn option_chain_info_by_date( &self, symbol: impl Into<String>, expiry_date: Date ) -> Result<Vec<StrikePriceInfo>>
Get option chain info by date
Reference: https://open.longportapp.com/en/docs/quote/pull/optionchain-date-strike
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
use time::macros::date;
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx
.option_chain_info_by_date("AAPL.US", date!(2023 - 01 - 20))
.await?;
println!("{:?}", resp);
sourcepub async fn warrant_issuers(&self) -> Result<Vec<IssuerInfo>>
pub async fn warrant_issuers(&self) -> Result<Vec<IssuerInfo>>
Get warrant issuers
Reference: https://open.longportapp.com/en/docs/quote/pull/issuer
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.warrant_issuers().await?;
println!("{:?}", resp);
sourcepub async fn warrant_list(
&self,
symbol: impl Into<String>,
sort_by: WarrantSortBy,
sort_order: SortOrderType,
warrant_type: Option<&[WarrantType]>,
issuer: Option<&[i32]>,
expiry_date: Option<&[FilterWarrantExpiryDate]>,
price_type: Option<&[FilterWarrantInOutBoundsType]>,
status: Option<&[WarrantStatus]>
) -> Result<Vec<WarrantInfo>>
pub async fn warrant_list( &self, symbol: impl Into<String>, sort_by: WarrantSortBy, sort_order: SortOrderType, warrant_type: Option<&[WarrantType]>, issuer: Option<&[i32]>, expiry_date: Option<&[FilterWarrantExpiryDate]>, price_type: Option<&[FilterWarrantInOutBoundsType]>, status: Option<&[WarrantStatus]> ) -> Result<Vec<WarrantInfo>>
Query warrant list
sourcepub async fn trading_session(&self) -> Result<Vec<MarketTradingSession>>
pub async fn trading_session(&self) -> Result<Vec<MarketTradingSession>>
Get trading session of the day
Reference: https://open.longportapp.com/en/docs/quote/pull/trade-session
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.trading_session().await?;
println!("{:?}", resp);
sourcepub async fn trading_days(
&self,
market: Market,
begin: Date,
end: Date
) -> Result<MarketTradingDays>
pub async fn trading_days( &self, market: Market, begin: Date, end: Date ) -> Result<MarketTradingDays>
Get market trading days
The interval must be less than one month, and only the most recent year is supported.
Reference: https://open.longportapp.com/en/docs/quote/pull/trade-day
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config, Market};
use time::macros::date;
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx
.trading_days(Market::HK, date!(2022 - 01 - 20), date!(2022 - 02 - 20))
.await?;
println!("{:?}", resp);
sourcepub async fn capital_flow(
&self,
symbol: impl Into<String>
) -> Result<Vec<CapitalFlowLine>>
pub async fn capital_flow( &self, symbol: impl Into<String> ) -> Result<Vec<CapitalFlowLine>>
Get capital flow intraday
Reference: https://open.longportapp.com/en/docs/quote/pull/capital-flow-intraday
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.capital_flow("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn capital_distribution(
&self,
symbol: impl Into<String>
) -> Result<CapitalDistributionResponse>
pub async fn capital_distribution( &self, symbol: impl Into<String> ) -> Result<CapitalDistributionResponse>
Get capital distribution
Reference: https://open.longportapp.com/en/docs/quote/pull/capital-distribution
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.capital_distribution("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn calc_indexes<I, T, J>(
&self,
symbols: I,
indexes: J
) -> Result<Vec<SecurityCalcIndex>>
pub async fn calc_indexes<I, T, J>( &self, symbols: I, indexes: J ) -> Result<Vec<SecurityCalcIndex>>
Get calc indexes
sourcepub async fn watchlist(&self) -> Result<Vec<WatchlistGroup>>
pub async fn watchlist(&self) -> Result<Vec<WatchlistGroup>>
Get watchlist
Reference: https://open.longportapp.com/en/docs/quote/individual/watchlist_groups
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let resp = ctx.watchlist().await?;
println!("{:?}", resp);
sourcepub async fn create_watchlist_group(
&self,
req: RequestCreateWatchlistGroup
) -> Result<i64>
pub async fn create_watchlist_group( &self, req: RequestCreateWatchlistGroup ) -> Result<i64>
Create watchlist group
Reference: https://open.longportapp.com/en/docs/quote/individual/watchlist_create_group
§Examples
use std::sync::Arc;
use longport::{
quote::{QuoteContext, RequestCreateWatchlistGroup},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let req = RequestCreateWatchlistGroup::new("Watchlist1").securities(["700.HK", "BABA.US"]);
let group_id = ctx.create_watchlist_group(req).await?;
println!("{}", group_id);
sourcepub async fn delete_watchlist_group(&self, id: i64, purge: bool) -> Result<()>
pub async fn delete_watchlist_group(&self, id: i64, purge: bool) -> Result<()>
Delete watchlist group
Reference: https://open.longportapp.com/en/docs/quote/individual/watchlist_delete_group
§Examples
use std::sync::Arc;
use longport::{quote::QuoteContext, Config};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.delete_watchlist_group(10086, true).await?;
sourcepub async fn update_watchlist_group(
&self,
req: RequestUpdateWatchlistGroup
) -> Result<()>
pub async fn update_watchlist_group( &self, req: RequestUpdateWatchlistGroup ) -> Result<()>
Update watchlist group
Reference: https://open.longportapp.com/en/docs/quote/individual/watchlist_update_group Reference: https://open.longportapp.com/en/docs/quote/individual/watchlist_update_group_securities
§Examples
use std::sync::Arc;
use longport::{
quote::{QuoteContext, RequestUpdateWatchlistGroup},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
let req = RequestUpdateWatchlistGroup::new(10086)
.name("Watchlist2")
.securities(["700.HK", "BABA.US"]);
ctx.update_watchlist_group(req).await?;
sourcepub async fn realtime_quote<I, T>(
&self,
symbols: I
) -> Result<Vec<RealtimeQuote>>
pub async fn realtime_quote<I, T>( &self, symbols: I ) -> Result<Vec<RealtimeQuote>>
Get real-time quotes
Get real-time quotes of the subscribed symbols, it always returns the data in the local storage.
§Examples
use std::{sync::Arc, time::Duration};
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::QUOTE, true)
.await?;
tokio::time::sleep(Duration::from_secs(5)).await;
let resp = ctx.realtime_quote(["700.HK", "AAPL.US"]).await?;
println!("{:?}", resp);
sourcepub async fn realtime_depth(
&self,
symbol: impl Into<String>
) -> Result<SecurityDepth>
pub async fn realtime_depth( &self, symbol: impl Into<String> ) -> Result<SecurityDepth>
Get real-time depth
Get real-time depth of the subscribed symbols, it always returns the data in the local storage.
§Examples
use std::{sync::Arc, time::Duration};
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::DEPTH, true)
.await?;
tokio::time::sleep(Duration::from_secs(5)).await;
let resp = ctx.realtime_depth("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn realtime_trades(
&self,
symbol: impl Into<String>,
count: usize
) -> Result<Vec<Trade>>
pub async fn realtime_trades( &self, symbol: impl Into<String>, count: usize ) -> Result<Vec<Trade>>
Get real-time trades
Get real-time trades of the subscribed symbols, it always returns the data in the local storage.
§Examples
use std::{sync::Arc, time::Duration};
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::TRADE, false)
.await?;
tokio::time::sleep(Duration::from_secs(5)).await;
let resp = ctx.realtime_trades("700.HK", 10).await?;
println!("{:?}", resp);
sourcepub async fn realtime_brokers(
&self,
symbol: impl Into<String>
) -> Result<SecurityBrokers>
pub async fn realtime_brokers( &self, symbol: impl Into<String> ) -> Result<SecurityBrokers>
Get real-time broker queue
Get real-time broker queue of the subscribed symbols, it always returns the data in the local storage.
§Examples
use std::{sync::Arc, time::Duration};
use longport::{
quote::{QuoteContext, SubFlags},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe(["700.HK", "AAPL.US"], SubFlags::BROKER, true)
.await?;
tokio::time::sleep(Duration::from_secs(5)).await;
let resp = ctx.realtime_brokers("700.HK").await?;
println!("{:?}", resp);
sourcepub async fn realtime_candlesticks(
&self,
symbol: impl Into<String>,
period: Period,
count: usize
) -> Result<Vec<Candlestick>>
pub async fn realtime_candlesticks( &self, symbol: impl Into<String>, period: Period, count: usize ) -> Result<Vec<Candlestick>>
Get real-time candlesticks
Get real-time candlesticks of the subscribed symbols, it always returns the data in the local storage.
§Examples
use std::{sync::Arc, time::Duration};
use longport::{
quote::{Period, QuoteContext},
Config,
};
let config = Arc::new(Config::from_env()?);
let (ctx, _) = QuoteContext::try_new(config).await?;
ctx.subscribe_candlesticks("AAPL.US", Period::OneMinute)
.await?;
tokio::time::sleep(Duration::from_secs(5)).await;
let resp = ctx
.realtime_candlesticks("AAPL.US", Period::OneMinute, 10)
.await?;
println!("{:?}", resp);
Trait Implementations§
source§impl Clone for QuoteContext
impl Clone for QuoteContext
source§fn clone(&self) -> QuoteContext
fn clone(&self) -> QuoteContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more