# Get Option Strategy
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_strategy(code, option_strategy, expire_time, spread=None, far_expire_time=None, index_option_type=IndexOptionType.NORMAL, option_type=OptionType.ALL, strike_price=None)
Description
Query option chain legs by strategy type. Supports vertical spread, straddle, collar, butterfly, and other standard strategies.
Parameters
Parameter Type Description code str Underlying stock code 如 US.AAPL、HK.00700option_strategy OptionStrategyType Option strategy type expire_time str Expiration date Format: yyyy-MM-dd, in market timezone; required for Calendar spread and Diagonal spreadspread float Spread Required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spreadfar_expire_time str Far expiration date Format: yyyy-MM-dd; required for Calendar spread and Diagonal spreadindex_option_type IndexOptionType Index option type Only effective for HK index option filteringoption_type OptionType Option call/put type Default: allstrike_price float Strike price Required parameters by strategy type:
- expire_time Required for:
CALENDAR_SPREAD(Calendar spread)、DIAGONAL_SPREAD(Diagonal spread) - spread Required for:
SPREAD(Vertical spread)、STRANGLE(Strangle)、COLLAR(Collar)、BUTTERFLY(Butterfly)、CONDOR(Condor)、IRON_BUTTERFLY(Iron butterfly)、IRON_CONDOR(Iron condor)、DIAGONAL_SPREAD(Diagonal spread) - far_expire_time Required for:
CALENDAR_SPREAD(Calendar spread)、DIAGONAL_SPREAD(Diagonal spread)
- expire_time Required for:
Return
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns strategy list data str When ret != RET_OK, returns error description DataFrame fields:
Field Type Description code str Strategy identifier code name str Strategy name option_strategy str Option strategy type 如 STRADDLEstock_owner str Underlying stock legs list Combo leg list Elements are OptionStrategyLegOptionStrategyLeg fields:
Field Type Description code str Option contract code action str Buy/sell direction BUY / SELLquantity float Quantity
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret,data = quote_ctx.get_option_strategy(code='HK.00700', option_strategy=OptionStrategyType.STRADDLE)
if ret == RET_OK:
print(data)
print(data['legs'][0])
else:
print('error:', data)
quote_ctx.close() # Remember to close the connection to avoid exhausting connection quota
2
3
4
5
6
7
8
9
10
- Output
code name option_strategy stock_owner legs
0 TCH260522C/P330 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
1 TCH260522C/P340 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P340000, a...
2 TCH260522C/P350 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P350000, a...
...
26 TCH260522C/P590 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P590000, a...
[OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
2
3
4
5
6
7
# Qot_GetOptionStrategy.proto
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
uint GetOptionStrategy(QotGetOptionStrategy.Request req);
virtual void OnReply_GetOptionStrategy(FTAPI_Conn client, uint nSerialNo, QotGetOptionStrategy.Response rsp);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- 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)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security owner = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetOptionStrategy.C2S c2s = QotGetOptionStrategy.C2S.CreateBuilder()
.SetOwner(owner)
.SetOptionStrategy((int)QotCommon.OptionStrategyType.OptionStrategyType_Straddle)
.Build();
QotGetOptionStrategy.Request req = QotGetOptionStrategy.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionStrategy(req);
Console.Write("Send QotGetOptionStrategy: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode)
{
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionStrategy(FTAPI_Conn client, uint nSerialNo, QotGetOptionStrategy.Response rsp)
{
Console.Write("Reply: QotGetOptionStrategy: {0} {1}\n", nSerialNo, rsp.ToString());
}
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
- Output
connect
Request GetOptionStrategy SerialNo: 3
OnReply_GetOptionStrategy SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int getOptionStrategy(QotGetOptionStrategy.Request req);
void onReply_GetOptionStrategy(FTAPI_Conn client, int nSerialNo, QotGetOptionStrategy.Response rsp);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1);
qot.setConnSpi(this);
qot.setQotSpi(this);
}
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;
QotCommon.Security owner = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetOptionStrategy.C2S c2s = QotGetOptionStrategy.C2S.newBuilder()
.setOwner(owner)
.setOptionStrategy(QotCommon.OptionStrategyType.OptionStrategyType_Straddle_VALUE)
.build();
QotGetOptionStrategy.Request req = QotGetOptionStrategy.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionStrategy(req);
System.out.printf("Send QotGetOptionStrategy: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionStrategy(FTAPI_Conn client, int nSerialNo, QotGetOptionStrategy.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionStrategy failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionStrategy: %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
56
57
58
59
60
61
62
63
64
65
66
67
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionStrategy: 2
Receive QotGetOptionStrategy: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Futu::u32_t GetOptionStrategy(const Qot_GetOptionStrategy::Request &stReq);
virtual void OnReply_GetOptionStrategy(Futu::u32_t nSerialNo, const Qot_GetOptionStrategy::Response &stRsp) = 0;
Description
Get option strategy data. Given the underlying stock and an option strategy type, returns the candidate combo strategies under that underlying. Each strategy contains a list of combo legs
multi_legsthat can be fed directly into Get Option Combo Quote.Parameters
message C2S
{
required Qot_Common.Security owner = 1; //Underlying stock
required int32 option_strategy = 2; //OptionStrategyType, option strategy type
optional string expire_time = 3; //Near-leg expiration date, format yyyy-MM-dd
optional string far_expire_time = 4; //Far-leg expiration date, format yyyy-MM-dd (required for calendar-spread strategies)
optional double spread = 5; //Spread, expressed as a percentage of the underlying price (required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread)
optional int32 option_type = 6; //OptionType, Call/Put (required for single-direction strategies)
optional double strike_price = 7; //Strike price (required for protective strategies)
optional int32 index_option_type = 8; //IndexOptionType, index option type
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- OptionType enum: OptionType
- IndexOptionType enum: IndexOptionType
- Return
message OptionStrategyItem
{
required string code = 1; //Combo strategy code
required string name = 2; //Combo strategy name
required int32 option_strategy = 3; //OptionStrategyType, combo strategy type
required Qot_Common.Security stock_owner = 4; //Underlying stock
repeated Qot_Common.ComboLeg multi_legs = 5; //Combo sub-order list (actual leg qty = outer qty * leg.qty_ratio)
}
message S2C
{
repeated OptionStrategyItem strategyList = 1; //Option strategy combo list
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- 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;
// Build request
Qot_GetOptionStrategy::Request req;
Qot_GetOptionStrategy::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *owner = c2s->mutable_owner();
owner->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
owner->set_code("00700");
c2s->set_option_strategy(Qot_Common::OptionStrategyType_Straddle); // Straddle strategy
m_GetOptionStrategySerialNo = m_pQotApi->GetOptionStrategy(req);
cout << "Request GetOptionStrategy SerialNo: " << m_GetOptionStrategySerialNo << endl;
}
virtual void OnReply_GetOptionStrategy(Futu::u32_t nSerialNo, const Qot_GetOptionStrategy::Response &stRsp) {
if (nSerialNo != m_GetOptionStrategySerialNo) return;
cout << "OnReply_GetOptionStrategy SerialNo: " << nSerialNo << endl;
// Parse the internal structure and print
// ProtoBufToBodyData and UTF8ToLocal are defined in tool.h under Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetOptionStrategySerialNo = 0;
};
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
- Output
connect
Request GetOptionStrategy SerialNo: 3
OnReply_GetOptionStrategy SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
GetOptionStrategy(req);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security owner = 1; //Underlying stock; only HK/US stocks and HSI/HSCEI supported
required int32 option_strategy = 2; //OptionStrategyType, option strategy type
optional string expire_time = 3; //Expiry (near), yyyy-MM-dd; empty means no filter
optional string far_expire_time = 4; //Far expiry, used for DiagonalSpread
optional double spread = 5; //Spread filter; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional int32 option_type = 6; //OptionType; empty returns all
optional double strike_price = 7; //Strike filter; empty returns all
optional int32 index_option_type = 8; //IndexOptionType; only for HSI/HSCEI
optional Qot_Common.QotHeader header = 100; //Quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
- Return
message OptionStrategyItem
{
required string code = 1; //Combo strategy code
required string name = 2; //Combo strategy name
required int32 option_strategy = 3; //OptionStrategyType, combo strategy type
required Qot_Common.Security stock_owner = 4; //Underlying stock
repeated Qot_Common.ComboLeg multi_legs = 5; //Combo sub-order list
}
message S2C
{
repeated OptionStrategyItem strategyList = 1; //Option strategy combo list
}
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
15
16
17
18
19
20
21
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetOptionStrategy(){
const { RetType } = Common
const { QotMarket, OptionStrategyType } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登录成功
const req = {
c2s: {
owner: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
optionStrategy: OptionStrategyType.OptionStrategyType_Straddle, // 跨式策略
},
};
websocket.GetOptionStrategy(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionStrategy: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//关闭行情连接,连接不再使用之后,要关闭,否则占用不必要资源
//同时OpenD也限制了最多128条连接
//也可以一个页面或者一个项目维护一条连接,这里范例请求一次创建一条连接
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 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
41
42
43
44
45
46
47
48
49
50
- Output
GetOptionStrategy: errCode 0, retMsg , retType 0
{
"strategyList": [{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": {
"market": 1,
"code": "00700"
},
"multiLegs": [{
"security": { "market": 1, "code": "TCH260522P330000" },
"side": 1,
"qtyRatio": 1
}, {
"security": { "market": 1, "code": "TCH260522C330000" },
"side": 1,
"qtyRatio": 1
}]
}, ...]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
API Restrictions
- Maximum 30 requests per 30 seconds.
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_strategy(code, option_strategy, expire_time, spread=None, far_expire_time=None, index_option_type=IndexOptionType.NORMAL, option_type=OptionType.ALL, strike_price=None)
Description
Query option chain legs by strategy type. Supports vertical spread, straddle, collar, butterfly, and other standard strategies.
Parameters
Parameter Type Description code str Underlying stock code 如 US.AAPL、HK.00700option_strategy OptionStrategyType Option strategy type expire_time str Expiration date Format: yyyy-MM-dd, in market timezone; required for Calendar spread and Diagonal spreadspread float Spread Required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spreadfar_expire_time str Far expiration date Format: yyyy-MM-dd; required for Calendar spread and Diagonal spreadindex_option_type IndexOptionType Index option type Only effective for HK index option filteringoption_type OptionType Option call/put type Default: allstrike_price float Strike price Required parameters by strategy type:
- expire_time Required for:
CALENDAR_SPREAD(Calendar spread)、DIAGONAL_SPREAD(Diagonal spread) - spread Required for:
SPREAD(Vertical spread)、STRANGLE(Strangle)、COLLAR(Collar)、BUTTERFLY(Butterfly)、CONDOR(Condor)、IRON_BUTTERFLY(Iron butterfly)、IRON_CONDOR(Iron condor)、DIAGONAL_SPREAD(Diagonal spread) - far_expire_time Required for:
CALENDAR_SPREAD(Calendar spread)、DIAGONAL_SPREAD(Diagonal spread)
- expire_time Required for:
Return
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns strategy list data str When ret != RET_OK, returns error description DataFrame fields:
Field Type Description code str Strategy identifier code name str Strategy name option_strategy str Option strategy type 如 STRADDLEstock_owner str Underlying stock legs list Combo leg list Elements are OptionStrategyLegOptionStrategyLeg fields:
Field Type Description code str Option contract code action str Buy/sell direction BUY / SELLquantity float Quantity
Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret,data = quote_ctx.get_option_strategy(code='HK.00700', option_strategy=OptionStrategyType.STRADDLE)
if ret == RET_OK:
print(data)
print(data['legs'][0])
else:
print('error:', data)
quote_ctx.close() # Remember to close the connection to avoid exhausting connection quota
2
3
4
5
6
7
8
9
10
- Output
code name option_strategy stock_owner legs
0 TCH260522C/P330 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
1 TCH260522C/P340 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P340000, a...
2 TCH260522C/P350 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P350000, a...
...
26 TCH260522C/P590 Tencent Straddle STRADDLE HK.00700 [OptionStrategyLeg(code=HK.TCH260522P590000, a...
[OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
2
3
4
5
6
7
# Qot_GetOptionStrategy.proto
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
uint GetOptionStrategy(QotGetOptionStrategy.Request req);
virtual void OnReply_GetOptionStrategy(MMAPI_Conn client, uint nSerialNo, QotGetOptionStrategy.Response rsp);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- 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)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security owner = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetOptionStrategy.C2S c2s = QotGetOptionStrategy.C2S.CreateBuilder()
.SetOwner(owner)
.SetOptionStrategy((int)QotCommon.OptionStrategyType.OptionStrategyType_Straddle)
.Build();
QotGetOptionStrategy.Request req = QotGetOptionStrategy.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionStrategy(req);
Console.Write("Send QotGetOptionStrategy: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode)
{
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionStrategy(MMAPI_Conn client, uint nSerialNo, QotGetOptionStrategy.Response rsp)
{
Console.Write("Reply: QotGetOptionStrategy: {0} {1}\n", nSerialNo, rsp.ToString());
}
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
- Output
connect
Request GetOptionStrategy SerialNo: 3
OnReply_GetOptionStrategy SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int getOptionStrategy(QotGetOptionStrategy.Request req);
void onReply_GetOptionStrategy(MMAPI_Conn client, int nSerialNo, QotGetOptionStrategy.Response rsp);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Underlying stock
required Qot_Common.OptionStrategyType optionStrategy = 2; // Option strategy type
required string expireTime = 3; // Expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional double spread = 4; // Spread; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional string farExpireTime = 5; // Far expiration date, format yyyy-MM-dd; required for Calendar spread and Diagonal spread
optional Qot_Common.IndexOptionType indexOptionType = 6; // Index option type
optional Qot_Common.OptionType optionType = 7; // Option type
optional double strikePrice = 8; // Strike price
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
* Some parameters are required by strategy type:
* **expireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **spread** Required for: `OptionStrategyType_Spread` (Vertical spread), `OptionStrategyType_Strangle` (Strangle), `OptionStrategyType_Collar` (Collar), `OptionStrategyType_Butterfly` (Butterfly), `OptionStrategyType_Condor` (Condor), `OptionStrategyType_IronButterfly` (Iron butterfly), `OptionStrategyType_IronCondor` (Iron condor), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
* **farExpireTime** Required for: `OptionStrategyType_CalendarSpread` (Calendar spread), `OptionStrategyType_DiagonalSpread` (Diagonal spread)
- Return
message OptionStrategyLeg
{
optional string code = 1; // Option contract code
optional int32 action = 2; // Buy/sell direction,详见 TrdSide
optional double quantity = 3; // Quantity
}
message OptionStrategyItem
{
optional string code = 1; // Strategy identifier code
optional string name = 2; // Strategy name
optional Qot_Common.OptionStrategyType optionStrategy = 3; // Option strategy type
optional string stockOwner = 4; // Underlying stock
repeated OptionStrategyLeg legs = 5; // Combo leg list
}
message S2C
{
repeated OptionStrategyItem itemList = 1; // Strategy list
}
message Response
{
required int32 retType = 1 [default = -400]; // Return result,详见 Common.RetType
optional string retMsg = 2; // Return result description
optional int32 errCode = 3; // Error code
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1);
qot.setConnSpi(this);
qot.setQotSpi(this);
}
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;
QotCommon.Security owner = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetOptionStrategy.C2S c2s = QotGetOptionStrategy.C2S.newBuilder()
.setOwner(owner)
.setOptionStrategy(QotCommon.OptionStrategyType.OptionStrategyType_Straddle_VALUE)
.build();
QotGetOptionStrategy.Request req = QotGetOptionStrategy.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionStrategy(req);
System.out.printf("Send QotGetOptionStrategy: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionStrategy(MMAPI_Conn client, int nSerialNo, QotGetOptionStrategy.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionStrategy failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionStrategy: %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
56
57
58
59
60
61
62
63
64
65
66
67
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionStrategy: 2
Receive QotGetOptionStrategy: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
moomoo::u32_t GetOptionStrategy(const Qot_GetOptionStrategy::Request &stReq);
virtual void OnReply_GetOptionStrategy(moomoo::u32_t nSerialNo, const Qot_GetOptionStrategy::Response &stRsp) = 0;
Description
Get option strategy data. Given the underlying stock and an option strategy type, returns the candidate combo strategies under that underlying. Each strategy contains a list of combo legs
multi_legsthat can be fed directly into Get Option Combo Quote.Parameters
message C2S
{
required Qot_Common.Security owner = 1; //Underlying stock
required int32 option_strategy = 2; //OptionStrategyType, option strategy type
optional string expire_time = 3; //Near-leg expiration date, format yyyy-MM-dd
optional string far_expire_time = 4; //Far-leg expiration date, format yyyy-MM-dd (required for calendar-spread strategies)
optional double spread = 5; //Spread, expressed as a percentage of the underlying price (required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread)
optional int32 option_type = 6; //OptionType, Call/Put (required for single-direction strategies)
optional double strike_price = 7; //Strike price (required for protective strategies)
optional int32 index_option_type = 8; //IndexOptionType, index option type
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- OptionType enum: OptionType
- IndexOptionType enum: IndexOptionType
- Return
message OptionStrategyItem
{
required string code = 1; //Combo strategy code
required string name = 2; //Combo strategy name
required int32 option_strategy = 3; //OptionStrategyType, combo strategy type
required Qot_Common.Security stock_owner = 4; //Underlying stock
repeated Qot_Common.ComboLeg multi_legs = 5; //Combo sub-order list (actual leg qty = outer qty * leg.qty_ratio)
}
message S2C
{
repeated OptionStrategyItem strategyList = 1; //Option strategy combo list
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
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
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- 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;
// Build request
Qot_GetOptionStrategy::Request req;
Qot_GetOptionStrategy::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *owner = c2s->mutable_owner();
owner->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
owner->set_code("00700");
c2s->set_option_strategy(Qot_Common::OptionStrategyType_Straddle); // Straddle strategy
m_GetOptionStrategySerialNo = m_pQotApi->GetOptionStrategy(req);
cout << "Request GetOptionStrategy SerialNo: " << m_GetOptionStrategySerialNo << endl;
}
virtual void OnReply_GetOptionStrategy(moomoo::u32_t nSerialNo, const Qot_GetOptionStrategy::Response &stRsp) {
if (nSerialNo != m_GetOptionStrategySerialNo) return;
cout << "OnReply_GetOptionStrategy SerialNo: " << nSerialNo << endl;
// Parse the internal structure and print
// ProtoBufToBodyData and UTF8ToLocal are defined in tool.h under Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetOptionStrategySerialNo = 0;
};
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
- Output
connect
Request GetOptionStrategy SerialNo: 3
OnReply_GetOptionStrategy SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"strategyList": [
{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": { "market": 1, "code": "00700" },
"multiLegs": [
{ "security": { "market": 1, "code": "TCH260522P330000" }, "side": 1, "qtyRatio": 1 },
{ "security": { "market": 1, "code": "TCH260522C330000" }, "side": 1, "qtyRatio": 1 }
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
GetOptionStrategy(req);
Description
Get option strategy data
Parameters
message C2S
{
required Qot_Common.Security owner = 1; //Underlying stock; only HK/US stocks and HSI/HSCEI supported
required int32 option_strategy = 2; //OptionStrategyType, option strategy type
optional string expire_time = 3; //Expiry (near), yyyy-MM-dd; empty means no filter
optional string far_expire_time = 4; //Far expiry, used for DiagonalSpread
optional double spread = 5; //Spread filter; required for Vertical spread, Strangle, Collar, Butterfly, Condor, Iron butterfly, Iron condor, and Diagonal spread
optional int32 option_type = 6; //OptionType; empty returns all
optional double strike_price = 7; //Strike filter; empty returns all
optional int32 index_option_type = 8; //IndexOptionType; only for HSI/HSCEI
optional Qot_Common.QotHeader header = 100; //Quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure: Security
- OptionStrategyType enum: OptionStrategyType
- IndexOptionType enum: IndexOptionType
- OptionType enum: OptionType
- Return
message OptionStrategyItem
{
required string code = 1; //Combo strategy code
required string name = 2; //Combo strategy name
required int32 option_strategy = 3; //OptionStrategyType, combo strategy type
required Qot_Common.Security stock_owner = 4; //Underlying stock
repeated Qot_Common.ComboLeg multi_legs = 5; //Combo sub-order list
}
message S2C
{
repeated OptionStrategyItem strategyList = 1; //Option strategy combo list
}
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
15
16
17
18
19
20
21
- API call result structure: RetType
- OptionStrategyType enum: OptionStrategyType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetOptionStrategy(){
const { RetType } = Common
const { QotMarket, OptionStrategyType } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登录成功
const req = {
c2s: {
owner: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
optionStrategy: OptionStrategyType.OptionStrategyType_Straddle, // 跨式策略
},
};
websocket.GetOptionStrategy(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionStrategy: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//关闭行情连接,连接不再使用之后,要关闭,否则占用不必要资源
//同时OpenD也限制了最多128条连接
//也可以一个页面或者一个项目维护一条连接,这里范例请求一次创建一条连接
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 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
41
42
43
44
45
46
47
48
49
50
- Output
GetOptionStrategy: errCode 0, retMsg , retType 0
{
"strategyList": [{
"code": "TCH260522C/P330",
"name": "腾讯 跨式策略",
"optionStrategy": 6,
"stockOwner": {
"market": 1,
"code": "00700"
},
"multiLegs": [{
"security": { "market": 1, "code": "TCH260522P330000" },
"side": 1,
"qtyRatio": 1
}, {
"security": { "market": 1, "code": "TCH260522C330000" },
"side": 1,
"qtyRatio": 1
}]
}, ...]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
API Restrictions
- Maximum 30 requests per 30 seconds.