# Price Reminder Callback
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
The price reminder notification callback, asynchronously handles the notification push that has been set to the price reminder. After receiving the real-time price notification, it will call back to this function. You need to override on_recv_rsp in the derived class.
Parameters
Parameter Type Description rsp_pb Qot_UpdatePriceReminder_pb2.Response This parameter does not need to be processed directly in the derived class.
Return
Field Type Description ret RET_CODE Interface result. data dict If ret == RET_OK, price reminder is returned. str If ret != RET_OK, error description is returned. - Price reminder format as follows:
Field Type Description code str Stock code. name str Stock name. price float Current price. change_rate str Current change rate. market_status PriceReminderMarketStatus The time period for triggering. content str Text content of price reminder. note str Note. Note supports no more than 20 Chinese characters.key int Price reminder identification. reminder_type PriceReminderType The type of price reminder. set_value float The reminder value set by the user. cur_value float The value when the reminder was triggered.
- Price reminder format as follows:
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's own processing logic
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = PriceReminderTest()
quote_ctx.set_handler(handler) # Set price reminder notification callback
time.sleep(15) # Set the script to receive OpenD push duration to 15 seconds
quote_ctx.close() # Close the current connection, OpenD will automatically cancel the corresponding type of subscription for the corresponding stock after 1 minute
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Output
PriceReminderTest {'code': 'HK.HSImain','name':'HSI Futures Main(JUL3)' 'price': 24529.0, 'change_rate': 0.11, 'market_status': 'OPEN', 'content': 'Price rose to24531.000', 'note': '', 'key': 158815186771390101, 'reminder_type': 'PRICE_UP', 'set_value': 24531.0, 'cur_value': 24532.0}
# Qot_UpdatePriceReminder.proto
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
Protocol ID
3019
virtual void OnReply_UpdatePriceReminder(FTAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp);
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
- Example
public class Program: FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //Set client information
qot.SetConnCallback(this); //Set connection callback
qot.SetQotCallback(this); //Set transaction callback
}
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: Price rose to20.650
2
3
void onPush_UpdatePriceReminder(FTAPI_Conn client, int nSerialNo, QotUpdatePriceReminder.Response rsp);
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //Set client information
qot.setConnSpi(this); //Set connection callback
qot.setQotSpi(this); //Set transaction callback
}
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": "Price rises to 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": "Price falls under 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;
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to 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;
// print response
// ProtoBufToBodyData and UTF8ToLocal refer to tool.h in Samples
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": "Price rises to 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": "Price falls under 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)
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to 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();
// Need a set price reminder
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdatePriceReminder.cmd == cmd){ // PriceReminderTest's own processing logic
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);
// After using the connection, remember to close it to prevent the number of connections from running out
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000); // Set the script to receive OpenD push duration to 3600 seconds
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
Tips
- This interface provides the function of continuously obtaining pushed data. If you need to obtain real-time data at one time, please refer to the Get Price Reminder List API.
- For the difference between get real-time data and real-time data callback, please refer to How to Get Real-time Quotes Through Subscription Interface API.
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
The price reminder notification callback, asynchronously handles the notification push that has been set to the price reminder. After receiving the real-time price notification, it will call back to this function. You need to override on_recv_rsp in the derived class.
Parameters
Parameter Type Description rsp_pb Qot_UpdatePriceReminder_pb2.Response This parameter does not need to be processed directly in the derived class.
Return
Field Type Description ret RET_CODE Interface result. data dict If ret == RET_OK, price reminder is returned. str If ret != RET_OK, error description is returned. - Price reminder format as follows:
Field Type Description code str Stock code. name str Stock name. price float Current price. change_rate str Current change rate. market_status PriceReminderMarketStatus The time period for triggering. content str Text content of price reminder. note str Note. Note supports no more than 20 Chinese characters.key int Price reminder identification. reminder_type PriceReminderType The type of price reminder. set_value float The reminder value set by the user. cur_value float The value when the reminder was triggered.
- Price reminder format as follows:
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's own processing logic
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = PriceReminderTest()
quote_ctx.set_handler(handler) # Set price reminder notification callback
time.sleep(15) # Set the script to receive OpenD push duration to 15 seconds
quote_ctx.close() # Close the current connection, OpenD will automatically cancel the corresponding type of subscription for the corresponding stock after 1 minute
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Output
PriceReminderTest {'code': 'HK.HSImain','name':'HSI Futures Main(JUL3)' 'price': 24529.0, 'change_rate': 0.11, 'market_status': 'OPEN', 'content': 'Price rose to24531.000', 'note': '', 'key': 158815186771390101, 'reminder_type': 'PRICE_UP', 'set_value': 24531.0, 'cur_value': 24532.0}
# Qot_UpdatePriceReminder.proto
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
Protocol ID
3019
virtual void OnReply_UpdatePriceReminder(MMAPI_Conn client, uint nSerialNo, QotUpdatePriceReminder.Response rsp);
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
- Example
public class Program: MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //Set client information
qot.SetConnCallback(this); //Set connection callback
qot.SetQotCallback(this); //Set transaction callback
}
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: Price rose to20.650
2
3
void onPush_UpdatePriceReminder(MMAPI_Conn client, int nSerialNo, QotUpdatePriceReminder.Response rsp);
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to RetType
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //Set client information
qot.setConnSpi(this); //Set connection callback
qot.setQotSpi(this); //Set transaction callback
}
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": "Price rises to 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": "Price falls under 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;
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to 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;
// print response
// ProtoBufToBodyData and UTF8ToLocal refer to tool.h in Samples
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": "Price rises to 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": "Price falls under 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)
Description
Price alert notification callback, asynchronously process notification pushes that have been set to price alert.
Parameters
enum MarketStatus
{
MarketStatus_Unknow = 0;
MarketStatus_Open = 1; //Trading session
MarketStatus_USPre = 2; //US stocks pre-market
MarketStatus_USAfter = 3; //US stocks after-hours
}
message S2C
{
required Qot_Common.Security security = 1; //Security
optional string name = 11; // Stock name
required double price = 2; //Price
required double changeRate = 3; //Price change rate today
required int32 marketStatus = 4; //Qot_Common::MarketStatus. Market status
required string content = 5; //Content
required string note = 6; //Note supports no more than 20 Chinese characters
optional int64 key = 7; //Identification of the price reminder
optional int32 type = 8; //Qot_Common::PriceReminderType, reminder frequency type
optional double setValue = 9; //Set reminder value
optional double curValue = 10; //Current value when the set reminder type is triggered
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
- For stock structure, refer to Security
- For reminder type enumeration, refer to PriceReminderType
- For interface result, refer to 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();
// Need a set price reminder
websocket.onPush = (cmd, res)=>{
if(mmCmdID.QotUpdatePriceReminder.cmd == cmd){ // PriceReminderTest's own processing logic
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);
// After using the connection, remember to close it to prevent the number of connections from running out
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000); // Set the script to receive OpenD push duration to 3600 seconds
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
Tips
- This interface provides the function of continuously obtaining pushed data. If you need to obtain real-time data at one time, please refer to the Get Price Reminder List API.
- For the difference between get real-time data and real-time data callback, please refer to How to Get Real-time Quotes Through Subscription Interface API.