# 指标异步计算结果推送

class IndicatorCalcHandlerBase(RspHandlerBase)

  • 介绍

    指标异步计算结果推送回调基类。当 request_indicator_calc_async 发起的计算任务完成后,服务端会通过该回调主动推送结果。用户继承 IndicatorCalcHandlerBase 并重写 on_recv_rsp 方法接收推送,通过 calc_id 与发起的请求配对。

  • 参数

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

    参数 类型 说明
    calc_id str 计算任务 ID,与 request_indicator_calc_async 返回的 calc_id 对应
    outputs list 输出线元数据,每项含 index、name
    output_rows list 计算结果,按时间顺序,每项含 time 与 values(与 outputs 一一对应)
  • Example

from futu import *

class IndicatorCalcHandler(IndicatorCalcHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, content = super(IndicatorCalcHandler, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print('IndicatorCalc error:', content)
            return RET_ERROR, content
        print('收到指标计算结果推送:')
        print('  calc_id:', content['calc_id'])
        print('  outputs:', content['outputs'])
        print('  rows:', len(content['output_rows']))
        return RET_OK, content

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
quote_ctx.set_handler(IndicatorCalcHandler())

# 通过 request_indicator_calc_async 发起计算后,结果会异步推送至上述 handler
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

说明