Package com.longport.quote
Class QuoteContext
- java.lang.Object
-
- com.longport.quote.QuoteContext
-
- All Implemented Interfaces:
AutoCloseable
public class QuoteContext extends Object implements AutoCloseable
Quote context
-
-
Constructor Summary
Constructors Constructor Description QuoteContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static CompletableFuture<QuoteContext>
create(Config config)
Create a QuoteContext objectCompletableFuture<Long>
createWatchlistGroup(CreateWatchlistGroup req)
Create watchlist groupCompletableFuture<Void>
deleteWatchlistGroup(DeleteWatchlistGroup req)
Delete watchlist groupCompletableFuture<SecurityBrokers>
getBrokers(String symbol)
Get security brokersCompletableFuture<SecurityCalcIndex[]>
getCalcIndexes(String[] symbols, CalcIndex[] indexes)
Get security calc indexesCompletableFuture<Candlestick[]>
getCandlesticks(String symbol, Period period, int count, AdjustType adjustType)
Get security candlesticksCompletableFuture<CapitalFlowLine[]>
getCapitalFlow(String symbol)
Get capital flow intradayCompletableFuture<SecurityDepth>
getDepth(String symbol)
Get security depthCompletableFuture<Candlestick[]>
getHistoryCandlesticksByDate(String symbol, Period period, AdjustType adjustType, LocalDate start, LocalDate end)
Get history candlesticks by dateCompletableFuture<Candlestick[]>
getHistoryCandlesticksByOffset(String symbol, Period period, AdjustType adjustType, boolean forward, LocalDateTime datetime, int count)
Get history candlesticks by offsetCompletableFuture<IntradayLine[]>
getIntraday(String symbol)
Get security intraday lineslong
getMemberId()
Returns the member IDCompletableFuture<LocalDate[]>
getOptionChainExpiryDateList(String symbol)
Get option chain expiry date listCompletableFuture<StrikePriceInfo[]>
getOptionChainInfoByDate(String symbol, LocalDate expiryDate)
Get option chain info by dateCompletableFuture<OptionQuote[]>
getOptionQuote(String[] symbols)
Get quote of option securitiesCompletableFuture<ParticipantInfo[]>
getParticipants()
Get participantsCompletableFuture<SecurityQuote[]>
getQuote(String[] symbols)
Get quote of securitiesString
getQuoteLevel()
Returns the quote levelQuotePackageDetail[]
getQuotePackageDetails()
Returns the quote package detailsCompletableFuture<SecurityBrokers>
getRealtimeBrokers(String symbol)
Get real-time broker queueCompletableFuture<Candlestick[]>
getRealtimeCandlesticks(String symbol, Period period, int count)
Get real-time candlesticksCompletableFuture<SecurityDepth>
getRealtimeDepth(String symbol)
Get real-time depthCompletableFuture<RealtimeQuote[]>
getRealtimeQuote(String[] symbols)
Get real-time quotesCompletableFuture<Trade[]>
getRealtimeTrades(String symbol, int count)
Get real-time tradesCompletableFuture<SecurityStaticInfo[]>
getStaticInfo(String[] symbols)
Get basic information of securitiesCompletableFuture<Subscription[]>
getSubscrptions()
Get subscription informationCompletableFuture<Trade[]>
getTrades(String symbol, int count)
Get security tradesCompletableFuture<MarketTradingDays>
getTradingDays(Market market, LocalDate begin, LocalDate end)
Get market trading daysCompletableFuture<MarketTradingSession[]>
getTradingSession()
Get trading session of the dayCompletableFuture<IssuerInfo[]>
getWarrantIssuers()
Get warrant issuersCompletableFuture<WarrantQuote[]>
getWarrantQuote(String[] symbols)
Get quote of warrant securitiesCompletableFuture<WatchlistGroup[]>
getWatchlist()
Get watchlistCompletableFuture<WarrantInfo[]>
queryWarrantList(QueryWarrantOptions opts)
Query warrant listCompletableFuture<Security[]>
securityList(Market market, SecurityListCategory category)
Security listvoid
setOnBrokers(BrokersHandler handler)
Set brokers callback, after receiving the brokers data push, it will call back to this handler.void
setOnCandlestick(CandlestickHandler handler)
Set candlestick callback, after receiving the trades data push, it will call back to this function.void
setOnDepth(DepthHandler handler)
Set depth callback, after receiving the depth data push, it will call back to this handler.void
setOnQuote(QuoteHandler handler)
Set quote callback, after receiving the quote data push, it will call back to this handler.void
setOnTrades(TradesHandler handler)
Set trades callback, after receiving the trades data push, it will call backto this handler.CompletableFuture<Void>
subscribe(String[] symbols, int flags, boolean isFirstPush)
SubscribeCompletableFuture<Candlestick[]>
subscribeCandlesticks(String symbol, Period period)
Subscribe security candlesticksCompletableFuture<Void>
unsubscribe(String[] symbols, int flags)
UnsubscribeCompletableFuture<Void>
unsubscribeCandlesticks(String symbol, Period period)
Unsubscribe security candlesticksCompletableFuture<Long>
updateWatchlistGroup(UpdateWatchlistGroup req)
Update watchlist group
-
-
-
Method Detail
-
create
public static CompletableFuture<QuoteContext> create(Config config) throws OpenApiException
Create a QuoteContext object- Parameters:
config
- Config object- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
getMemberId
public long getMemberId()
Returns the member ID- Returns:
- Member ID
-
getQuoteLevel
public String getQuoteLevel()
Returns the quote level- Returns:
- Quote level
-
getQuotePackageDetails
public QuotePackageDetail[] getQuotePackageDetails()
Returns the quote package details- Returns:
- Quote package details
-
setOnQuote
public void setOnQuote(QuoteHandler handler)
Set quote callback, after receiving the quote data push, it will call back to this handler.- Parameters:
handler
- A quote handler
-
setOnDepth
public void setOnDepth(DepthHandler handler)
Set depth callback, after receiving the depth data push, it will call back to this handler.- Parameters:
handler
- A depth handler
-
setOnBrokers
public void setOnBrokers(BrokersHandler handler)
Set brokers callback, after receiving the brokers data push, it will call back to this handler.- Parameters:
handler
- A brokers handler
-
setOnTrades
public void setOnTrades(TradesHandler handler)
Set trades callback, after receiving the trades data push, it will call backto this handler.- Parameters:
handler
- A trades handler
-
setOnCandlestick
public void setOnCandlestick(CandlestickHandler handler)
Set candlestick callback, after receiving the trades data push, it will call back to this function.- Parameters:
handler
- A candlestick handler
-
subscribe
public CompletableFuture<Void> subscribe(String[] symbols, int flags, boolean isFirstPush) throws OpenApiException
Subscribeimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.setOnQuote((symbol, event) -> { System.out.printf("%s\t%s\n", symbol, event); }); ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Quote, true).get(); Thread.sleep(30000); } } }
- Parameters:
symbols
- Security symbolsflags
- Subscription flagsisFirstPush
- Whether to perform a data push immediately after subscribing.- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
unsubscribe
public CompletableFuture<Void> unsubscribe(String[] symbols, int flags) throws OpenApiException
Unsubscribeimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.setOnQuote((symbol, quote) -> { System.out.printf("%s\t%s\n", symbol, quote); }); ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Quote, true).get(); ctx.unsubscribe(new String[] { "AAPL.US" }, SubFlags.Quote).get(); } } }
- Parameters:
symbols
- Security symbolsflags
- Subscription flags- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
subscribeCandlesticks
public CompletableFuture<Candlestick[]> subscribeCandlesticks(String symbol, Period period) throws OpenApiException
Subscribe security candlesticksimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.setOnCandlestick((symbol, event) -> { System.out.printf("%s\t%s\n", symbol, event); }); ctx.subscribeCandlesticks("700.HK", Period.Min_1).get(); Thread.sleep(30000); } } }
- Parameters:
symbol
- Security symbolperiod
- Period type- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
unsubscribeCandlesticks
public CompletableFuture<Void> unsubscribeCandlesticks(String symbol, Period period) throws OpenApiException
Unsubscribe security candlesticks- Parameters:
symbol
- Security symbolperiod
- Period type- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getSubscrptions
public CompletableFuture<Subscription[]> getSubscrptions() throws OpenApiException
Get subscription informationimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Quote, true); Subscription[] subscriptions = ctx.getSubscrptions().get(); for (Subscription obj : subscriptions) { System.out.println(obj); } } } }
- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getStaticInfo
public CompletableFuture<SecurityStaticInfo[]> getStaticInfo(String[] symbols) throws OpenApiException
Get basic information of securitiesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { SecurityStaticInfo[] resp = ctx .getStaticInfo(new String[] { "700.HK", "AAPL.US", "TSLA.US", "NFLX.US" }) .get(); for (SecurityStaticInfo obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbols
- Security symbols- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getQuote
public CompletableFuture<SecurityQuote[]> getQuote(String[] symbols) throws OpenApiException
Get quote of securitiesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { SecurityQuote[] resp = ctx.getQuote(new String[] { "700.HK", "AAPL.US", "TSLA.US", "NFLX.US" }) .get(); for (SecurityQuote obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbols
- Security symbols- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getOptionQuote
public CompletableFuture<OptionQuote[]> getOptionQuote(String[] symbols) throws OpenApiException
Get quote of option securitiesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { OptionQuote[] resp = ctx.getOptionQuote(new String[] { "AAPL230317P160000.US" }).get(); for (OptionQuote obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbols
- Security symbols- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getWarrantQuote
public CompletableFuture<WarrantQuote[]> getWarrantQuote(String[] symbols) throws OpenApiException
Get quote of warrant securitiesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { WarrantQuote[] resp = ctx.getWarrantQuote(new String[] { "21125.HK" }).get(); for (WarrantQuote obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbols
- Security symbols- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getDepth
public CompletableFuture<SecurityDepth> getDepth(String symbol) throws OpenApiException
Get security depthimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { SecurityDepth resp = ctx.getDepth("700.HK").get(); System.out.println(resp); } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getBrokers
public CompletableFuture<SecurityBrokers> getBrokers(String symbol) throws OpenApiException
Get security brokersimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { SecurityBrokers resp = ctx.getBrokers("700.HK").get(); System.out.println(resp); } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getParticipants
public CompletableFuture<ParticipantInfo[]> getParticipants() throws OpenApiException
Get participantsimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ParticipantInfo[] resp = ctx.getParticipants().get(); for (ParticipantInfo obj : resp) { System.out.println(obj); } } } }
- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getTrades
public CompletableFuture<Trade[]> getTrades(String symbol, int count) throws OpenApiException
Get security tradesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { Trade[] resp = ctx.getTrades("700.HK", 10).get(); for (Trade obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbolcount
- Count of trades- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getIntraday
public CompletableFuture<IntradayLine[]> getIntraday(String symbol) throws OpenApiException
Get security intraday linesimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { IntradayLine[] resp = ctx.getIntraday("700.HK").get(); for (IntradayLine obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getCandlesticks
public CompletableFuture<Candlestick[]> getCandlesticks(String symbol, Period period, int count, AdjustType adjustType) throws OpenApiException
Get security candlesticksimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { Candlestick[] resp = ctx.getCandlesticks("700.HK", Period.Day, 10, AdjustType.NoAdjust).get(); for (Candlestick obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbolperiod
- Candlestick periodcount
- Count of candlesticksadjustType
- Adjustment type- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getOptionChainExpiryDateList
public CompletableFuture<LocalDate[]> getOptionChainExpiryDateList(String symbol) throws OpenApiException
Get option chain expiry date listimport com.longport.*; import com.longport.quote.*; import java.time.LocalDate; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { LocalDate[] resp = ctx.getOptionChainExpiryDateList("AAPL.US").get(); for (LocalDate obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getOptionChainInfoByDate
public CompletableFuture<StrikePriceInfo[]> getOptionChainInfoByDate(String symbol, LocalDate expiryDate) throws OpenApiException
Get option chain info by dateimport com.longport.*; import com.longport.quote.*; import java.time.LocalDate; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { StrikePriceInfo[] resp = ctx.getOptionChainInfoByDate("AAPL.US", LocalDate.of(2023, 1, 20)).get(); for (StrikePriceInfo obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbolexpiryDate
- Option expiry date- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getWarrantIssuers
public CompletableFuture<IssuerInfo[]> getWarrantIssuers() throws OpenApiException
Get warrant issuersimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { IssuerInfo[] resp = ctx.getWarrantIssuers().get(); for (IssuerInfo obj : resp) { System.out.println(obj); } } } }
- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
queryWarrantList
public CompletableFuture<WarrantInfo[]> queryWarrantList(QueryWarrantOptions opts) throws OpenApiException
Query warrant listimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { QueryWarrantOptions opts = new QueryWarrantOptions("700.HK", WarrantSortBy.LastDone, SortOrderType.Ascending); IssuerInfo[] resp = ctx.queryWarrantList(opts).get(); for (IssuerInfo obj : resp) { System.out.println(obj); } } } }
- Parameters:
opts
- Query options- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getTradingSession
public CompletableFuture<MarketTradingSession[]> getTradingSession() throws OpenApiException
Get trading session of the dayimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { MarketTradingSession[] resp = ctx.getTradingSession().get(); for (MarketTradingSession obj : resp) { System.out.println(obj); } } } }
- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getTradingDays
public CompletableFuture<MarketTradingDays> getTradingDays(Market market, LocalDate begin, LocalDate end) throws OpenApiException
Get market trading daysThe interval must be less than one month, and only the most recent year is supported.
import com.longport.*; import com.longport.quote.*; import java.time.LocalDate; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { MarketTradingDays resp = ctx .getTradingDays(Market.HK, LocalDate.of(2022, 1, 20), LocalDate.of(2022, 2, 20)).get(); System.out.println(resp); } } }
- Parameters:
market
- Marketbegin
- Begin dateend
- End date- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getCapitalFlow
public CompletableFuture<CapitalFlowLine[]> getCapitalFlow(String symbol) throws OpenApiException
Get capital flow intradayimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { CapitalFlowLine[] resp = ctx.getCapitalFlow("700.HK").get(); for (CapitalFlowLine obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security code- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getHistoryCandlesticksByOffset
public CompletableFuture<Candlestick[]> getHistoryCandlesticksByOffset(String symbol, Period period, AdjustType adjustType, boolean forward, LocalDateTime datetime, int count) throws OpenApiException
Get history candlesticks by offset- Parameters:
symbol
- Security symbolperiod
- Candlestick periodadjustType
- Adjustment typeforward
- Forward or backwarddatetime
- From datetimecount
- Count of candlesticks- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getHistoryCandlesticksByDate
public CompletableFuture<Candlestick[]> getHistoryCandlesticksByDate(String symbol, Period period, AdjustType adjustType, LocalDate start, LocalDate end) throws OpenApiException
Get history candlesticks by date- Parameters:
symbol
- Security symbolperiod
- Candlestick periodadjustType
- Adjustment typestart
- Start dateend
- End date- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getCalcIndexes
public CompletableFuture<SecurityCalcIndex[]> getCalcIndexes(String[] symbols, CalcIndex[] indexes) throws OpenApiException
Get security calc indexes- Parameters:
symbols
- Security symbolsindexes
- Calc indexes- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getWatchlist
public CompletableFuture<WatchlistGroup[]> getWatchlist() throws OpenApiException
Get watchlistimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { CapitalDistributionResponse resp = ctx.getWatchlist().get(); System.out.println(resp); } } }
- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
createWatchlistGroup
public CompletableFuture<Long> createWatchlistGroup(CreateWatchlistGroup req) throws OpenApiException
Create watchlist groupimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { CreateWatchlistGroup req = new CreateWatchlistGroup("Watchlist1") .setSecurities(new String[] { "700.HK", "AAPL.US" }); Long groupId = ctx.createWatchlistGroup(req).get(); System.out.println(groupId); } } }
- Parameters:
req
- Create watchlist group request- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
deleteWatchlistGroup
public CompletableFuture<Void> deleteWatchlistGroup(DeleteWatchlistGroup req) throws OpenApiException
Delete watchlist groupimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { DeleteWatchlistGroup req = new DeleteWatchlistGroup(10086); ctx.deleteWatchlistGroup(req).get(); } } }
- Parameters:
req
- Delete watchlist group request- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
updateWatchlistGroup
public CompletableFuture<Long> updateWatchlistGroup(UpdateWatchlistGroup req) throws OpenApiException
Update watchlist groupimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { CreateWatchlistGroup req = new UpdateWatchlistGroup(10086) .setName("watchlist2") .setSecurities(new String[] { "700.HK", "AAPL.US" }); ctx.updateWatchlistGroup(req).get(); } } }
- Parameters:
req
- Update watchlist group request- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
securityList
public CompletableFuture<Security[]> securityList(Market market, SecurityListCategory category) throws OpenApiException
Security listimport com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { Security[] resp = ctx.securityList(Market.US, SecurityListCategory.Overnight).get(); for (Security obj : resp) { System.out.println(obj); } } } }
- Parameters:
market
- Marketcategory
- Security list category- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getRealtimeQuote
public CompletableFuture<RealtimeQuote[]> getRealtimeQuote(String[] symbols) throws OpenApiException
Get real-time quotesGet real-time quotes of the subscribed symbols, it always returns the data in the local storage.
import com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Quote, true).get(); Thread.sleep(5000); RealtimeQuote[] resp = ctx.getRealtimeQuote(new String[] { "700.HK", "AAPL.US" }).get(); for (RealtimeQuote obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbols
- Security symbols- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getRealtimeDepth
public CompletableFuture<SecurityDepth> getRealtimeDepth(String symbol) throws OpenApiException
Get real-time depthGet real-time depth of the subscribed symbols, it always returns the data in the local storage.
import com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Depth, true).get(); Thread.sleep(5000); SecurityDepth resp = ctx.getRealtimeDepth("700.HK").get(); System.out.println(resp); } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getRealtimeBrokers
public CompletableFuture<SecurityBrokers> getRealtimeBrokers(String symbol) throws OpenApiException
Get real-time broker queueGet real-time broker queue of the subscribed symbols, it always returns the data in the local storage.
import com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Brokers, true).get(); Thread.sleep(5000); SecurityBrokers resp = ctx.getRealtimeBrokers("700.HK").get(); System.out.println(resp); } } }
- Parameters:
symbol
- Security symbol- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getRealtimeTrades
public CompletableFuture<Trade[]> getRealtimeTrades(String symbol, int count) throws OpenApiException
Get real-time tradesGet real-time trades of the subscribed symbols, it always returns the data in the local storage.
import com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribe(new String[] { "700.HK", "AAPL.US" }, SubFlags.Trade, false).get(); Thread.sleep(5000); Trade[] resp = ctx.getRealtimeTrades("700.HK", 10).get(); for (Trade obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbolcount
- Count of trades- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
getRealtimeCandlesticks
public CompletableFuture<Candlestick[]> getRealtimeCandlesticks(String symbol, Period period, int count) throws OpenApiException
Get real-time candlesticksGet real-time candlesticks of the subscribed symbols, it always returns the data in the local storage.
import com.longport.*; import com.longport.quote.*; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { ctx.subscribeCandlesticks("AAPL.US", Period.Min_1).get(); Thread.sleep(5000); Candlestick[] resp = ctx.getRealtimeCandlesticks("AAPL.US", Period.Min_1, 10).get(); for (Candlestick obj : resp) { System.out.println(obj); } } } }
- Parameters:
symbol
- Security symbolperiod
- Period typecount
- Count of trades- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException
- If an error occurs
-
-