LongPort OpenAPI SDK
LongPort OpenAPI SDK
QuoteContext
Quote context
Parameters:
brokers(symbol)
Get security brokers
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.brokers("700.HK")
print(resp)
calc_indexes(symbols, indexes)
Get calc indexes
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
Parameters:
Returns:
Type Description
List[Candlestick] Candlesticks
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.candlesticks(
"700.HK", Period.Day, 10, AdjustType.NoAdjust)
print(resp)
capital_distribution(symbol)
Get capital distribution
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.capital_distribution("700.HK")
print(resp)
capital_flow(symbol)
Get capital flow intraday
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.capital_flow("700.HK")
print(resp)
create_watchlist_group(name,
securities=None)
Create watchlist group
Parameters:
Returns:
Type Description
int Group ID
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
group_id = ctx.create_watchlist_group(name = "Watchlist1", securities = ["700
print(group_id)
delete_watchlist_group(id,
purge=False)
Delete watchlist group
Parameters:
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.delete_watchlist_group(10086)
depth(symbol)
Get security depth
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.depth("700.HK")
print(resp)
history_candlesticks_by_date(symbol,
period, adjust_type, start, end)
Get security history candlesticks by date
Parameters:
history_candlesticks_by_offset(symbol
, period, adjust_type, forward, time,
count)
Get security history candlesticks by offset
Parameters:
intraday(symbol)
Get security intraday lines
Parameters:
Name Type Description Default
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.intraday("700.HK")
print(resp)
member_id()
Returns the member ID
option_chain_expiry_date_list(symbol
)
Get option chain expiry date list
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.option_chain_expiry_date_list("AAPL.US")
print(resp)
option_chain_info_by_date(symbol,
expiry_date)
Get option chain info by date
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.option_chain_info_by_date(
"AAPL.US", date(2023, 1, 20))
print(resp)
option_quote(symbols)
Get quote of option securities
Parameters:
Returns:
Type Description
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.option_quote(["AAPL230317P160000.US"])
print(resp)
participants()
Get participants
Returns:
Type Description
List[ParticipantInfo] Participants
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.participants()
print(resp)
quote(symbols)
Get quote of securities
Parameters:
Returns:
Type Description
Examples:
::
from longport.openapi import QuoteContext, Config
config = Config.from_env()
ctx = QuoteContext(config)
quote_level()
Returns the quote level
quote_package_details()
Returns the quote package details
realtime_brokers(symbol)
Get real-time brokers
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.subscribe(["700.HK", "AAPL.US"], [
SubType.Brokers], is_first_push = True)
sleep(5)
resp = ctx.realtime_brokers("700.HK")
print(resp)
realtime_candlesticks(symbol, period,
count)
Get real-time candlesticks
Get Get real-time candlesticks of the subscribed symbols, it always
returns the data in the local storage.
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.subscribe_candlesticks("AAPL.US", Period.Min_1)
sleep(5)
resp = ctx.realtime_candlesticks("AAPL.US", Period.Min_1, 10)
print(resp)
realtime_depth(symbol)
Get real-time depth
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.subscribe(["700.HK", "AAPL.US"], [
SubType.Depth], is_first_push = True)
sleep(5)
resp = ctx.realtime_depth("700.HK")
print(resp)
realtime_quote(symbols)
Get real-time quote
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.subscribe(["700.HK", "AAPL.US"], [
SubType.Quote], is_first_push = True)
sleep(5)
resp = ctx.realtime_quote(["700.HK", "AAPL.US"])
print(resp)
realtime_trades(symbol, count)
Get real-time trades
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.subscribe(["700.HK", "AAPL.US"], [
SubType.Trade], is_first_push = False)
sleep(5)
resp = ctx.realtime_trades("700.HK", 10)
print(resp)
security_list(market, category)
Get security list
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
set_on_brokers(callback)
Set brokers callback, after receiving the brokers data push, it will
call back to this function.
set_on_candlestick(callback)
Set candlestick callback, after receiving the candlestick updated
event, it will call back to this function.
set_on_depth(callback)
Set depth callback, after receiving the depth data push, it will call
back to this function.
set_on_quote(callback)
Set quote callback, after receiving the quote data push, it will call
back to this function.
set_on_trades(callback)
Set trades callback, after receiving the trades data push, it will call
back to this function.
static_info(symbols)
Get basic information of securities
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.static_info(
["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
print(resp)
subscribe(symbols, sub_types,
is_first_push=False)
Subscribe
Parameters:
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.set_on_quote(on_quote)
ctx.subscribe(["700.HK", "AAPL.US"], [
SubType.Quote], is_first_push = True)
sleep(30)
subscribe_candlesticks(symbol,
period)
Subscribe security candlesticks
Parameters:
Examples:
::
ctx.set_on_candlestick(on_candlestick)
ctx.subscribe_candlesticks("700.HK", Period.Min_1)
sleep(30)
subscriptions()
Get subscription information
Examples:
::
trades(symbol, count)
Get security trades
Parameters:
Name Type Description Default
Returns:
Type Description
List[Trade] Trades
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
The interval must be less than one month, and only the most
recent year is supported.
Parameters:
Returns:
Type Description
Examples:
::
from datetime import date
from longport.openapi import QuoteContext, Config, Market
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.trading_days(
Market.HK, date(2022, 1, 1), date(2022, 2, 1))
print(resp)
trading_session()
Get trading session of the day
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.trading_session()
print(resp)
unsubscribe(symbols, sub_types)
Unsubscribe
Parameters:
Examples:
::
Parameters:
update_watchlist_group(id, name=None,
securities=None, mode=None)
Update watchlist group
Parameters:
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
ctx.update_watchlist_group(10086, name = "Watchlist2", securities = ["700.HK
warrant_issuers()
Get warrant issuers
Returns:
Type Description
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.warrant_issuers()
print(resp)
warrant_list(symbol, sort_by,
sort_order, warrant_type=None,
issuer=None, expiry_date=None,
price_type=None, status=None)
Get warrant list
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
warrant_quote(symbols)
Get quote of warrant securities
Parameters:
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.warrant_quote(["21125.HK"])
print(resp)
watchlist()
Get watch list
Returns:
Type Description
Examples:
::
config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.watchlist()
print(resp)