# Get Real-time Candlestick

get_cur_kline(code, num, ktype=SubType.K_DAY, autype=AuType.QFQ)

  • Description

    Get real-time candlestick data of subscribed stocks, you must subscribe first.

  • Parameters

    Parameter Type Description
    code str Stock code.
    num int The number of candlesticks.
    ktype KLType Candlestick type.
    autype AuType Type of adjustment.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, IPO data is returned.
    str If ret != RET_OK, error description is returned.
    • IPO data format as follows:
      Field Type Description
      code str Stock code.
      name str Stock name.
      time_key str Time.
      open float Open.
      close float Close.
      high float High.
      low float Low.
      volume int Volume.
      turnover float Turnover.
      pe_ratio float P/E ratio.
      turnover_rate float Turnover rate.
      last_close float Yesterday's close.
  • Example

from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

ret_sub, err_message = quote_ctx.subscribe(['HK.00700'], [SubType.K_DAY], subscribe_push=False)
# First subscribe to the candlestick type. After the subscription is successful, OpenD will continue to receive pushes from the server, False means that there is no need to push to the script temporarily
if ret_sub == RET_OK:  # Successfully subscribed
    ret, data = quote_ctx.get_cur_kline('HK.00700', 2, SubType.K_DAY, AuType.QFQ)  # Get the latest 2 candlestick data of HK.00700
    if ret == RET_OK:
        print(data)
        print(data['turnover_rate'][0])   # Take the first turnover rate
        print(data['turnover_rate'].values.tolist())   # Convert to list
    else:
        print('error:', data)
else:
    print('subscription failed', err_message)
quote_ctx.close()  # Close the current link, OpenD will automatically cancel the corresponding type of subscription for the corresponding stock after 1 minute
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • Output
    code     name             time_key   open  close   high    low    volume      turnover  pe_ratio  turnover_rate  last_close
0  HK.00700  TENCENT  2023-07-18 00:00:00  351.8  336.4  351.8  335.0  29147987  9.911757e+09    15.283        0.00304       352.6
1  HK.00700  TENCENT  2023-07-19 00:00:00  330.6  333.0  333.8  327.0  21913296  7.240461e+09    15.128        0.00229       336.4
0.00304
[0.00304, 0.00229]
1
2
3
4
5

Interface Limitations

  • This interface is to obtain real-time candlestick, which can obtain the nearest 1000 at most. To get historical candlestick, please refer to Get historical candlestick.
  • Only a stock of daily timeframe and above have P/E ratio and turnover ratio fields.
  • Options related candlestick data, only supports 1 day, 1 minute, 5 minutes, 15 minutes and 60 minutes.

Tips