# Subscribe Event Contract

subscribe_event_contract(code_list, subtype_list, kline_source_list=None, is_first_push=True, subscribe_push=True)

  • Description

    Subscribe to real-time market data push for event contracts. After a successful subscription, order book, K-line, and ticker data are returned in real time via push callbacks. You must register a handler of the corresponding type via set_handler before receiving push data.

  • Parameters

    Parameter Type Description
    code_list list List of event contract codes, e.g. ['EC.KXODIMATCH-26JUL140600INDENG-IND']
    subtype_list SubType List of subscription types
    kline_source_list ECKlineSource Optional, list of K-line sources. Effective when subscribing to K-line types, defaults to None which means contract-level trade-price K-line
    is_first_push bool Whether to push existing data once right after subscription, defaults to True
    subscribe_push bool Whether to register for push, defaults to True
  • Return

    Parameter Type Description
    ret RET_CODE API call result
    err_message str When ret == RET_OK, returns None; when ret != RET_OK, returns an error description
  • Example

from moomoo import *

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

# Subscribe: Day K + Ticker + Order Book
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    [SubType.K_DAY, SubType.TICKER, SubType.ORDER_BOOK]
)
if ret == RET_OK:
    print('subscribe success')
else:
    print('subscribe failed:', err)

# To receive push, register handlers via set_handler and keep the connection running
quote_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • Output
subscribe success
1

On success err is None. After a successful subscription, the corresponding K-line/ticker/order book pushes will trigger the registered handler callbacks (see the output examples in the push documentation).