The maximum number of candlesticks returned in this request.
Sending None indicates that all data between start and end is returned.
Note: FutuOpenD requests all the data and then sends it to the script. If the number of candlesticks you want to obtain is more than 1000, it is recommended to select paging to prevent from timeout.
page_req_key
bytes
The key of the page request. If the number of candlesticks between start and end is more than max_count, then None should be passed at the first time you call this interface, and the page_req_key returned by the last call must be passed in the subsequent pagerequests.
extended_time
bool
Need pre-market and after-hours data for US stocks or not. False: not need, True: need.
The combination of start and end is as follows
Start type
End type
Description
str
str
start and end are the specified dates respectively.
None
str
start is 365 days before end.
str
None
end is 365 days after start.
None
None
end is the current date, start is 365 days before.
If ret == RET_OK, historical candlestick data is returned.
str
If ret != RET_OK, error description is returned.
page_req_key
bytes
The key of the next page request.
Historical candlestick data format as follows:
Field
Type
Description
code
str
Stock code.
time_key
str
Candlestick time.
Format: yyyy-MM-dd HH:mm:ss The default of HK stock market and A-share market is Beijing time, while that of US stock market is US Eastern time.
open
float
Open.
close
float
Close.
high
float
High.
low
float
Low.
pe_ratio
float
P/E ratio.
This field is a ratio field, and % is not displayed.
turnover_rate
float
Turnover rate.
volume
int
Volume.
turnover
float
Turnover.
change_rate
float
Change rate.
last_close
float
Yesterday's close.
Example
from futu import*
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data, page_req_key = quote_ctx.request_history_kline('HK.00700', start='2019-09-11', end='2019-09-18', max_count=5)# 5 per page, request the first pageif ret == RET_OK:print(data)print(data['code'][0])# Take the first stock codeprint(data['close'].values.tolist())# The closing price of the first page is converted to a listelse:print('error:', data)while page_req_key !=None:# Request all results afterprint('*************************************')
ret, data, page_req_key = quote_ctx.request_history_kline('HK.00700', start='2019-09-11', end='2019-09-18', max_count=5,page_req_key=page_req_key)# Request the page after turning dataif ret == RET_OK:print(data)else:print('error:', data)print('All pages are finished!')
quote_ctx.close()# After using the connection, remember to close it to prevent the number of connections from running out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Output
code time_key open close high low pe_ratio turnover_rate volume turnover change_rate last_close
0 HK.007002019-09-1100:00:00341.0346.0347.8339.436.4050.00165157949035.437023e+091.466276340.2......................................4 HK.007002019-09-1700:00:00343.2343.6345.4340.636.1530.0009792256873.165508e+09-0.865551346.6[5 rows x 12 columns]
HK.00700[346.0,349.4,349.6,346.6,343.6]*************************************
code time_key open close high low pe_ratio turnover_rate volume turnover change_rate last_close
0 HK.007002019-09-1800:00:00344.0343.0345.6341.636.090.0007773354072.516701e+09-0.290698343.6
All pages are finished!
messageC2S{requiredint32 rehabType =1;//Qot_Common.RehabType, rehabilitation typerequiredint32 klType =2;//Qot_Common.KLType, timeframe of candlestickrequiredQot_Common.Security security =3;//Security coderequiredstring beginTime =4;//Start time string (Format: yyyy-MM-dd)requiredstring endTime =5;//End time string (Format: yyyy-MM-dd)optionalint32 maxAckKLNum =6;//How many candlesticks can be returned at most, if not specified, it means no limitoptionalint64 needKLFieldsFlag =7;//Specific fields of candlestick structure to return. A combination of KLFields enumeratio. If not specified, return all fieldsoptionalbytes nextReqKey =8;//Paging request keyoptionalbool extendedTime =9;//Whether to get the pre-market and after-hours data of US stocks, currently only supports timeframe of 1-minute.}messageRequest{requiredC2S c2s =1;}
messageC2S{requiredint32 rehabType =1;//Qot_Common.RehabType, rehabilitation typerequiredint32 klType =2;//Qot_Common.KLType, timeframe of candlestickrequiredQot_Common.Security security =3;//Security coderequiredstring beginTime =4;//Start time string (Format: yyyy-MM-dd)requiredstring endTime =5;//End time string (Format: yyyy-MM-dd)optionalint32 maxAckKLNum =6;//How many candlesticks can be returned at most, if not specified, it means no limitoptionalint64 needKLFieldsFlag =7;//Specific fields of candlestick structure to return. A combination of KLFields enumeratio. If not specified, return all fieldsoptionalbytes nextReqKey =8;//Paging request keyoptionalbool extendedTime =9;//Whether to get the pre-market and after-hours data of US stocks, currently only supports timeframe of 1-minute.}messageRequest{requiredC2S c2s =1;}
int requestHistoryKL(QotRequestHistoryKL.Request req); void onReply_RequestHistoryKL(FTAPI_Conn client, int nSerialNo, QotRequestHistoryKL.Response rsp);
Introduction
Get historical candlesticks
Parameters
messageC2S{requiredint32 rehabType =1;//Qot_Common.RehabType, rehabilitation typerequiredint32 klType =2;//Qot_Common.KLType, timeframe of candlestickrequiredQot_Common.Security security =3;//Security coderequiredstring beginTime =4;//Start time string (Format: yyyy-MM-dd)requiredstring endTime =5;//End time string (Format: yyyy-MM-dd)optionalint32 maxAckKLNum =6;//How many candlesticks can be returned at most, if not specified, it means no limitoptionalint64 needKLFieldsFlag =7;//Specific fields of candlestick structure to return. A combination of KLFields enumeratio. If not specified, return all fieldsoptionalbytes nextReqKey =8;//Paging request keyoptionalbool extendedTime =9;//Whether to get the pre-market and after-hours data of US stocks, currently only supports timeframe of 1-minute.}messageRequest{requiredC2S c2s =1;}
messageC2S{requiredint32 rehabType =1;//Qot_Common.RehabType, rehabilitation typerequiredint32 klType =2;//Qot_Common.KLType, timeframe of candlestickrequiredQot_Common.Security security =3;//Security coderequiredstring beginTime =4;//Start time string (Format: yyyy-MM-dd)requiredstring endTime =5;//End time string (Format: yyyy-MM-dd)optionalint32 maxAckKLNum =6;//How many candlesticks can be returned at most, if not specified, it means no limitoptionalint64 needKLFieldsFlag =7;//Specific fields of candlestick structure to return. A combination of KLFields enumeratio. If not specified, return all fieldsoptionalbytes nextReqKey =8;//Paging request keyoptionalbool extendedTime =9;//Whether to get the pre-market and after-hours data of US stocks, currently only supports timeframe of 1-minute.}messageRequest{requiredC2S c2s =1;}
messageC2S{requiredint32 rehabType =1;//Qot_Common.RehabType, rehabilitation typerequiredint32 klType =2;//Qot_Common.KLType, timeframe of candlestickrequiredQot_Common.Security security =3;//Security coderequiredstring beginTime =4;//Start time string (Format: yyyy-MM-dd)requiredstring endTime =5;//End time string (Format: yyyy-MM-dd)optionalint32 maxAckKLNum =6;//How many candlesticks can be returned at most, if not specified, it means no limitoptionalint64 needKLFieldsFlag =7;//Specific fields of candlestick structure to return. A combination of KLFields enumeratio. If not specified, return all fieldsoptionalbytes nextReqKey =8;//Paging request keyoptionalbool extendedTime =9;//Whether to get the pre-market and after-hours data of US stocks, currently only supports timeframe of 1-minute.}messageRequest{requiredC2S c2s =1;}
Candlestick data with timeframes of 60 minutes and below, is only supported for the last 2 years. Data with timeframes of daily and above, is supported for the last 10 years.
We will issue historical candlestick quota based on your account assets and transaction conditions. Therefore, you can only obtain historical candlestick data for a limited number of stocks within 30 days. For specific rules, please refer to Subscription Quota & Historical Candlestick Quota. The historical candlestick quota you consume on that day will be automatically released after 30 days.
A maximum of 10 requests per 30 seconds. Note: If you obtain data by page, this frequency limit rule is only applicable to the first time calling the interface, and subsequent pages request frequency is unlimited.
Change rate, only supports timeframes of daily and above.
The pre-market and after-hours candlestick of US stocks, only supports timeframes of 60 minutes and below. Since the pre-market and after-hours of the US stock market are irregular trading hours, the candlestick data for this period may be less than 2 years.
Turnover of US stocks, only supports data after 2015-10-12.