longport::quote

Struct QuoteContext

source
pub struct QuoteContext { /* private fields */ }
Expand description

Quote context

Implementations§

source§

impl QuoteContext

source

pub async fn try_new( config: Arc<Config>, ) -> Result<(Self, UnboundedReceiver<PushEvent>)>

Create a QuoteContext

source

pub fn member_id(&self) -> i64

Returns the member ID

source

pub fn quote_level(&self) -> &str

Returns the quote level

source

pub fn quote_package_details(&self) -> &[QuotePackageDetail]

Returns the quote package details

source

pub async fn subscribe<I, T>( &self, symbols: I, sub_types: impl Into<SubFlags>, is_first_push: bool, ) -> Result<()>
where I: IntoIterator<Item = T>, T: AsRef<str>,

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);
}
source

pub async fn unsubscribe<I, T>( &self, symbols: I, sub_types: impl Into<SubFlags>, ) -> Result<()>
where I: IntoIterator<Item = T>, T: AsRef<str>,

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?;
source

pub async fn subscribe_candlesticks<T>( &self, symbol: T, period: Period, ) -> Result<Vec<Candlestick>>
where T: AsRef<str>,

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);
}
source

pub async fn unsubscribe_candlesticks<T>( &self, symbol: T, period: Period, ) -> Result<()>
where T: AsRef<str>,

Unsubscribe security candlesticks

source

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);
source

pub async fn static_info<I, T>( &self, symbols: I, ) -> Result<Vec<SecurityStaticInfo>>
where I: IntoIterator<Item = T>, T: Into<String>,

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);
source

pub async fn quote<I, T>(&self, symbols: I) -> Result<Vec<SecurityQuote>>
where I: IntoIterator<Item = T>, T: Into<String>,

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);
source

pub async fn option_quote<I, T>(&self, symbols: I) -> Result<Vec<OptionQuote>>
where I: IntoIterator<Item = T>, T: Into<String>,

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);
source

pub async fn warrant_quote<I, T>(&self, symbols: I) -> Result<Vec<WarrantQuote>>
where I: IntoIterator<Item = T>, T: Into<String>,

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

pub async fn history_candlesticks_by_offset( &self, symbol: impl Into<String>, period: Period, adjust_type: AdjustType, forward: bool, time: Option<PrimitiveDateTime>, count: usize, ) -> Result<Vec<Candlestick>>

Get security history candlesticks by offset

source

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

source

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);
source

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);
source

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);
source

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

source

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);
source

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);
source

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);
source

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);
source

pub async fn calc_indexes<I, T, J>( &self, symbols: I, indexes: J, ) -> Result<Vec<SecurityCalcIndex>>
where I: IntoIterator<Item = T>, T: Into<String>, J: IntoIterator<Item = CalcIndex>,

Get calc indexes

source

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);
source

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);
source

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?;
source

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?;
source

pub async fn security_list( &self, market: Market, category: SecurityListCategory, ) -> Result<Vec<Security>>

Get security list

source

pub async fn realtime_quote<I, T>( &self, symbols: I, ) -> Result<Vec<RealtimeQuote>>
where I: IntoIterator<Item = T>, T: Into<String>,

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);
source

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);
source

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);
source

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);
source

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

source§

fn clone(&self) -> QuoteContext

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T