# オプション異常変動プッシュ
- 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
Example: サンプルは提供していません(Qot_RegQotPush 登録後にプッシュを受信)
Output
Push: {
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
2
3
4
5
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
Example: サンプルは提供していません(Qot_RegQotPush 登録後にプッシュを受信)
Output
Push: {
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
2
3
4
5
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
Example: サンプルは提供していません(Qot_RegQotPush 登録後にプッシュを受信)
Output
Push: {
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
2
3
4
5
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
Example: サンプルは提供していません(Qot_RegQotPush 登録後にプッシュを受信)
Output
Push: {
"owner": { "market": 1, "code": "TSLA" },
"option": { "market": 1, "code": "TSLA250620C250" },
"message": "TSLA $250 Call 06/20 大额扫单 500张 成交价$12.50"
}
2
3
4
5
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