# インジケーター計算結果プッシュ
- Python
- Proto
- C#
- Java
- C++
- JavaScript
IndicatorCalcHandlerBase
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果プッシュを受信します。本プッシュは能動的に呼び出すものではなく、SPI/ハンドラーを登録することでcalcId単位で結果を受動的に受信します。コールバックパラメータ
フィールド 型 説明 calc_id str 計算タスクID、リクエスト時に返却された calcId に対応 outputs list 出力ライン(IndicatorOutputParam)のメタデータ output_rows list 計算結果、時刻順
# Qot_PushIndicatorCalc.proto
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。戻り値
//1 行の計算結果、1 つのK線時刻に対応;values の順序は outputs と 1 対 1 で対応
message IndicatorOutputRow
{
optional string time = 1; //K線時刻(リクエスト中の KLine.time と一致)
repeated double values = 2; //各出力ラインの当該時刻における値
}
//非同期インジケーター計算結果プッシュ、Qot_RequestIndicatorCalc と calcId で紐付け
message S2C
{
required string calcId = 1; //発起時に返却された calcId と対応
repeated Qot_Common.IndicatorOutputParam outputs = 2; //出力ラインのメタデータ
repeated IndicatorOutputRow outputRows = 3; //計算結果、時刻順
}
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
13
14
15
16
17
18
19
20
21
22
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
プロトコル ID
3261
virtual void OnPush_PushIndicatorCalc(FTAPI_Conn client, QotPushIndicatorCalc.Response rsp);
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、SPI を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
- Output
void onPush_PushIndicatorCalc(FTAPI_Conn client, QotPushIndicatorCalc.Response rsp);
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、SPI を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
- Output
virtual void OnPush_PushIndicatorCalc(const Qot_PushIndicatorCalc::Response &stRsp) = 0;
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、Spi を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: 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_RegQotPush でプッシュ登録
Qot_RegQotPush::Request req;
Qot_RegQotPush::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->add_securitylist();
sec->set_market(Qot_Common::QotMarket_US_Security);
sec->set_code("AAPL");
c2s->add_subtypelist(Qot_Common::SubType_KL_Day);
c2s->set_regpush(true);
m_RegQotPushSerialNo = m_pQotApi->RegQotPush(req);
}
// RequestIndicatorCalc を別途呼び出した後、計算結果が以下のプッシュで受信される
virtual void OnPush_PushIndicatorCalc(const Qot_PushIndicatorCalc::Response &stRsp) {
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_RegQotPushSerialNo = 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
PushIndicatorCalc
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本通知は能動的に呼び出さず、イベントリスナーを登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotPushIndicatorCalc(){
const { RetType } = Common
const { KLType, IndicatorLangType, QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
// 注册指标异步计算结果推送回调,与 RequestIndicatorCalc 返回的 calcId 配对
websocket.onPush_PushIndicatorCalc = (qotPushIndicatorCalc)=>{
let { errCode, retMsg, retType, s2c } = qotPushIndicatorCalc
console.log("PushIndicatorCalc: 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);
}
};
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 发起一次 MACD 指标计算,结果由上面的回调推送回来
const req = {
c2s: {
shortName: "MACD",
langType: IndicatorLangType.IndicatorLangType_MyLang,
data: {
security: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
klType: KLType.KLType_Day,
kLine: [
{ time: 1700000000, open: 310.0, close: 315.0, high: 318.0, low: 308.0, volume: 10000000, turnover: 3150000000 }
]
},
},
};
websocket.RequestIndicatorCalc(req)
.then((res)=>{ console.log("RequestIndicatorCalc calcId:", res.s2c && res.s2c.calcId); })
.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);
}
QotPushIndicatorCalc()
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
- Output
RequestIndicatorCalc calcId: 1700000000000-0
PushIndicatorCalc: errCode 0, retMsg , retType 0
{
"calcId": "1700000000000-0",
"outputs": [
{ "index": 0, "name": "DIF", "type": 1 },
{ "index": 1, "name": "DEA", "type": 1 },
{ "index": 2, "name": "MACD", "type": 1 }
],
"outputRows": [
{ "time": "1700000000", "values": [0.5234, 0.4123, 0.2222] }
]
}
2
3
4
5
6
7
8
9
10
11
12
13
- Python
- Proto
- C#
- Java
- C++
- JavaScript
IndicatorCalcHandlerBase
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果プッシュを受信します。本プッシュは能動的に呼び出すものではなく、SPI/ハンドラーを登録することでcalcId単位で結果を受動的に受信します。コールバックパラメータ
フィールド 型 説明 calc_id str 計算タスクID、リクエスト時に返却された calcId に対応 outputs list 出力ライン(IndicatorOutputParam)のメタデータ output_rows list 計算結果、時刻順
# Qot_PushIndicatorCalc.proto
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
プロトコル ID
3261
virtual void OnPush_PushIndicatorCalc(MMAPI_Conn client, QotPushIndicatorCalc.Response rsp);
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、SPI を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
- Output
void onPush_PushIndicatorCalc(MMAPI_Conn client, QotPushIndicatorCalc.Response rsp);
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、SPI を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
- Output
virtual void OnPush_PushIndicatorCalc(const Qot_PushIndicatorCalc::Response &stRsp) = 0;
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本コールバックは能動的に呼び出さず、Spi を登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: 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_RegQotPush でプッシュ登録
Qot_RegQotPush::Request req;
Qot_RegQotPush::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->add_securitylist();
sec->set_market(Qot_Common::QotMarket_US_Security);
sec->set_code("AAPL");
c2s->add_subtypelist(Qot_Common::SubType_KL_Day);
c2s->set_regpush(true);
m_RegQotPushSerialNo = m_pQotApi->RegQotPush(req);
}
// RequestIndicatorCalc を別途呼び出した後、計算結果が以下のプッシュで受信される
virtual void OnPush_PushIndicatorCalc(const Qot_PushIndicatorCalc::Response &stRsp) {
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
Moomoo::u32_t m_RegQotPushSerialNo = 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
PushIndicatorCalc
説明
Qot_RequestIndicatorCalcで起動した非同期インジケーター計算の結果をcalcId単位でプッシュ通知します。本通知は能動的に呼び出さず、イベントリスナーを登録することで受動的にプッシュを受信します。戻り値
message IndicatorOutputRow
{
optional string time = 1;
repeated double values = 2;
}
message S2C
{
required string calcId = 1;
repeated Qot_Common.IndicatorOutputParam outputs = 2;
repeated IndicatorOutputRow outputRows = 3;
}
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
13
14
15
16
17
18
19
20
- 指標出力パラメータの構造体は IndicatorOutputParam を参照
- インジケーター計算の起動は Qot_RequestIndicatorCalc を参照
- API呼び出し結果の構造体: RetType
- Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotPushIndicatorCalc(){
const { RetType } = Common
const { KLType, IndicatorLangType, QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
// 注册指标异步计算结果推送回调,与 RequestIndicatorCalc 返回的 calcId 配对
websocket.onPush_PushIndicatorCalc = (qotPushIndicatorCalc)=>{
let { errCode, retMsg, retType, s2c } = qotPushIndicatorCalc
console.log("PushIndicatorCalc: 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);
}
};
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 发起一次 MACD 指标计算,结果由上面的回调推送回来
const req = {
c2s: {
shortName: "MACD",
langType: IndicatorLangType.IndicatorLangType_MyLang,
data: {
security: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
klType: KLType.KLType_Day,
kLine: [
{ time: 1700000000, open: 310.0, close: 315.0, high: 318.0, low: 308.0, volume: 10000000, turnover: 3150000000 }
]
},
},
};
websocket.RequestIndicatorCalc(req)
.then((res)=>{ console.log("RequestIndicatorCalc calcId:", res.s2c && res.s2c.calcId); })
.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);
}
QotPushIndicatorCalc()
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
- Output
RequestIndicatorCalc calcId: 1700000000000-0
PushIndicatorCalc: errCode 0, retMsg , retType 0
{
"calcId": "1700000000000-0",
"outputs": [
{ "index": 0, "name": "DIF", "type": 1 },
{ "index": 1, "name": "DEA", "type": 1 },
{ "index": 2, "name": "MACD", "type": 1 }
],
"outputRows": [
{ "time": "1700000000", "values": [0.5234, 0.4123, 0.2222] }
]
}
2
3
4
5
6
7
8
9
10
11
12
13