# 指标异步计算结果推送

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
    outputs list 输出线元数据
    output_rows list 计算结果,按时间顺序
  • Example

from moomoo 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'])
        return RET_OK, content

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

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

说明