# 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
    num int or None Use at most the first N K-lines; None means all K-lines
    input_params list[dict] or None Input parameter overrides (optional)
  • 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 moomoo 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)
    print('calc_id:', 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

if ret == RET_OK: print('calc_id:', calc_id) else: print('error:', calc_id) quote_ctx.close() # Remember to close the connection to avoid exhausting connection quota


</template>

<template v-slot:pb>

## Qot_RequestIndicatorCalc.proto

* **Description**

    Asynchronously request indicator calculation. The API returns a `calcId` immediately; the actual calculation result is delivered asynchronously through `Qot_PushIndicatorCalc` (3261), paired by `calcId`.

* **Parameters**

```protobuf
message IndicatorInputItem
{
    required int32 index = 1;
    optional string value = 2;
}

message IndicatorCalcData
{
    required Qot_Common.Security security = 1;
    required Qot_Common.KLType klType = 2;
    repeated Qot_Common.KLine kLine = 3;
}

message C2S
{
    required string shortName = 1;
    required Qot_Common.IndicatorLangType langType = 2;
    required IndicatorCalcData data = 3;
    optional int32 num = 4;
    repeated IndicatorInputItem inputs = 5;
}

message Request
{
    required C2S c2s = 1;
}
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
28
29
30
31
32
33
34
35
36
37
38
39
40
  • Return
message S2C
{
    required string calcId = 1;
}

message Response
{
    required int32 retType = 1 [default = -400];
    optional string retMsg = 2;
    optional int32 errCode = 3;
    optional S2C s2c = 4;
}
1
2
3
4
5
6
7
8
9
10
11
12
  • Protocol ID

    3260