# Indicator Async Calc Result Push

on_recv_rsp(self, rsp_pb)

  • Description

    Indicator async calculation result push callback. The result is paired with the original request submitted via request-indicator-calc by calc_id. The client registers a handler (typically via set_handler) to passively receive the push.

  • Parameters

    Parameter Type Description
    rsp_pb Qot_PushIndicatorCalc_pb2.Response This parameter does not need to be processed directly in the derived class.
  • Return

    Field Type Description
    ret RET_CODE API call result
    data dict When ret == RET_OK, returns the indicator calculation result
    str When ret != RET_OK, returns error description
    • Result fields:

      Field Type Description
      calc_id str Calculation task ID, matches the value returned by request_indicator_calc_async
      outputs list Output line metadata, each item is an IndicatorOutputParam
      output_rows list Calculation result in time order, each row contains time and values (one value per output)
  • Example

import time
from moomoo import *
class IndicatorCalcTest(IndicatorCalcHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(IndicatorCalcTest, self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("IndicatorCalcTest: error, msg: %s" % data)
            return RET_ERROR, data
        print("IndicatorCalcTest ", data)
        return RET_OK, data

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = IndicatorCalcTest()
quote_ctx.set_handler(handler)
ret, kl_data, _ = quote_ctx.request_history_kline('US.AAPL', start='2024-01-01', end='2024-06-01', ktype=KLType.K_DAY)
if ret == RET_OK:
    quote_ctx.request_indicator_calc_async('MACD', IndicatorLangType.MYLANG, 'US.AAPL', KLType.K_DAY, kl_data)
time.sleep(15)
quote_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Tips

  • This interface provides the function of continuously receiving pushed indicator calculation results. To trigger a calculation, call request-indicator-calc. Each push is paired with the original request by calcId.