# 到價提醒回呼
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
在收到實時到價提醒通知推送後會回呼到該函數,您需要在衍生類別中覆寫 on_recv_rsp。參數
參數 類型 説明 rsp_pb Qot_UpdatePriceReminder_pb2.Response 衍生類別中不需要直接處理該參數
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data dict 當 ret == RET_OK,返回到價提醒 str 當 ret != RET_OK,返回錯誤描述 - 到價提醒
欄位 類型 説明 code str 股票代碼 name str 股票名稱 price float 當前價格 change_rate str 當前漲跌幅 market_status PriceReminderMarketStatus 觸發的時間段 content str 到價提醒文字內容 note str 備註 僅支援 20 個以內的中文字元key int 到價提醒標識 reminder_type PriceReminderType 到價提醒的類型 set_value float 用戶設定的提醒值 cur_value float 提醒觸發時的值
- 到價提醒
Example
import time
from futu import *
class PriceReminderTest(PriceReminderHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(PriceReminderTest,self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("PriceReminderTest: error, msg: %s" % content)
return RET_ERROR, content
print("PriceReminderTest ", content) # PriceReminderTest 自己的處理邏輯
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = PriceReminderTest()
quote_ctx.set_handler(handler) # 設定到價提醒通知回呼
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
- Output
PriceReminderTest {'code': 'US.AAPL', 'name': '蘋果', 'price': 185.750, 'change_rate': 0.11, 'market_status': 'US_PRE', 'content': '買一價高於185.500', 'note': '', 'key': 1744022257052794489, 'reminder_type': 'BID_PRICE_UP', 'set_value': 185.500, 'cur_value': 185.750}
# Qot_UpdatePriceReminder.proto
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
協議 ID
3019
virtual void OnReply_UpdatePriceReminder(FTAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp);
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_UpdatePriceReminder(FTAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp)
{
Console.Write("Reply: QotUpdatePriceReminder: {0}\n", nSerialNo);
Console.Write("code: {0}, content: {1}\n", rsp.S2C.Security.Code, rsp.S2C.Content);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6826796032557005979
Reply: QotUpdatePriceReminder: 4
code: VXmain, content: 價格漲到20.650
2
3
void onPush_UpdatePriceReminder(FTAPI_Conn client, int nSerialNo, QotUpdatePriceReminder.Response rsp);
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onPush_UpdatePriceReminder(FTAPI_Conn client, QotUpdatePriceReminder.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdatePriceReminder failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdatePriceReminder: %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
- Output
Receive QotUpdatePriceReminder: {
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 604,
"changeRate": 0.499,
"marketStatus": 1,
"content": "價格漲到604.000",
"note": "",
"key": "162321935858611601",
"type": 1,
"setValue": 604,
"curValue": 604
}
}
Receive QotUpdatePriceReminder: {
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 603.5,
"changeRate": 0.415,
"marketStatus": 1,
"content": "價格跌到603.990",
"note": "",
"key": "162320791658522901",
"type": 2,
"setValue": 603.99,
"curValue": 603.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
virtual void OnPush_UpdatePriceReminder(const Qot_UpdatePriceReminder::Response &stRsp) = 0;
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
virtual void OnPush_UpdatePriceReminder(const Qot_UpdatePriceReminder::Response &stRsp) {
cout << "OnPush_UpdatePriceReminder: " << endl;
// 解析內部結構列印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h檔案
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
};
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
- Output
connect
OnPush_UpdatePriceReminder:
{
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 604,
"changeRate": 0.499,
"marketStatus": 1,
"content": "價格漲到604.000",
"note": "",
"key": "162321935858611601",
"type": 1,
"setValue": 604,
"curValue": 604
}
}
OnPush_UpdatePriceReminder:
{
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 603.5,
"changeRate": 0.415,
"marketStatus": 1,
"content": "價格跌到603.990",
"note": "",
"key": "162320791658522901",
"type": 2,
"setValue": 603.99,
"curValue": 603.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
OnPush(cmd,res)
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 介面呼叫結果,結構參見 RetType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common, Trd_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotUpdatePriceReminder(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, 'ec16fde057a2e7a0'];
let websocket = new ftWebsocket();
// 需要已有設定的到價提醒
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdatePriceReminder.cmd == cmd){ // 到價提醒推送的處理邏輯
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log("PriceReminderTest:");
console.log(data);
} else {
console.log("PriceReminderTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000); // 接收 OpenD 的推送持續時間為3600秒, 3600秒後斷開
}
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
- Output
PriceReminderTest:
{
"security": {
"market": 1,
"code": "00700"
},
"price": 482.8,
"changeRate": 1.004,
"marketStatus": 1,
"content": "Daily rises more than 1.000%",
"note": "",
"key": "163126377342664201",
"type": 3,
"setValue": 1,
"curValue": 1.004
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
提示
- 此介面提供了持續獲取推送數據的功能,如需一次性獲取實時數據,請參考 獲取到價提醒 介面
- 獲取實時數據 和 實時數據回呼 的差別,請參考 如何透過訂閲介面獲取實時行情?
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
在收到實時到價提醒通知推送後會回呼到該函數,您需要在衍生類別中覆寫 on_recv_rsp。參數
參數 類型 説明 rsp_pb Qot_UpdatePriceReminder_pb2.Response 衍生類別中不需要直接處理該參數
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data dict 當 ret == RET_OK,返回到價提醒 str 當 ret != RET_OK,返回錯誤描述 - 到價提醒
欄位 類型 説明 code str 股票代碼 name str 股票名稱 price float 當前價格 change_rate str 當前漲跌幅 market_status PriceReminderMarketStatus 觸發的時間段 content str 到價提醒文字內容 note str 備註 僅支援 20 個以內的中文字元key int 到價提醒標識 reminder_type PriceReminderType 到價提醒的類型 set_value float 用戶設定的提醒值 cur_value float 提醒觸發時的值
- 到價提醒
Example
import time
from moomoo import *
class PriceReminderTest(PriceReminderHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(PriceReminderTest,self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("PriceReminderTest: error, msg: %s" % content)
return RET_ERROR, content
print("PriceReminderTest ", content) # PriceReminderTest 自己的處理邏輯
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = PriceReminderTest()
quote_ctx.set_handler(handler) # 設定到價提醒通知回呼
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
- Output
PriceReminderTest {'code': 'US.AAPL', 'name': '蘋果', 'price': 185.750, 'change_rate': 0.11, 'market_status': 'US_PRE', 'content': '買一價高於185.500', 'note': '', 'key': 1744022257052794489, 'reminder_type': 'BID_PRICE_UP', 'set_value': 185.500, 'cur_value': 185.750}
# Qot_UpdatePriceReminder.proto
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
協議 ID
3019
virtual void OnReply_UpdatePriceReminder(MMAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp);
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_UpdatePriceReminder(MMAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp)
{
Console.Write("Reply: QotUpdatePriceReminder: {0}\n", nSerialNo);
Console.Write("code: {0}, content: {1}\n", rsp.S2C.Security.Code, rsp.S2C.Content);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6826796032557005979
Reply: QotUpdatePriceReminder: 4
code: VXmain, content: 價格漲到20.650
2
3
void onPush_UpdatePriceReminder(MMAPI_Conn client, int nSerialNo, QotUpdatePriceReminder.Response rsp);
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onPush_UpdatePriceReminder(MMAPI_Conn client, QotUpdatePriceReminder.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdatePriceReminder failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdatePriceReminder: %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
- Output
Receive QotUpdatePriceReminder: {
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 604,
"changeRate": 0.499,
"marketStatus": 1,
"content": "價格漲到604.000",
"note": "",
"key": "162321935858611601",
"type": 1,
"setValue": 604,
"curValue": 604
}
}
Receive QotUpdatePriceReminder: {
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 603.5,
"changeRate": 0.415,
"marketStatus": 1,
"content": "價格跌到603.990",
"note": "",
"key": "162320791658522901",
"type": 2,
"setValue": 603.99,
"curValue": 603.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
virtual void OnPush_UpdatePriceReminder(const Qot_UpdatePriceReminder::Response &stRsp) = 0;
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 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;
}
virtual void OnPush_UpdatePriceReminder(const Qot_UpdatePriceReminder::Response &stRsp) {
cout << "OnPush_UpdatePriceReminder: " << endl;
// 解析內部結構列印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h檔案
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
};
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
- Output
connect
OnPush_UpdatePriceReminder:
{
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 604,
"changeRate": 0.499,
"marketStatus": 1,
"content": "價格漲到604.000",
"note": "",
"key": "162321935858611601",
"type": 1,
"setValue": 604,
"curValue": 604
}
}
OnPush_UpdatePriceReminder:
{
"retType": 0,
"s2c": {
"security": {
"market": 1,
"code": "00700"
},
"price": 603.5,
"changeRate": 0.415,
"marketStatus": 1,
"content": "價格跌到603.990",
"note": "",
"key": "162320791658522901",
"type": 2,
"setValue": 603.99,
"curValue": 603.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
OnPush(cmd,res)
介紹
到價提醒通知回呼,非同步處理已設定到價提醒的通知推送。
參數
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; // 盤中
MarketStatus_USPre = 2; // 美股盤前
MarketStatus_USAfter = 3; // 美股盤後
MarketStatus_USOverNight = 4; // 美股夜盤
}
message S2C
{
required Qot_Common.Security security = 1; //股票
optional string name = 11; // 股票名稱
required double price = 2; //價格
required double changeRate = 3; //當日漲跌幅
required int32 marketStatus = 4; //Qot_Common::MarketStatus 市場狀態
required string content = 5; //內容
required string note = 6; //備註僅支援 20 個以內的中文字元
optional int64 key = 7; //到價提醒的標識
optional int32 type = 8; //Qot_Common::PriceReminderType,提醒頻率類型
optional double setValue = 9; //設定的提醒值
optional double curValue = 10; //設定的提醒類型觸發時當前值
}
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
23
24
25
26
27
28
29
30
31
32
- 股票結構參見 Security
- 提醒類型列舉參見 PriceReminderType
- 介面呼叫結果,結構參見 RetType
- 介面呼叫結果,結構參見 RetType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common, Trd_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotUpdatePriceReminder(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, 'ec16fde057a2e7a0'];
let websocket = new mmWebsocket();
// 需要已有設定的到價提醒
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdatePriceReminder.cmd == cmd){ // 到價提醒推送的處理邏輯
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log("PriceReminderTest:");
console.log(data);
} else {
console.log("PriceReminderTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000); // 接收 FOpenD 的推送持續時間為3600秒, 3600秒後斷開
}
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
- Output
PriceReminderTest:
{
"security": {
"market": 1,
"code": "00700"
},
"price": 482.8,
"changeRate": 1.004,
"marketStatus": 1,
"content": "Daily rises more than 1.000%",
"note": "",
"key": "163126377342664201",
"type": 3,
"setValue": 1,
"curValue": 1.004
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
提示
- 此介面提供了持續獲取推送數據的功能,如需一次性獲取實時數據,請參考 獲取到價提醒 介面
- 獲取實時數據 和 實時數據回呼 的差別,請參考 如何透過訂閲介面獲取實時行情?