# 異步發起指標計算
- Python
- Proto
- C#
- Java
- C++
- JavaScript
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.00700kl_type KLType K 線類型 klines pd.DataFrame 或 list[dict] K 線數據,可由 request_history_kline/get_cur_kline返回num int 或 None 最多取前 N 條 K 線參與計算 None 表示使用全部 K 線input_params list[dict] 或 None 入參覆蓋列表 留空則使用雲端配置;每項為{"index": int, "value": str}返回
參數 類型 說明 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()
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
# Qot_RequestIndicatorCalc.proto
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
// 單個輸入參數覆蓋項
message IndicatorInputItem
{
required int32 index = 1; // 入參下標,對應 IndicatorInfo.inputs 中的 index,從 0 開始
optional string value = 2; // 入參值(字符串形式,省略則沿用默認值)
}
// 計算所需的標的與 K 線數據
message IndicatorCalcData
{
required Qot_Common.Security security = 1; // 標的
required Qot_Common.KLType klType = 2; // K 線週期
repeated Qot_Common.KLine kLine = 3; // K 線數據
}
message C2S
{
required string shortName = 1; // 指標短名
required Qot_Common.IndicatorLangType langType = 2; // 指標語言類型
required IndicatorCalcData data = 3; // 計算所需數據
optional int32 num = 4; // 最多取前 N 條 K 線參與計算;不填表示使用全部 K 線
repeated IndicatorInputItem inputs = 5; // 入參覆蓋(可空,留空則使用雲端配置)
}
message Request
{
required C2S c2s = 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
- 返回
message S2C
{
required string calcId = 1; // 計算任務 ID,與推送結果配對
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- K 線週期參見 KLType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
協議 ID
3260
uint RequestIndicatorCalc(QotRequestIndicatorCalc.Request req);
virtual void OnReply_RequestIndicatorCalc(FTAPI_Conn client, uint nSerialNo, QotRequestIndicatorCalc.Response rsp);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
- Output
int requestIndicatorCalc(QotRequestIndicatorCalc.Request req);
void onReply_RequestIndicatorCalc(FTAPI_Conn client, int nSerialNo, QotRequestIndicatorCalc.Response rsp);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
- Output
Futu::u32_t RequestIndicatorCalc(const Qot_RequestIndicatorCalc::Request &stReq);
virtual void OnReply_RequestIndicatorCalc(Futu::u32_t nSerialNo, const Qot_RequestIndicatorCalc::Response &stRsp) = 0;
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr) {
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
Qot_RequestIndicatorCalc::Request req;
Qot_RequestIndicatorCalc::C2S *c2s = req.mutable_c2s();
c2s->set_shortname("MACD");
c2s->set_langtype(Qot_Common::IndicatorLangType_MyLang);
Qot_RequestIndicatorCalc::IndicatorCalcData *data = c2s->mutable_data();
Qot_Common::Security *sec = data->mutable_security();
sec->set_market(Qot_Common::QotMarket_HK_Security);
sec->set_code("00700");
data->set_kltype(Qot_Common::KLType_Day);
// 此處填充 data->add_kline() ...
m_RequestIndicatorCalcSerialNo = m_pQotApi->RequestIndicatorCalc(req);
}
virtual void OnReply_RequestIndicatorCalc(Futu::u32_t nSerialNo, const Qot_RequestIndicatorCalc::Response &stRsp) {
if (nSerialNo != m_RequestIndicatorCalcSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_RequestIndicatorCalcSerialNo = 0;
};
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
41
42
43
44
45
46
47
48
49
RequestIndicatorCalc(req);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotRequestIndicatorCalc(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
const req = {
c2s: {
shortName: "MACD",
langType: 1,
data: {
security: { market: 1, code: "00700" },
klType: 2,
kLine: [],
},
},
};
websocket.RequestIndicatorCalc(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("RequestIndicatorCalc: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotRequestIndicatorCalc()
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
41
42
43
44
45
46
47
48
- Output
RequestIndicatorCalc: errCode 0, retMsg , retType 0
{
"calcId": "1700000000000-0"
}
2
3
4
- Python
- Proto
- C#
- Java
- C++
- JavaScript
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.00700kl_type KLType K 線類型 klines pd.DataFrame 或 list[dict] K 線數據,可由 request_history_kline/get_cur_kline返回num int 或 None 最多取前 N 條 K 線參與計算 None 表示使用全部 K 線input_params list[dict] 或 None 入參覆蓋列表 留空則使用雲端配置;每項為{"index": int, "value": str}返回
參數 類型 說明 ret RET_CODE 接口調用結果 data str 當 ret == RET_OK,返回計算任務 ID(calc_id),與推送結果配對 str 當 ret != RET_OK,返回錯誤描述 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)
if ret == RET_OK:
print('calcId:', calc_id)
else:
print('error:', calc_id)
time.sleep(5)
quote_ctx.close()
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
# Qot_RequestIndicatorCalc.proto
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
協議 ID
3260
uint RequestIndicatorCalc(QotRequestIndicatorCalc.Request req);
virtual void OnReply_RequestIndicatorCalc(MMAPI_Conn client, uint nSerialNo, QotRequestIndicatorCalc.Response rsp);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
- Output
int requestIndicatorCalc(QotRequestIndicatorCalc.Request req);
void onReply_RequestIndicatorCalc(MMAPI_Conn client, int nSerialNo, QotRequestIndicatorCalc.Response rsp);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
- Output
Moomoo::u32_t RequestIndicatorCalc(const Qot_RequestIndicatorCalc::Request &stReq);
virtual void OnReply_RequestIndicatorCalc(Moomoo::u32_t nSerialNo, const Qot_RequestIndicatorCalc::Response &stRsp) = 0;
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr) {
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, Moomoo::i64_t nErrCode, const char* strDesc) {
Qot_RequestIndicatorCalc::Request req;
Qot_RequestIndicatorCalc::C2S *c2s = req.mutable_c2s();
c2s->set_shortname("MACD");
c2s->set_langtype(Qot_Common::IndicatorLangType_MyLang);
Qot_RequestIndicatorCalc::IndicatorCalcData *data = c2s->mutable_data();
Qot_Common::Security *sec = data->mutable_security();
sec->set_market(Qot_Common::QotMarket_HK_Security);
sec->set_code("00700");
data->set_kltype(Qot_Common::KLType_Day);
// 此處填充 data->add_kline() ...
m_RequestIndicatorCalcSerialNo = m_pQotApi->RequestIndicatorCalc(req);
}
virtual void OnReply_RequestIndicatorCalc(Moomoo::u32_t nSerialNo, const Qot_RequestIndicatorCalc::Response &stRsp) {
if (nSerialNo != m_RequestIndicatorCalcSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
Moomoo::u32_t m_RequestIndicatorCalcSerialNo = 0;
};
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
41
42
43
44
45
46
47
48
49
RequestIndicatorCalc(req);
介紹
異步發起指標計算。接口立即返回 calcId,實際計算結果由 Qot_PushIndicatorCalc 異步推送。
參數
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;
}
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
- 返回
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;
}
2
3
4
5
6
7
8
9
10
11
12
- 指標語言類型參見 IndicatorLangType
- 指標異步計算結果推送參見 Qot_PushIndicatorCalc
- 接口調用結果,結構參見 RetType
- Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotRequestIndicatorCalc(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
const req = {
c2s: {
shortName: "MACD",
langType: 1,
data: {
security: { market: 1, code: "00700" },
klType: 2,
kLine: [],
},
},
};
websocket.RequestIndicatorCalc(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("RequestIndicatorCalc: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotRequestIndicatorCalc()
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
41
42
43
44
45
46
47
48
- Output
RequestIndicatorCalc: errCode 0, retMsg , retType 0
{
"calcId": "1700000000000-0"
}
2
3
4
← 獲取指標列表 指標異步計算結果推送 →