# Unsubscribe Event Contract

unsubscribe_event_contract(code_list, subtype_list, kline_source_list=None)

  • Description

    Unsubscribe from real-time event contract market data pushes. Supports precise unsubscription by contract code, subscription type, and K-line source.

  • Parameters

    Parameter Type Description
    code_list list Event contract code list, e.g. ['EC.KXODIMATCH-26JUL140600INDENG-IND']
    subtype_list SubType Subscription type list
    kline_source_list ECKlineSource K-line source list
  • Return

    Parameter Type Description
    ret RET_CODE Interface call result
    err_message None When ret == RET_OK, returns None
    str When ret != RET_OK, returns the error description
  • Example

from moomoo import *
import time

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

# Subscribe: Day K + Ticker
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    [SubType.K_DAY, SubType.TICKER]
)
if ret != RET_OK:
    print('Subscribe failed:', err)
    quote_ctx.close()
    exit()

# You can only unsubscribe at least 1 minute after subscribing
time.sleep(62)

# Precisely unsubscribe: unsubscribe only ticker
ret, err = quote_ctx.unsubscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'],
    [SubType.TICKER]
)
if ret == RET_OK:
    print('Unsubscribe succeeded')
else:
    print('Unsubscribe failed:', err)

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
24
25
26
27
28
29
  • Output
Unsubscribe succeeded
1