# 获取事件合约摆盘

get_event_contract_order_book(code, num=10)

  • 介绍

    获取单只事件合约的摆盘数据,包括 YES/NO 买盘和卖盘各档价量。

  • 参数

    参数 类型 说明
    code str 事件合约代码,如 'EC.KXODIMATCH-26JUL140600INDENG-IND'
    num int 请求的摆盘档数,默认 10,需大于 0
  • 返回

    参数 类型 说明
    ret RET_CODE 接口调用结果
    data dict 当 ret == RET_OK,返回摆盘数据,包含 code、yes_bids、yes_asks、no_bids、no_asks
    str 当 ret != RET_OK,返回错误描述

    返回的 dict 字段如下:

    字段 类型 说明
    code str 合约代码
    yes_bids list[tuple] YES 买盘,[(price, size), ...]
    yes_asks list[tuple] YES 卖盘,[(price, size), ...]
    no_bids list[tuple] NO 买盘,[(price, size), ...]
    no_asks list[tuple] NO 卖盘,[(price, size), ...]
  • Example

from moomoo import *

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

# 查询摆盘前需先订阅 ORDER_BOOK 类型(否则返回错误)
ret, err = quote_ctx.subscribe_event_contract(
    ['EC.KXODIMATCH-26JUL140600INDENG-IND'], [SubType.ORDER_BOOK]
)
if ret != RET_OK:
    print('订阅失败:', err)
else:
    ret, data = quote_ctx.get_event_contract_order_book(
        'EC.KXODIMATCH-26JUL140600INDENG-IND', num=5
    )
    if ret == RET_OK:
        print('合约:', data['code'])
        print('YES 买盘:', data['yes_bids'])
        print('YES 卖盘:', data['yes_asks'])
        print('NO 买盘:', data['no_bids'])
        print('NO 卖盘:', 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
合约: EC.KXODIMATCH-26JUL140600INDENG-IND
YES 买盘: [(0.5, 1030.0), (0.48, 0.01), (0.45, 5.0), (0.43, 1.0), (0.42, 175.0)]
YES 卖盘: [(0.51, 2633.6), (0.52, 15500.0), (0.53, 3000.0), (0.54, 1000.0), (0.55, 2124.0)]
NO 买盘: [(0.49, 2633.6), (0.48, 15500.0), (0.47, 3000.0), (0.46, 1000.0), (0.45, 2124.0)]
NO 卖盘: [(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