# Get Event Contract Order Book

get_event_contract_order_book(code, num=10)

  • Description

    Get the order book of a single event contract, including YES/NO bid and ask levels.

  • Parameters

    Parameter Type Description
    code str Event contract code, e.g. 'EC.KXODIMATCH-26JUL140600INDENG-IND'
    num int Requested order book depth, default 10, must be greater than 0
  • Return

    Parameter Type Description
    ret RET_CODE API call result
    data dict When ret == RET_OK, returns order book data, containing code, yes_bids, yes_asks, no_bids, no_asks
    str When ret != RET_OK, returns error description

    The fields of the returned dict are as follows:

    Field Type Description
    code str Contract code
    yes_bids list[tuple] YES bids, [(price, size), ...]
    yes_asks list[tuple] YES asks, [(price, size), ...]
    no_bids list[tuple] NO bids, [(price, size), ...]
    no_asks list[tuple] NO asks, [(price, size), ...]
  • Example

from moomoo import *

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

# Before querying the order book, you must first subscribe to ORDER_BOOK (otherwise an error is returned)
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'], [SubType.ORDER_BOOK]
)
if ret != RET_OK:
    print('subscription failed:', err)
else:
    ret, data = quote_ctx.get_event_contract_order_book(
        'EC.KXODIMATCH-26JUL140600INDENG-IND', num=5
    )
    if ret == RET_OK:
        print('contract:', data['code'])
        print('YES bids:', data['yes_bids'])
        print('YES asks:', data['yes_asks'])
        print('NO bids:', data['no_bids'])
        print('NO asks:', data['no_asks'])
    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
24
  • Output
contract: EC.KXODIMATCH-26JUL140600INDENG-IND
YES bids: [(0.5, 1030.0), (0.48, 0.01), (0.45, 5.0), (0.43, 1.0), (0.42, 175.0)]
YES asks: [(0.51, 2633.6), (0.52, 15500.0), (0.53, 3000.0), (0.54, 1000.0), (0.55, 2124.0)]
NO bids: [(0.49, 2633.6), (0.48, 15500.0), (0.47, 3000.0), (0.46, 1000.0), (0.45, 2124.0)]
NO asks: [(0.5, 1030.0), (0.52, 0.01), (0.55, 5.0), (0.57, 1.0), (0.58, 175.0)]
1
2
3
4
5