# Option Event Push

class OptionEventHandlerBase(RspHandlerBase)

  • Description

    Receive option event push notifications. When a configured event alert is triggered, the server will actively push the event information. You need to first set alert conditions via set_option_event_alert and register a callback via handler. Users inherit OptionEventHandlerBase and override on_recv_rsp to receive push notifications.

  • Parameters

    on_recv_rsp callback returns (ret_code, content), where content is a dict:

    Parameter Type Description
    owner_code str Underlying code (e.g. 'US.TSLA')
    option_code str Option contract code (e.g. 'US.TSLA250620C250')
    message str Push message text
  • 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("Received option event push:")
        print("  Underlying:", content['owner_code'])
        print("  Option:", content['option_code'])
        print("  Message:", content['message'])
        return RET_OK, content

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

# Register option event push handler
quote_ctx.set_handler(OptionEventHandler())

# Must first set alert conditions via set_option_event_alert before pushes are triggered
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('Alert set successfully, waiting for push...')
else:
    print('Failed to set alert:', 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
Received option event push:
  Underlying: US.TSLA
  Option: US.TSLA250620C250
  Message: TSLA $250 Call 06/20 Large sweep 500 contracts at $12.50
1
2
3
4