# リアルタイムローソク足コールバック
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
リアルタイム ローソク足データプッシュの受信時にこの関数がコールバックされます。派生クラスで on_recv_rsp をオーバーライドしてください。
パラメータ
パラメータ 型 説明 rsp_pb Qot_UpdateKL_pb2.Response 派生クラスでは直接処理不要 戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 data pd.DataFrame ret == RET_OK の場合、 ローソク足データデータ str ret != RET_OK の場合、エラーの説明を返す - ローソク足データフォーマットは以下の通りです:
フィールド タイプ 説明 code str 銘柄コード name str 銘柄名 time_key str 時間 フォーマット:yyyy-MM-dd HH:mm:ss
香港株と A 株市場のデフォルトは北京時間、米国株市場のデフォルトは米国東部時間open float 始値 close float 終値 high float 高値 low float 安値 volume int 出来高 turnover float 売買代金 pe_ratio float PER turnover_rate float 売買回転率 このフィールドはパーセントフィールドで、デフォルトでは小数を返します。例:0.01 は実際には 1% に対応しますlast_close float 前日終値 前の時刻の終値を指します
効率上の理由から、最初のデータの前日終値は 0 になる場合がありますk_type KLType ローソク足タイプ
- ローソク足データフォーマットは以下の通りです:
Example
import time
from futu import *
class CurKlineTest(CurKlineHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, data = super(CurKlineTest,self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("CurKlineTest: error, msg: %s" % data)
return RET_ERROR, data
print("CurKlineTest ", data) # CurKlineTest 独自の処理ロジック
return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = CurKlineTest()
quote_ctx.set_handler(handler) # リアルタイムローソク足コールバックを設定
ret, data = quote_ctx.subscribe(['US.AAPL'], [SubType.K_1M], session=Session.ALL) # ローソク足データタイプを登録、OpenD がサーバーからのプッシュを継続的に受信開始
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # スクリプトが OpenD のプッシュを受信する時間を15秒に設定
quote_ctx.close() # 接続をクローズすると、OpenD は1分後に対応銘柄の登録を自動解除
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- Output
CurKlineTest code name time_key open close high low volume turnover k_type last_close
0 US.AAPL 苹果 2025-04-07 05:15:00 180.39 180.26 180.46 180.2 1322 238340.48 K_1M 0.0
2
# Qot_UpdateKL.proto
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
プロトコル ID
3007
virtual void OnReply_UpdateKL(FTAPI_Conn client, QotUpdateKL.Response rsp);
- 概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
- パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
public class Program : FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //クライアント情報の設定
qot.SetConnCallback(this); //接続コールバックの設定
qot.SetQotCallback(this); //取引コールバックの設定
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotSub.C2S c2s = QotSub.C2S.CreateBuilder()
.AddSecurityList(sec)
.AddSubTypeList((int)QotCommon.SubType.SubType_KL_1Min)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true)
.Build();
QotSub.Request req = QotSub.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.Sub(req);
Console.Write("Send QotSub: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_Sub(FTAPI_Conn client, uint nSerialNo, QotSub.Response rsp) {
Console.Write("Reply: QotSub: {0} {1}\n", nSerialNo, rsp.ToString());
}
public void OnReply_UpdateKL(FTAPI_Conn client, uint nSerialNo, QotUpdateKL.Response rsp)
{
Console.Write("Push: UpdateKL: {0}\n", nSerialNo);
Console.Write("closePrice: {0}\n", rsp.S2C.KlListList[0].ClosePrice);
}
public static void Main(String[] args) {
FTAPI.Init();
Program qot = new Program();
qot.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
- Output
Qot onInitConnect: ret=0 desc= connID=6825346061843741897
Send QotSub: 3
Reply: QotSub: 3 retType: 0
retMsg: ""
errCode: 0
Push: UpdateKL: 1
closePrice: 490
...
2
3
4
5
6
7
8
9
void onPush_UpdateKL(FTAPI_Conn client, QotUpdateKL.Response rsp);
- 概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
- パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //クライアント情報の設定
qot.setConnSpi(this); //接続コールバックの設定
qot.setQotSpi(this); //取引コールバックの設定
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotSub.C2S c2s = QotSub.C2S.newBuilder()
.addSecurityList(sec)
.addSubTypeList(QotCommon.SubType.SubType_KL_1Min_VALUE)
.setIsSubOrUnSub(true)
.setIsRegOrUnRegPush(true)
.build();
QotSub.Request req = QotSub.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.sub(req);
System.out.printf("Send QotSub: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_Sub(FTAPI_Conn client, int nSerialNo, QotSub.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotSub failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotSub: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
@Override
public void onPush_UpdateKL(FTAPI_Conn client, QotUpdateKL.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdateKL failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdateKL: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
FTAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- Output
Receive QotUpdateKL: {
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [{
"time": "2021-06-25 10:02:00",
"isBlank": false,
"highPrice": 587.0,
"openPrice": 586.0,
"lowPrice": 586.0,
"closePrice": 586.5,
"lastClosePrice": 0.0,
"volume": "60600",
"turnover": 3.5556525E7,
"turnoverRate": 0.0,
"pe": 0.0,
"timestamp": 1.62458652E9
}]
}
}
Receive QotUpdateKL: {
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [{
"time": "2021-06-25 10:02:00",
"isBlank": false,
"highPrice": 587.0,
"openPrice": 586.0,
"lowPrice": 586.0,
"closePrice": 587.0,
"lastClosePrice": 0.0,
"volume": "60800",
"turnover": 3.5673925E7,
"turnoverRate": 0.0,
"pe": 0.0,
"timestamp": 1.62458652E9
}]
}
}
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
50
virtual void OnPush_UpdateKL(const Qot_UpdateKL::Response &stRsp) = 0;
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, 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) {
cout << "connect" << endl;
// この API は事前に登録が必要
Qot_Sub::Request req;
Qot_Sub::C2S *c2s = req.mutable_c2s();
auto secList = c2s->mutable_securitylist();
Qot_Common::Security *sec = secList->Add();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
c2s->add_subtypelist(Qot_Common::SubType::SubType_KL_1Min);
c2s->set_isregorunregpush(true);
c2s->set_issuborunsub(true);
m_SubSerialNo = m_pQotApi->Sub(req);
cout << "Request Sub SerialNo: " << m_SubSerialNo << endl;
}
virtual void OnReply_Sub(Futu::u32_t nSerialNo, const Qot_Sub::Response &stRsp)
{
if(nSerialNo == m_SubSerialNo)
{
cout << "OnReply_Sub SerialNo: " << nSerialNo << endl;
if (stRsp.rettype() != Common::RetType::RetType_Succeed)
{
cout << "Sub Failed" << endl;
return;
}
}
}
virtual void OnPush_UpdateKL(const Qot_UpdateKL::Response &stRsp) {
cout << "OnPush_UpdateKL: " << endl;
// 内部構造を解析して出力
// ProtoBufToBodyData と UTF8ToLocal 関数の定義は Sample の tool.h ファイルを参照
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_SubSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
FTAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
FTAPI::UnInit();
return 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
- Output
connect
Request Sub SerialNo: 3
OnReply_Sub SerialNo: 3
OnPush_UpdateKL:
{
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [
{
"time": "2021-06-09 11:09:00",
"isBlank": false,
"highPrice": 605,
"openPrice": 604.5,
"lowPrice": 604.5,
"closePrice": 605,
"lastClosePrice": 0,
"volume": "2900",
"turnover": 1753900,
"turnoverRate": 0,
"pe": 0,
"timestamp": 1623208140
}
]
}
}
OnPush_UpdateKL:
{
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [
{
"time": "2021-06-09 11:09:00",
"isBlank": false,
"highPrice": 605,
"openPrice": 604.5,
"lowPrice": 604.5,
"closePrice": 604.5,
"lastClosePrice": 0,
"volume": "3000",
"turnover": 1814350,
"turnoverRate": 0,
"pe": 0,
"timestamp": 1623208140
}
]
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
OnPush(cmd,res)
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
function QotUpdateKL(){
const { RetType } = Common
const { SubType, QotMarket } = Qot_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: {
securityList: [
{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
],
subTypeList: [ SubType.SubType_KL_1Min ], // リアルタイムローソク足(分足)タイプを登録
isSubOrUnSub: true, // 登録 true、登録解除 false
isRegOrUnRegPush: true, // プッシュ登録 true、プッシュ解除 false
},
}; // 登録パラメータ
websocket.Sub(req) //# 登録、OpenD がサーバーからのプッシュを継続的に受信開始
.then((res) => { })
.catch((error) => {
if ("retMsg" in error) {
console.log("error:", error.retMsg);
}
});
} else {
console.log("error", msg);
}
};
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdateKL.cmd == cmd){ // リアルタイムローソク足プッシュの処理ロジック
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("CurKlineTest", JSON.stringify(s2c));
} else {
console.log("CurKlineTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // OpenD のプッシュ受信継続時間は5秒、5秒後に切断
}
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
50
51
52
53
54
55
56
- Output
CurKlineTest {"rehabType":1,"klType":1,"security":{"market":1,"code":"00700"},"klList":[{"time":"2021-09-09 16:00:00","isBlank":false,"highPrice":481.4,"openPrice":479.6,"lowPrice":479.6,"closePrice":480,"lastClosePrice":0,"volume":"5134400","turnover":2464740790,"turnoverRate":0,"pe":0,"timestamp":1631174400}]}
CurKlineTest { ... }
...
...
stop
2
3
4
5
ご注意
- このAPIは継続的にプッシュデータを取得する機能を提供します。一括でリアルタイムデータを取得する場合は リアルタイムローソク足取得 APIをご利用ください
- リアルタイムデータの取得とリアルタイムデータコールバックの違いについては、 如何から登録 API で取得してくださいリアルタイム相場情報?
- オプション,日足、1分足、5分足、15分足、60分足のみ提供しています。
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
リアルタイム ローソク足データプッシュの受信時にこの関数がコールバックされます。派生クラスで on_recv_rsp をオーバーライドしてください。
パラメータ
パラメータ 型 説明 rsp_pb Qot_UpdateKL_pb2.Response 派生クラスでは直接処理不要 戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 data pd.DataFrame ret == RET_OK の場合、 ローソク足データデータ str ret != RET_OK の場合、エラーの説明を返す - ローソク足データフォーマットは以下の通りです:
フィールド タイプ 説明 code str 銘柄コード name str 銘柄名 time_key str 時間 フォーマット:yyyy-MM-dd HH:mm:ss
香港株と A 株市場のデフォルトは北京時間、米国株市場のデフォルトは米国東部時間open float 始値 close float 終値 high float 高値 low float 安値 volume int 出来高 turnover float 売買代金 pe_ratio float PER turnover_rate float 売買回転率 このフィールドはパーセントフィールドで、デフォルトでは小数を返します。例:0.01 は実際には 1% に対応しますlast_close float 前日終値 前の時刻の終値を指します
効率上の理由から、最初のデータの前日終値は 0 になる場合がありますk_type KLType ローソク足タイプ
- ローソク足データフォーマットは以下の通りです:
Example
import time
from moomoo import *
class CurKlineTest(CurKlineHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, data = super(CurKlineTest,self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("CurKlineTest: error, msg: %s" % data)
return RET_ERROR, data
print("CurKlineTest ", data) # CurKlineTest 独自の処理ロジック
return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = CurKlineTest()
quote_ctx.set_handler(handler) # リアルタイムローソク足コールバックを設定
ret, data = quote_ctx.subscribe(['US.AAPL'], [SubType.K_1M], session=Session.ALL) # ローソク足データタイプを登録、OpenD がサーバーからのプッシュを継続的に受信開始
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # スクリプトが OpenD のプッシュを受信する時間を15秒に設定
quote_ctx.close() # 接続をクローズすると、OpenD は1分後に対応銘柄の登録を自動解除
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- Output
CurKlineTest code name time_key open close high low volume turnover k_type last_close
0 US.AAPL 苹果 2025-04-07 05:15:00 180.39 180.26 180.46 180.2 1322 238340.48 K_1M 0.0
2
# Qot_UpdateKL.proto
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
プロトコル ID
3007
virtual void OnReply_UpdateKL(MMAPI_Conn client, QotUpdateKL.Response rsp);
- 概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
- パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
public class Program : MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //クライアント情報の設定
qot.SetConnCallback(this); //接続コールバックの設定
qot.SetQotCallback(this); //取引コールバックの設定
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotSub.C2S c2s = QotSub.C2S.CreateBuilder()
.AddSecurityList(sec)
.AddSubTypeList((int)QotCommon.SubType.SubType_KL_1Min)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true)
.Build();
QotSub.Request req = QotSub.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.Sub(req);
Console.Write("Send QotSub: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_Sub(MMAPI_Conn client, uint nSerialNo, QotSub.Response rsp) {
Console.Write("Reply: QotSub: {0} {1}\n", nSerialNo, rsp.ToString());
}
public void OnReply_UpdateKL(MMAPI_Conn client, uint nSerialNo, QotUpdateKL.Response rsp)
{
Console.Write("Push: UpdateKL: {0}\n", nSerialNo);
Console.Write("closePrice: {0}\n", rsp.S2C.KlListList[0].ClosePrice);
}
public static void Main(String[] args) {
MMAPI.Init();
Program qot = new Program();
qot.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
- Output
Qot onInitConnect: ret=0 desc= connID=6825346061843741897
Send QotSub: 3
Reply: QotSub: 3 retType: 0
retMsg: ""
errCode: 0
Push: UpdateKL: 1
closePrice: 490
...
2
3
4
5
6
7
8
9
void onPush_UpdateKL(MMAPI_Conn client, QotUpdateKL.Response rsp);
- 概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
- パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //クライアント情報の設定
qot.setConnSpi(this); //接続コールバックの設定
qot.setQotSpi(this); //取引コールバックの設定
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotSub.C2S c2s = QotSub.C2S.newBuilder()
.addSecurityList(sec)
.addSubTypeList(QotCommon.SubType.SubType_KL_1Min_VALUE)
.setIsSubOrUnSub(true)
.setIsRegOrUnRegPush(true)
.build();
QotSub.Request req = QotSub.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.sub(req);
System.out.printf("Send QotSub: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_Sub(MMAPI_Conn client, int nSerialNo, QotSub.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotSub failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotSub: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
@Override
public void onPush_UpdateKL(MMAPI_Conn client, QotUpdateKL.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdateKL failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdateKL: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MMAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- Output
Receive QotUpdateKL: {
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [{
"time": "2021-06-25 10:02:00",
"isBlank": false,
"highPrice": 587.0,
"openPrice": 586.0,
"lowPrice": 586.0,
"closePrice": 586.5,
"lastClosePrice": 0.0,
"volume": "60600",
"turnover": 3.5556525E7,
"turnoverRate": 0.0,
"pe": 0.0,
"timestamp": 1.62458652E9
}]
}
}
Receive QotUpdateKL: {
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [{
"time": "2021-06-25 10:02:00",
"isBlank": false,
"highPrice": 587.0,
"openPrice": 586.0,
"lowPrice": 586.0,
"closePrice": 587.0,
"lastClosePrice": 0.0,
"volume": "60800",
"turnover": 3.5673925E7,
"turnoverRate": 0.0,
"pe": 0.0,
"timestamp": 1.62458652E9
}]
}
}
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
50
virtual void OnPush_UpdateKL(const Qot_UpdateKL::Response &stRsp) = 0;
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, 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) {
cout << "connect" << endl;
// この API は事前に登録が必要
Qot_Sub::Request req;
Qot_Sub::C2S *c2s = req.mutable_c2s();
auto secList = c2s->mutable_securitylist();
Qot_Common::Security *sec = secList->Add();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
c2s->add_subtypelist(Qot_Common::SubType::SubType_KL_1Min);
c2s->set_isregorunregpush(true);
c2s->set_issuborunsub(true);
m_SubSerialNo = m_pQotApi->Sub(req);
cout << "Request Sub SerialNo: " << m_SubSerialNo << endl;
}
virtual void OnReply_Sub(moomoo::u32_t nSerialNo, const Qot_Sub::Response &stRsp)
{
if(nSerialNo == m_SubSerialNo)
{
cout << "OnReply_Sub SerialNo: " << nSerialNo << endl;
if (stRsp.rettype() != Common::RetType::RetType_Succeed)
{
cout << "Sub Failed" << endl;
return;
}
}
}
virtual void OnPush_UpdateKL(const Qot_UpdateKL::Response &stRsp) {
cout << "OnPush_UpdateKL: " << endl;
// 内部構造を解析して出力
// ProtoBufToBodyData と UTF8ToLocal 関数の定義は Sample の tool.h ファイルを参照
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_SubSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
MMAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
MMAPI::UnInit();
return 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
- Output
connect
Request Sub SerialNo: 3
OnReply_Sub SerialNo: 3
OnPush_UpdateKL:
{
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [
{
"time": "2021-06-09 11:09:00",
"isBlank": false,
"highPrice": 605,
"openPrice": 604.5,
"lowPrice": 604.5,
"closePrice": 605,
"lastClosePrice": 0,
"volume": "2900",
"turnover": 1753900,
"turnoverRate": 0,
"pe": 0,
"timestamp": 1623208140
}
]
}
}
OnPush_UpdateKL:
{
"retType": 0,
"s2c": {
"rehabType": 1,
"klType": 1,
"security": {
"market": 1,
"code": "00700"
},
"klList": [
{
"time": "2021-06-09 11:09:00",
"isBlank": false,
"highPrice": 605,
"openPrice": 604.5,
"lowPrice": 604.5,
"closePrice": 604.5,
"lastClosePrice": 0,
"volume": "3000",
"turnover": 1814350,
"turnoverRate": 0,
"pe": 0,
"timestamp": 1623208140
}
]
}
}
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
50
51
52
53
54
55
56
57
58
59
60
61
OnPush(cmd,res)
概要
リアルタイムローソク足コールバック。登録済み株式のリアルタイムローソク足プッシュを非同期処理します。
パラメータ
message S2C
{
required int32 rehabType = 1; //Qot_Common.RehabType, 復権タイプ
required int32 klType = 2; //Qot_Common.KLType, ローソク足タイプ
required Qot_Common.Security security = 3; //株式
optional string name = 5; // 銘柄名
repeated Qot_Common.KLine klList = 4; //プッシュされるローソク足データ構造体
}
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
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
function QotUpdateKL(){
const { RetType } = Common
const { SubType, QotMarket } = Qot_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: {
securityList: [
{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
],
subTypeList: [ SubType.SubType_KL_1Min ], // リアルタイムローソク足(分足)タイプを登録
isSubOrUnSub: true, // 登録 true、登録解除 false
isRegOrUnRegPush: true, // プッシュ登録 true、プッシュ解除 false
},
}; // 登録パラメータ
websocket.Sub(req) //# 登録、OpenD がサーバーからのプッシュを継続的に受信開始
.then((res) => { })
.catch((error) => {
if ("retMsg" in error) {
console.log("error:", error.retMsg);
}
});
} else {
console.log("error", msg);
}
};
websocket.onPush = (cmd, res)=>{
if(mmCmdID.QotUpdateKL.cmd == cmd){ // リアルタイムローソク足プッシュの処理ロジック
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("CurKlineTest", JSON.stringify(s2c));
} else {
console.log("CurKlineTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // OpenD のプッシュ受信継続時間は5秒、5秒後に切断
}
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
50
51
52
53
54
55
56
- Output
CurKlineTest {"rehabType":1,"klType":1,"security":{"market":1,"code":"00700"},"klList":[{"time":"2021-09-09 16:00:00","isBlank":false,"highPrice":481.4,"openPrice":479.6,"lowPrice":479.6,"closePrice":480,"lastClosePrice":0,"volume":"5134400","turnover":2464740790,"turnoverRate":0,"pe":0,"timestamp":1631174400}]}
CurKlineTest { ... }
...
...
stop
2
3
4
5
ご注意
- このAPIは継続的にプッシュデータを取得する機能を提供します。一括でリアルタイムデータを取得する場合は リアルタイムローソク足取得 APIをご利用ください
- リアルタイムデータの取得とリアルタイムデータコールバックの違いについては、 如何から登録 API で取得してくださいリアルタイム相場情報?
- オプション,日足、1分足、5分足、15分足、60分足のみ提供しています。