# 獲取事件合約擺盤

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