# Set Option Event Alert
- Python
- Proto
- C#
- Java
- C++
- JavaScript
set_option_event_alert(op, alert_list=None)
Description
Add, modify, delete, or enable/disable option unusual activity alerts.
Parameters
Parameter Type Description op AlertOpType Operation type ADD=Add, DELETE=Delete, MODIFY=Modify, ENABLE=Enable, DISABLE=Disable, DELETE_ALL=Delete allalert_list OptionEventAlertItem or list[OptionEventAlertItem] Alert item(s) Do not pass key when adding, key is required when modifying/deletingOptionEventAlertItem fields:
Field Type Description key int Alert unique identifier (required for modify/delete/enable/disable) enable bool Alert switch option_market OptionMarket Option market to monitor (one of three) watchlist_group_name str Watchlist group name (one of three) underlying str Specified underlying code, e.g. 'US.AAPL'(one of three)option_type OptionType Option type (CALL/PUT) side_type_list list[EventTickerType] Trade direction list order_type_list list[AlertOrderType] Order type list market_cap_range_min float Underlying market cap lower bound market_cap_range_max float Underlying market cap upper bound market_cap_min_inclusive bool Whether market cap lower bound is inclusive (default True) market_cap_max_inclusive bool Whether market cap upper bound is inclusive (default True) expiry_days_range_min float Days to expiration lower bound expiry_days_range_max float Days to expiration upper bound expiry_days_min_inclusive bool Whether days to expiration lower bound is inclusive (default True) expiry_days_max_inclusive bool Whether days to expiration upper bound is inclusive (default True) price_range_min float Event fill price lower bound price_range_max float Event fill price upper bound price_min_inclusive bool Whether fill price lower bound is inclusive (default True) price_max_inclusive bool Whether fill price upper bound is inclusive (default True) size_range_min float Event volume lower bound (contracts) size_range_max float Event volume upper bound (contracts) size_min_inclusive bool Whether volume lower bound is inclusive (default True) size_max_inclusive bool Whether volume upper bound is inclusive (default True) premium_range_min float Event turnover lower bound premium_range_max float Event turnover upper bound premium_min_inclusive bool Whether turnover lower bound is inclusive (default True) premium_max_inclusive bool Whether turnover upper bound is inclusive (default True) iv_range_min float Implied volatility lower bound (%) iv_range_max float Implied volatility upper bound (%) iv_min_inclusive bool Whether IV lower bound is inclusive (default True) iv_max_inclusive bool Whether IV upper bound is inclusive (default True) earnings_date_begin str Earnings date filter start date (yyyy-MM-dd) earnings_date_end str Earnings date filter end date (yyyy-MM-dd) note str Note (max 20 characters)
Monitoring scope:
option_market,watchlist_group_name, andunderlyingare mutually exclusive. One must be set when adding a new alert.Returns
Parameter Type Description ret RET_CODE Interface call result data str When ret == RET_OK, returns empty string str When ret != RET_OK, returns error description Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Add an alert: monitor US stock option market CALL sweeps, volume > 100 (exclusive)
item = OptionEventAlertItem(
option_market=OptionMarket.US_SECURITY,
option_type=OptionType.CALL,
order_type_list=[AlertOrderType.SWEEP],
size_range_min=100,
size_min_inclusive=False,
note='test'
)
ret, data = quote_ctx.set_option_event_alert(AlertOpType.ADD, item)
if ret == RET_OK:
print('Added successfully')
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- Output
Added successfully
# Qot_SetOptionEventAlert.proto
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
uint SetOptionEventAlert(Qot_SetOptionEventAlert.Request req); virtual void OnReply_SetOptionEventAlert(FTAPI_Conn client, uint nSerialNo, Qot_SetOptionEventAlert.Response rsp);
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
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)
{
if (errCode != 0) return;
var c2s = Qot_SetOptionEventAlert.C2S.CreateBuilder()
// TODO: fill c2s fields per proto
.Build();
var req = Qot_SetOptionEventAlert.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SetOptionEventAlert(req);
Console.Write("Send SetOptionEventAlert: {0}\n", seqNo);
}
public void OnReply_SetOptionEventAlert(FTAPI_Conn client, uint nSerialNo, Qot_SetOptionEventAlert.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
FTAPI.Init();
new Program().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
- Output
Send SetOptionEventAlert: 1
Reply: 1 SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
3
int setOptionEventAlert(Qot_SetOptionEventAlert.Request req) onReply_SetOptionEventAlert(FTAPI_Conn client, int nSerialNo, Qot_SetOptionEventAlert.Response rsp)
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
Example
public class Program implements FTSPI_Qot, FTSPI_Conn {
private FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
Qot_SetOptionEventAlert.C2S c2s = Qot_SetOptionEventAlert.C2S.newBuilder()
// TODO: fill c2s fields per proto
.build();
Qot_SetOptionEventAlert.Request req = Qot_SetOptionEventAlert.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.setOptionEventAlert(req);
System.out.println("Send setOptionEventAlert: " + seqNo);
}
@Override
public void onReply_SetOptionEventAlert(FTAPI_Conn client, int nSerialNo, Qot_SetOptionEventAlert.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
FTAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
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
- Output
Send setOptionEventAlert: 1
Reply: 1 SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
3
Futu::u32_t SetOptionEventAlert(const Qot_SetOptionEventAlert::Request &stReq);
virtual void OnReply_SetOptionEventAlert(Futu::u32_t nSerialNo, const Qot_SetOptionEventAlert::Response &stRsp) = 0;
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
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_SetOptionEventAlert::Request req;
Qot_SetOptionEventAlert::C2S *c2s = req.mutable_c2s();
// TODO: 按 proto 填充 c2s 字段
m_SetOptionEventAlertSerialNo = m_pQotApi->SetOptionEventAlert(req);
}
virtual void OnReply_SetOptionEventAlert(Futu::u32_t nSerialNo, const Qot_SetOptionEventAlert::Response &stRsp) {
if (nSerialNo != m_SetOptionEventAlertSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_SetOptionEventAlertSerialNo = 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
setOptionEventAlert(qotSetOptionEventAlert)
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common, Qot_OptionCommon, Qot_GetOptionEvent, Qot_SetOptionEventAlert } from "futu-api/proto";
import beautify from "js-beautify";
function QotSetOptionEventAlert(){
const { RetType } = Common
const { OptionMarket } = Qot_OptionCommon
const { OptionType } = Qot_Common
const { OptionOrderType } = Qot_GetOptionEvent
const { AlertOpType } = Qot_SetOptionEventAlert
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 新增一个异动告警:监控美股股票期权市场的 CALL 扫单,成交量 >= 100
const req = {
c2s: {
operType: AlertOpType.AlertOpType_Add,
alertList: [
{
optionMarket: OptionMarket.OptionMarket_US_Security,
optionType: OptionType.OptionType_Call,
orderTypeList: [OptionOrderType.OptionOrderType_Sweep],
sizeRange: { filterMin: { value: 100, includes: true } },
note: "test",
}
],
},
};
websocket.SetOptionEventAlert(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("SetOptionEventAlert: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
console.log("新增成功");
}
})
.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);
}
QotSetOptionEventAlert()
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
SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
Rate Limit
- Maximum 60 requests per 30 seconds for the set option event alert interface
- Python
- Proto
- C#
- Java
- C++
- JavaScript
set_option_event_alert(op, alert_list=None)
Description
Add, modify, delete, or enable/disable option unusual activity alerts.
Parameters
Parameter Type Description op AlertOpType Operation type ADD=Add, DELETE=Delete, MODIFY=Modify, ENABLE=Enable, DISABLE=Disable, DELETE_ALL=Delete allalert_list OptionEventAlertItem or list[OptionEventAlertItem] Alert item(s) Do not pass key when adding, key is required when modifying/deletingOptionEventAlertItem fields:
Field Type Description key int Alert unique identifier (required for modify/delete/enable/disable) enable bool Alert switch option_market OptionMarket Option market to monitor (one of three) watchlist_group_name str Watchlist group name (one of three) underlying str Specified underlying code, e.g. 'US.AAPL'(one of three)option_type OptionType Option type (CALL/PUT) side_type_list list[EventTickerType] Trade direction list order_type_list list[AlertOrderType] Order type list market_cap_range_min float Underlying market cap lower bound market_cap_range_max float Underlying market cap upper bound market_cap_min_inclusive bool Whether market cap lower bound is inclusive (default True) market_cap_max_inclusive bool Whether market cap upper bound is inclusive (default True) expiry_days_range_min float Days to expiration lower bound expiry_days_range_max float Days to expiration upper bound expiry_days_min_inclusive bool Whether days to expiration lower bound is inclusive (default True) expiry_days_max_inclusive bool Whether days to expiration upper bound is inclusive (default True) price_range_min float Event fill price lower bound price_range_max float Event fill price upper bound price_min_inclusive bool Whether fill price lower bound is inclusive (default True) price_max_inclusive bool Whether fill price upper bound is inclusive (default True) size_range_min float Event volume lower bound (contracts) size_range_max float Event volume upper bound (contracts) size_min_inclusive bool Whether volume lower bound is inclusive (default True) size_max_inclusive bool Whether volume upper bound is inclusive (default True) premium_range_min float Event turnover lower bound premium_range_max float Event turnover upper bound premium_min_inclusive bool Whether turnover lower bound is inclusive (default True) premium_max_inclusive bool Whether turnover upper bound is inclusive (default True) iv_range_min float Implied volatility lower bound (%) iv_range_max float Implied volatility upper bound (%) iv_min_inclusive bool Whether IV lower bound is inclusive (default True) iv_max_inclusive bool Whether IV upper bound is inclusive (default True) earnings_date_begin str Earnings date filter start date (yyyy-MM-dd) earnings_date_end str Earnings date filter end date (yyyy-MM-dd) note str Note (max 20 characters)
Monitoring scope:
option_market,watchlist_group_name, andunderlyingare mutually exclusive. One must be set when adding a new alert.Returns
Parameter Type Description ret RET_CODE Interface call result data str When ret == RET_OK, returns empty string str When ret != RET_OK, returns error description Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Add an alert: monitor US stock option market CALL sweeps, volume > 100 (exclusive)
item = OptionEventAlertItem(
option_market=OptionMarket.US_SECURITY,
option_type=OptionType.CALL,
order_type_list=[AlertOrderType.SWEEP],
size_range_min=100,
size_min_inclusive=False,
note='test'
)
ret, data = quote_ctx.set_option_event_alert(AlertOpType.ADD, item)
if ret == RET_OK:
print('Added successfully')
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- Output
Added successfully
# Qot_SetOptionEventAlert.proto
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
uint SetOptionEventAlert(Qot_SetOptionEventAlert.Request req); virtual void OnReply_SetOptionEventAlert(MMAPI_Conn client, uint nSerialNo, Qot_SetOptionEventAlert.Response rsp);
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
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)
{
if (errCode != 0) return;
var c2s = Qot_SetOptionEventAlert.C2S.CreateBuilder()
// TODO: fill c2s fields per proto
.Build();
var req = Qot_SetOptionEventAlert.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SetOptionEventAlert(req);
Console.Write("Send SetOptionEventAlert: {0}\n", seqNo);
}
public void OnReply_SetOptionEventAlert(MMAPI_Conn client, uint nSerialNo, Qot_SetOptionEventAlert.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
MMAPI.Init();
new Program().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
- Output
Send SetOptionEventAlert: 1
Reply: 1 SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
3
int setOptionEventAlert(Qot_SetOptionEventAlert.Request req) onReply_SetOptionEventAlert(MMAPI_Conn client, int nSerialNo, Qot_SetOptionEventAlert.Response rsp)
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
Example
public class Program implements MMSPI_Qot, MMSPI_Conn {
private MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
Qot_SetOptionEventAlert.C2S c2s = Qot_SetOptionEventAlert.C2S.newBuilder()
// TODO: fill c2s fields per proto
.build();
Qot_SetOptionEventAlert.Request req = Qot_SetOptionEventAlert.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.setOptionEventAlert(req);
System.out.println("Send setOptionEventAlert: " + seqNo);
}
@Override
public void onReply_SetOptionEventAlert(MMAPI_Conn client, int nSerialNo, Qot_SetOptionEventAlert.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
MMAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
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
- Output
Send setOptionEventAlert: 1
Reply: 1 SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
3
Moomoo::u32_t SetOptionEventAlert(const Qot_SetOptionEventAlert::Request &stReq);
virtual void OnReply_SetOptionEventAlert(Moomoo::u32_t nSerialNo, const Qot_SetOptionEventAlert::Response &stRsp) = 0;
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
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_SetOptionEventAlert::Request req;
Qot_SetOptionEventAlert::C2S *c2s = req.mutable_c2s();
// TODO: 按 proto 填充 c2s 字段
m_SetOptionEventAlertSerialNo = m_pQotApi->SetOptionEventAlert(req);
}
virtual void OnReply_SetOptionEventAlert(Moomoo::u32_t nSerialNo, const Qot_SetOptionEventAlert::Response &stRsp) {
if (nSerialNo != m_SetOptionEventAlertSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
Moomoo::u32_t m_SetOptionEventAlertSerialNo = 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
setOptionEventAlert(qotSetOptionEventAlert)
Description
Add, modify, delete, or enable/disable option unusual activity alerts
Parameters
enum AlertOpType {
AlertOpType_Unknown = 0;
AlertOpType_Add = 1;
AlertOpType_Delete = 2;
AlertOpType_Modify = 3;
AlertOpType_Enable = 4;
AlertOpType_Disable = 5;
AlertOpType_DeleteAll = 6;
}
message C2S {
required int32 operType = 1;
repeated Qot_GetOptionEventAlert.EventAlertItem alertList = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- Returns
message S2C {
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, cyclic result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
- Interface call result, see RetType
Protocol ID
3309
Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common, Qot_OptionCommon, Qot_GetOptionEvent, Qot_SetOptionEventAlert } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotSetOptionEventAlert(){
const { RetType } = Common
const { OptionMarket } = Qot_OptionCommon
const { OptionType } = Qot_Common
const { OptionOrderType } = Qot_GetOptionEvent
const { AlertOpType } = Qot_SetOptionEventAlert
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 新增一个异动告警:监控美股股票期权市场的 CALL 扫单,成交量 >= 100
const req = {
c2s: {
operType: AlertOpType.AlertOpType_Add,
alertList: [
{
optionMarket: OptionMarket.OptionMarket_US_Security,
optionType: OptionType.OptionType_Call,
orderTypeList: [OptionOrderType.OptionOrderType_Sweep],
sizeRange: { filterMin: { value: 100, includes: true } },
note: "test",
}
],
},
};
websocket.SetOptionEventAlert(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("SetOptionEventAlert: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
console.log("新增成功");
}
})
.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);
}
QotSetOptionEventAlert()
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
SetOptionEventAlert: errCode 0, retMsg , retType 0
新增成功
2
Rate Limit
- Maximum 60 requests per 30 seconds for the set option event alert interface