# Get Event Contract K-line

get_event_contract_kline(code, pre_side=None, ktype=KLType.K_DAY, kline_source=None, max_count=1000)

  • Description

    Get the real-time K-line of an event contract. It supports two sources: contract-level trade-price K-line and YES sub-contract order book K-line, and supports querying by direction (YES/NO) and K-line type. You must subscribe to the corresponding K-line type (e.g. SubType.K_DAY) before querying K-lines, otherwise an error is returned.

  • Parameters

    Parameter Type Description
    code str Event contract code, e.g. 'EC.KXODIMATCH-26JUL140600INDENG-IND'
    pre_side PredSide Contract direction
    ktype KLType K-line type, default KLType.K_DAY
    kline_source ECKlineSource K-line source
    max_count int Maximum number of records returned, default 1000
  • Return

    Parameter Type Description
    ret RET_CODE API call result
    data pd.DataFrame When ret == RET_OK, returns the K-line list
    str When ret != RET_OK, returns the error description

    The returned DataFrame fields are as follows:

    Field Type Description
    code str Contract code
    pre_side str Contract direction (YES/NO/N/A), see PredSide
    name str Contract name
    time_key str K-line time (yyyy-MM-dd HH:mm:ss)
    open float Open
    high float High
    low float Low
    close float Close
    volume float Volume
  • Example

from moomoo import *

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

# You must subscribe to the corresponding K-line type before querying K-lines (otherwise an error is returned)
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'], [SubType.K_DAY]
)
if ret != RET_OK:
    print('subscribe failed:', err)
else:
    # Contract-level trade-price K-line (YES direction)
    ret, data = quote_ctx.get_event_contract_kline(
        'EC.KXODIMATCH-26JUL140600INDENG-IND',
        pre_side=PredSide.YES, ktype=KLType.K_DAY, max_count=5
    )
    if ret == RET_OK:
        print(data)
    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
  • Output
                                  code pre_side                      name             time_key  open  high   low  close     volume
0  EC.KXODIMATCH-26JUL140600INDENG-IND      YES  England vs India Winner?  2026-07-11 00:00:00  0.30  0.38  0.30   0.35      433.0
1  EC.KXODIMATCH-26JUL140600INDENG-IND      YES  England vs India Winner?  2026-07-12 00:00:00  0.64  0.73  0.35   0.52    10482.0
2  EC.KXODIMATCH-26JUL140600INDENG-IND      YES  England vs India Winner?  2026-07-13 00:00:00  0.51  0.52  0.46   0.49   193327.0
3  EC.KXODIMATCH-26JUL140600INDENG-IND      YES  England vs India Winner?  2026-07-14 00:00:00  0.49  0.99  0.37   0.99  3860182.0
1
2
3
4
5