# 期權異動推送
- 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