# 異步發起指標計算

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

  • 介紹

    異步發起指標計算。接口立即返回 calc_id,實際計算結果由 指標異步計算結果推送 異步推送。

  • 參數

    參數 類型 說明
    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,返回計算任務 ID(calc_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(
        'MACD', IndicatorLangType.MYLANG, 'HK.00700', KLType.K_DAY, kl_data)
    if ret == RET_OK:
        print('calcId:', 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
  • Output
calcId: 1234567890abcdef
1