# 期权异动推送
- Python
- Proto
- C#
- Java
- C++
- JavaScript
class OptionEventHandlerBase(RspHandlerBase)
介绍
接收期权异动推送,当设置的异动提醒被触发时,服务端会主动推送异动信息。需先通过
set_option_event_alert设置提醒条件,并通过 handler 注册回调。用户继承OptionEventHandlerBase并重写on_recv_rsp方法来接收推送。参数
on_recv_rsp 回调返回 (ret_code, content),content 为 dict:
参数 类型 说明 owner_code str 标的代码(如 'US.TSLA') option_code str 期权合约代码(如 'US.TSLA250620C250') message str 推送消息文本 Example
from futu import *
class OptionEventHandler(OptionEventHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(OptionEventHandler, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("OptionEvent error:", content)
return RET_ERROR, content
print("收到期权异动推送:")
print(" 标的:", content['owner_code'])
print(" 期权:", content['option_code'])
print(" 消息:", content['message'])
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 注册期权异动推送处理器
quote_ctx.set_handler(OptionEventHandler())
# 需要先通过 set_option_event_alert 设置提醒条件,推送才会触发
item = OptionEventAlertItem(
option_market=OptionMarket.US_SECURITY,
option_type=OptionType.CALL,
order_type_list=[AlertOrderType.SWEEP],
size_range_min=100,
)
ret, data = quote_ctx.set_option_event_alert(AlertOpType.ADD, item)
if ret == RET_OK:
print('提醒设置成功,等待推送...')
else:
print('设置失败:', data)
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
quote_ctx.close()
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
- Output
收到期权异动推送:
标的: US.TSLA
期权: US.TSLA250620C250
消息: TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50
2
3
4
# Qot_UpdateOptionEvent.proto
介绍
期权异动推送(服务端主动推送,无需客户端请求)
返回
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
virtual void OnPush_UpdateOptionEvent(FTAPI_Conn client, uint nSerialNo, Qot_UpdateOptionEvent.Response rsp);
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
onPush_UpdateOptionEvent(FTAPI_Conn client, int nSerialNo, Qot_UpdateOptionEvent.Response rsp)
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
virtual void OnPush_UpdateOptionEvent(const Qot_UpdateOptionEvent::Response &stRsp) = 0;
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- 返回
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
Example: 暂不提供示例(由 Qot_RegQotPush 注册后被动接收推送)
onPush_UpdateOptionEvent(qotUpdateOptionEvent)
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotUpdateOptionEvent(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11112, false, ''];
let websocket = new ftWebsocket();
// 需要已通过 SetOptionEventAlert 设置期权异动提醒,推送才会触发
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdateOptionEvent.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("UpdateOptionEvent:");
console.log(data);
} else {
console.log("UpdateOptionEvent: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000);
}
QotUpdateOptionEvent()
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
UpdateOptionEvent:
{
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
stop
2
3
4
5
6
7
- Python
- Proto
- C#
- Java
- C++
- JavaScript
class OptionEventHandlerBase(RspHandlerBase)
介绍
接收期权异动推送,当设置的异动提醒被触发时,服务端会主动推送异动信息。需先通过
set_option_event_alert设置提醒条件,并通过 handler 注册回调。用户继承OptionEventHandlerBase并重写on_recv_rsp方法来接收推送。参数
on_recv_rsp 回调返回 (ret_code, content),content 为 dict:
参数 类型 说明 owner_code str 标的代码(如 'US.TSLA') option_code str 期权合约代码(如 'US.TSLA250620C250') message str 推送消息文本 Example
from moomoo import *
class OptionEventHandler(OptionEventHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(OptionEventHandler, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("OptionEvent error:", content)
return RET_ERROR, content
print("收到期权异动推送:")
print(" 标的:", content['owner_code'])
print(" 期权:", content['option_code'])
print(" 消息:", content['message'])
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 注册期权异动推送处理器
quote_ctx.set_handler(OptionEventHandler())
# 需要先通过 set_option_event_alert 设置提醒条件,推送才会触发
item = OptionEventAlertItem(
option_market=OptionMarket.US_SECURITY,
option_type=OptionType.CALL,
order_type_list=[AlertOrderType.SWEEP],
size_range_min=100,
)
ret, data = quote_ctx.set_option_event_alert(AlertOpType.ADD, item)
if ret == RET_OK:
print('提醒设置成功,等待推送...')
else:
print('设置失败:', data)
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
quote_ctx.close()
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
- Output
收到期权异动推送:
标的: US.TSLA
期权: US.TSLA250620C250
消息: TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50
2
3
4
# Qot_UpdateOptionEvent.proto
介绍
期权异动推送(服务端主动推送,无需客户端请求)
返回
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
virtual void OnPush_UpdateOptionEvent(MMAPI_Conn client, uint nSerialNo, Qot_UpdateOptionEvent.Response rsp);
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
onPush_UpdateOptionEvent(MMAPI_Conn client, int nSerialNo, Qot_UpdateOptionEvent.Response rsp)
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
virtual void OnPush_UpdateOptionEvent(const Qot_UpdateOptionEvent::Response &stRsp) = 0;
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- 返回
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
Example: 暂不提供示例(由 Qot_RegQotPush 注册后被动接收推送)
onPush_UpdateOptionEvent(qotUpdateOptionEvent)
介绍
期权异动推送回调
参数
message S2C
{
optional Qot_Common.Security owner = 1; //标的
optional Qot_Common.Security option = 2; //期权合约
optional string message = 3; //推送消息文本
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
协议 ID
3310
Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotUpdateOptionEvent(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11112, false, ''];
let websocket = new mmWebsocket();
// 需要已通过 SetOptionEventAlert 设置期权异动提醒,推送才会触发
websocket.onPush = (cmd, res)=>{
if(mmCmdID.QotUpdateOptionEvent.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("UpdateOptionEvent:");
console.log(data);
} else {
console.log("UpdateOptionEvent: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 3600 * 1000);
}
QotUpdateOptionEvent()
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
UpdateOptionEvent:
{
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
stop
2
3
4
5
6
7