# 异步发起指标计算

request_indicator_calc_async(short_name, lang_type, code, kl_type, klines, num=None, input_params=None)

  • 介绍

    异步发起指标计算。接口先返回 calc_id,实际计算结果由 push-indicator-calc 推送,通过 calc_id 配对。需先注册 IndicatorCalcHandlerBase 子类接收推送。

  • 参数

    参数 类型 说明
    short_name str 指标短名
    lang_type IndicatorLangType 脚本语言类型
    code str 股票代码,如 HK.00700
    kl_type KLType K 线类型
    klines pd.DataFrame 或 list[dict] K 线数据,可由 request_history_kline / get_cur_kline 返回
    num int 或 None 最多取前 N 条 K 线参与计算
    input_params list[dict] 或 None 入参覆盖列表
  • 返回

    参数 类型 说明
    ret RET_CODE 接口调用结果
    data str 当 ret == RET_OK,返回 calc_id(计算任务 ID,与推送结果配对)
    str 当 ret != RET_OK,返回错误描述
  • Example

from futu import *
import time

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

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('error:', content)
            return ret_code, content
        print('calc result:', content)
        return RET_OK, content

quote_ctx.set_handler(IndicatorCalcHandler())

ret, kl_data, _ = quote_ctx.request_history_kline('HK.00700', start='2024-01-01', end='2024-03-01', ktype=KLType.K_DAY)
if ret == RET_OK:
    ret, calc_id = quote_ctx.request_indicator_calc_async(
        'MA', IndicatorLangType.MYLANG, 'HK.00700', KLType.K_DAY, kl_data)
    if ret == RET_OK:
        print('calc_id:', calc_id)
    else:
        print('error:', calc_id)

time.sleep(5)
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

接口限制

  • 每 30 秒内最多发起 10 次指标计算请求。
  • 实际计算结果通过 Qot_PushIndicatorCalc(3261) 异步推送,需提前注册推送回调。