# Asynchronously Request Indicator Calculation

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

  • Description

    Asynchronously request indicator calculation. The API returns a calc_id immediately; the actual calculation result is delivered asynchronously through the push-indicator-calc callback, paired by calc_id.

  • Parameters

    Parameter Type Description
    short_name str Indicator short name
    lang_type IndicatorLangType Script language type
    code str Stock code, e.g. HK.00700
    kl_type KLType K-line type
    klines pd.DataFrame or list[dict] K-line data from request_history_kline / get_cur_kline
    num int or None Use at most the first N K-lines; None means all K-lines
    input_params list[dict] or None Input overrides as {"index": int, "value": str}; empty uses defaults
  • Return

    Parameter Type Description
    ret RET_CODE API call result
    data str When ret == RET_OK, returns the `calc_id` of the calculation task, used to pair with push results
    str When ret != RET_OK, returns error description
  • 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('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