# Request Historical K-line of Event Contract

request_history_event_contract_kline(code, start=None, end=None, pre_side=None, ktype=KLType.K_DAY, kline_source=None, max_count=1000, page_req_key=None)

  • Description

    Pull the historical K-line of an event contract without downloading historical data first. Supports querying by time range, direction and K-line source, and handles pagination automatically (loops to pull when max_count exceeds the single-package limit).

  • Parameters

    Parameter Type Description
    code str Required. Event contract code, e.g. 'EC.KXNFLAFCCHAMP-27-CIN'
    start str Optional. Start time, e.g. '2026-07-05'
    end str Optional. End time, e.g. '2026-07-09'
    pre_side PredSide Optional. Contract direction
    ktype KLType Optional. K-line type, only K_1M/K_5M/K_60M/K_DAY supported, default K_DAY
    kline_source ECKlineSource Optional. K-line source
    max_count int Optional. Max number of data points returned in this request, None means all within the range
    page_req_key str Optional. Pagination key, pass None for the first request and the previous return value for subsequent requests
  • Return

    Parameter Type Description
    ret RET_CODE API call result
    data pd.DataFrame When ret == RET_OK, returns the historical K-line data
    str When ret != RET_OK, returns the error description
    page_req_key str Pagination key, None when there is no more data

    The DataFrame fields are as follows:

    Field Type Description
    code str Contract code
    pre_side str Contract direction (YES/NO/N/A)
    name str Contract name
    time_key str K-line time
    open float Open price
    high float High price
    low float Low price
    close float Close price
    volume float Volume
  • Example

from moomoo import *

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

# Subscribe the corresponding K-line type before pulling the historical K-line
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXNFLAFCCHAMP-27-CIN'], [SubType.K_DAY]
)
if ret != RET_OK:
    print('subscribe failed:', err)
else:
    ret, data, page_req_key = quote_ctx.request_history_event_contract_kline(
        'EC.KXNFLAFCCHAMP-27-CIN',
        start='2026-07-05', end='2026-07-09',
        pre_side=PredSide.YES, ktype=KLType.K_DAY, max_count=10
    )
    if ret == RET_OK:
        print(data)
        print('page_req_key:', page_req_key)
    else:
        print('error:', data)

quote_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • Output
                      code pre_side                                                    name             time_key  open  high   low  close  volume
0  EC.KXNFLAFCCHAMP-27-CIN      YES  Will Cincinnati win the Pro Football AFC Championship?  2026-07-05 00:00:00  0.92  0.92  0.92  0.92  201.0
1  EC.KXNFLAFCCHAMP-27-CIN      YES  Will Cincinnati win the Pro Football AFC Championship?  2026-07-06 00:00:00  0.93  0.93  0.92  0.92  659.0
2  EC.KXNFLAFCCHAMP-27-CIN      YES  Will Cincinnati win the Pro Football AFC Championship?  2026-07-07 00:00:00  0.93  0.93  0.92  0.92  490.0
3  EC.KXNFLAFCCHAMP-27-CIN      YES  Will Cincinnati win the Pro Football AFC Championship?  2026-07-08 00:00:00  0.93  0.93  0.92  0.92  669.0
4  EC.KXNFLAFCCHAMP-27-CIN      YES  Will Cincinnati win the Pro Football AFC Championship?  2026-07-09 00:00:00  0.92  0.92  0.92  0.92  343.0
page_req_key: None
1
2
3
4
5
6
7

Interface Limitations

  • Up to 60 requests for pulling the historical K-line of event contracts every 30 seconds