Class QuoteContext

    • Constructor Detail

      • QuoteContext

        public QuoteContext()
    • Method Detail

      • 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
        Subscribe
         
         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.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 symbols
        flags - Subscription flags
        isFirstPush - 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
        Unsubscribe
         
         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.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 symbols
        flags - 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 candlesticks
         
         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.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 symbol
        period - 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 symbol
        period - 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 information
         
         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);
                     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 securities
         
         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()) {
                     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 securities
         
         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()) {
                     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 securities
         
         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()) {
                     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 securities
         
         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()) {
                     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 depth
         
         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()) {
                     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 brokers
         
         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()) {
                     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 participants
         
         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()) {
                     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 trades
         
         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()) {
                     Trade[] resp = ctx.getTrades("700.HK", 10).get();
                     for (Trade obj : resp) {
                         System.out.println(obj);
                     }
                 }
             }
         }
         
         
        Parameters:
        symbol - Security symbol
        count - 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 lines
         
         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()) {
                     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 candlesticks
         
         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()) {
                     Candlestick[] resp = ctx.getCandlesticks("700.HK", Period.Day, 10, AdjustType.NoAdjust).get();
                     for (Candlestick obj : resp) {
                         System.out.println(obj);
                     }
                 }
             }
         }
         
         
        Parameters:
        symbol - Security symbol
        period - Candlestick period
        count - Count of candlesticks
        adjustType - 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 list
         
         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()) {
                     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 date
         
         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()) {
                     StrikePriceInfo[] resp = ctx.getOptionChainInfoByDate("AAPL.US", LocalDate.of(2023, 1, 20)).get();
                     for (StrikePriceInfo obj : resp) {
                         System.out.println(obj);
                     }
                 }
             }
         }
         
         
        Parameters:
        symbol - Security symbol
        expiryDate - 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 issuers
         
         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()) {
                     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 list
         
         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()) {
                     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 day
         
         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()) {
                     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 days

        The 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 - Market
        begin - Begin date
        end - 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 intraday
         
         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()) {
                     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 symbol
        period - Candlestick period
        adjustType - Adjustment type
        forward - Forward or backward
        datetime - From datetime
        count - Count of candlesticks
        Returns:
        A Future representing the result of the operation
        Throws:
        OpenApiException - If an error occurs
      • getWatchlist

        public CompletableFuture<WatchlistGroup[]> getWatchlist()
                                                         throws OpenApiException
        Get watchlist
         
         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()) {
                     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 group
         
         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()) {
                     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 group
         
         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()) {
                     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 group
         
         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()) {
                     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 list
         
         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()) {
                     Security[] resp = ctx.securityList(Market.US, SecurityListCategory.Overnight).get();
                     for (Security obj : resp) {
                         System.out.println(obj);
                     }
                 }
             }
         }
         
         
        Parameters:
        market - Market
        category - 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 quotes

        Get 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 depth

        Get 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 queue

        Get 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 trades

        Get 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 symbol
        count - 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 candlesticks

        Get 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 symbol
        period - Period type
        count - Count of trades
        Returns:
        A Future representing the result of the operation
        Throws:
        OpenApiException - If an error occurs