# 期权异动推送

class OptionEventHandlerBase(RspHandlerBase)

  • 介绍

    接收期权异动推送,当设置的异动提醒被触发时,服务端会主动推送异动信息。需先通过 set_option_event_alert 设置提醒条件,并通过 handler 注册回调。用户继承 OptionEventHandlerBase 并重写 on_recv_rsp 方法来接收推送。

  • 参数

    on_recv_rsp 回调返回 (ret_code, content),content 为 dict:

    参数 类型 说明
    owner_code str 标的代码(如 'US.TSLA')
    option_code str 期权合约代码(如 'US.TSLA250620C250')
    message str 推送消息文本
  • Example

from futu import *

class OptionEventHandler(OptionEventHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, content = super(OptionEventHandler, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("OptionEvent error:", content)
            return RET_ERROR, content

        print("收到期权异动推送:")
        print("  标的:", content['owner_code'])
        print("  期权:", content['option_code'])
        print("  消息:", content['message'])
        return RET_OK, content

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

# 注册期权异动推送处理器
quote_ctx.set_handler(OptionEventHandler())

# 需要先通过 set_option_event_alert 设置提醒条件,推送才会触发
item = OptionEventAlertItem(
    option_market=OptionMarket.US_SECURITY,
    option_type=OptionType.CALL,
    order_type_list=[AlertOrderType.SWEEP],
    size_range_min=100,
)
ret, data = quote_ctx.set_option_event_alert(AlertOpType.ADD, item)
if ret == RET_OK:
    print('提醒设置成功,等待推送...')
else:
    print('设置失败:', data)

import time
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass

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
30
31
32
33
34
35
36
37
38
39
40
41
  • Output
收到期权异动推送:
  标的: US.TSLA
  期权: US.TSLA250620C250
  消息: TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50
1
2
3
4