# Get Real-time Time Frame Data

get_rt_data(code)

  • Description

    Obtain real-time tick-by-tick data for a specified stock. (Require real-time data subscription.)

  • Parameters

    Parameter Type Description
    code str Stock code.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, Time Frame data is returned.
    str If ret != RET_OK, error description is returned.
    • Time Frame data format as follows:
      Field Type Description
      code str Stock code.
      name str Stock name.
      time str Time.
      is_blank bool Data status.
      opened_mins int How many minutes have passed from 0 o'clock.
      cur_price float Current price.
      last_close float Yesterday's close.
      avg_price float Average price.
      volume float Volume.
      turnover float Transaction amount.
  • Example

from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret_sub, err_message = quote_ctx.subscribe(['HK.00700'], [SubType.RT_DATA], subscribe_push=False)
# Subscribe to the Time Frame data type first. 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_rt_data('HK.00700')   # Get Time Frame data once
    if ret == RET_OK:
        print(data)
    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
  • Output
         code  name                 time  is_blank  opened_mins  cur_price  last_close   avg_price   volume     turnover
0    HK.00700  Tencent  2023-07-19 09:30:00     False          570      330.6       336.4  330.639590   380900  125940620.0
..        ...   ...                  ...       ...          ...        ...         ...         ...      ...          ...
330  HK.00700  Tencent  2023-07-19 16:00:00     False          960      333.0       336.4  330.400642  1766300  588143620.0

[331 rows x 10 columns]
1
2
3
4
5
6

Tips