# Get Market Snapshot
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_market_snapshot(code_list)
Description
Get market snapshot
Parameters
Parameter Type Description code_list list Stock list Up to 400 targets can be requested each time.
Data type of elements in the list is str.
Return
Field Type Description ret RET_CODE Interface result. data pd.DataFrame If ret == RET_OK, stock snapshot data is returned. str If ret != RET_OK, error description is returned. - Stock snapshot data format as follows:
Field Type Description code str Stock code. name str Stock name. update_time str Current update time. yyyy-MM-dd HH:mm:ss.
The default of HK stock market and A-share market is Beijing time, while that of US stock market is US Eastern time.last_price float Latest price. open_price float Open. high_price float High. low_price float Low. prev_close_price float Yesterday's close. volume int Volume. turnover float Turnover. turnover_rate float Turnover rate. This field is in percentage form, so 20 is equivalent to 20%.suspension bool Is suspended or not. True: suspension.listing_date str Listing date. yyyy-MM-ddequity_valid bool Is stock or not. The following equity-related fields will be legal only if this field is True.issued_shares int Total shares. total_market_val float Total market value. Unit: yuannet_asset int Net asset value. net_profit int Net profit. earning_per_share float Earnings per share. outstanding_shares int Shares outstanding. net_asset_per_share float Net assets per share. circular_market_val float Circulation market value. Unit: yuaney_ratio float Yield rate. This field is a ratio field, and % is not displayed.pe_ratio float P/E ratio. This field is a ratio field, and % is not displayed.pb_ratio float P/B ratio. This field is a ratio field, and % is not displayed.pe_ttm_ratio float P/E ratio TTM. This field is a ratio field, and % is not displayed.dividend_ttm float Dividend TTM, dividend. dividend_ratio_ttm float Dividend rate TTM. This field is in percentage form, so 20 is equivalent to 20%.dividend_lfy float Dividend LFY, dividend of the previous year. dividend_lfy_ratio float Dividend rate LFY. This field is in percentage form, so 20 is equivalent to 20%.stock_owner str The code of the underlying stock to which the warrant belongs or the code of the underlying stock of the option. wrt_valid bool Is warrant or not. The following warrant related fields will be legal if this field is True.wrt_conversion_ratio float Conversion ratio. wrt_type WrtType Warrant type. wrt_strike_price float Strike price. wrt_maturity_date str Maturity date. wrt_end_trade str Last trading time. wrt_leverage float Leverage ratio. Unit: timeswrt_ipop float in/out of the money. This field is in percentage form, so 20 is equivalent to 20%.wrt_break_even_point float Breakeven point. wrt_conversion_price float Conversion price. wrt_price_recovery_ratio float Price recovery ratio. This field is in percentage form, so 20 is equivalent to 20%.wrt_score float Comprehensive score of warrant. wrt_code str The underlying stock of the warrant (This field has been deprecated and changed to stock_owner.). wrt_recovery_price float Warrant recovery price. wrt_street_vol float Warrant Outstanding quantity. wrt_issue_vol float Warrant issuance. wrt_street_ratio float Outstanding percentage. This field is in percentage form, so 20 is equivalent to 20%.wrt_delta float Delta value of warrant. wrt_implied_volatility float Warrant implied volatility. wrt_premium float Warrant premium. This field is in percentage form, so 20 is equivalent to 20%.wrt_upper_strike_price float Upper bound price. Only Inline Warrant supports this field.wrt_lower_strike_price float lower bound price. Only Inline Warrant supports this field.wrt_inline_price_status PriceType in/out of bounds Only Inline Warrant supports this field.wrt_issuer_code str Issuer code. option_valid bool Is option or not. The following option related fields will be legal when this field is True.option_type OptionType Option type. strike_time str The option exercise date. Format: yyyy-MM-dd
The default of HK stock market and A-share market is Beijing time, while that of US stock market is US Eastern time.option_strike_price float Strike price. option_contract_size float Number of stocks per contract. option_open_interest int Total open contract number. option_implied_volatility float Implied volatility. option_premium float Premium. option_delta float Greek value Delta. option_gamma float Greek value Gamma. option_vega float Greek value Vega. option_theta float Greek value Theta. option_rho float Greek value Rho. index_option_type IndexOptionType Index option type. option_net_open_interest int Net open contract number. Only HK options support this field.option_expiry_date_distance int The number of days from the expiry date, a negative number means it has expired. option_contract_nominal_value float Contract nominal amount. Only HK options support this field.option_owner_lot_multiplier float Equal number of underlying stocks. Index options do not have this field, only HK options support this field.option_area_type OptionAreaType Option type (by exercise time). option_contract_multiplier float Contract multiplier. plate_valid bool Is plate or not. The following plate related fields will be legal when this field is True.plate_raise_count int Number of stocks that raises in the plate. plate_fall_count int Number of stocks that falls in the plate. plate_equal_count int Number of stocks that dose not change in price in the plate. index_valid bool Is index or not. The following index related fields will be legal when this field is True.index_raise_count int Number of stocks that raises in the plate. index_fall_count int Number of stocks that falls in the plate. index_equal_count int Number of stocks that dose not change in the plate. lot_size int The number of shares per lot, stock options represent the number of shares per contract Index options do not have this field.price_spread float The current upward price difference. That is, the quotation difference between ask price and sell 1.ask_price float Ask price. bid_price float Bid price. ask_vol float Ask volume. bid_vol float Bid volume. enable_margin bool Whether financing is available (Deprecated). Please use Get Margin Data.mortgage_ratio float Stock mortgage rate (Deprecated). long_margin_initial_ratio float The initial margin rate of financing (Deprecated). Please use Get Margin Data.enable_short_sell bool Whether short-selling is available (Deprecated). Please use Get Margin Data.short_sell_rate float Short-selling reference rate (Deprecated). Please use Get Margin Data.short_available_volume int Remaining quantity that can be sold short (Deprecated). Please use Get Margin Data.short_margin_initial_ratio float The initial margin rate for short selling (Deprecated). Please use Get Margin Data.sec_status SecurityStatus Stock status. amplitude float Amplitude. This field is in percentage form, so 20 is equivalent to 20%.avg_price float Average price. bid_ask_ratio float The Committee. This field is in percentage form, so 20 is equivalent to 20%.volume_ratio float Volume ratio. highest52weeks_price float Highest price in 52 weeks. lowest52weeks_price float Lowest price in 52 weeks . highest_history_price float Highest historical price. lowest_history_price float Lowest historical price. pre_price float Pre-market price. pre_high_price float Highest pre-market price. pre_low_price float Lowest pre-market price. pre_volume int Pre-market volume. pre_turnover float Pre-market turnover. pre_change_val float Pre-market change. pre_change_rate float Pre-market change rate. This field is in percentage form, so 20 is equivalent to 20%.pre_amplitude float Pre-market amplitude. This field is in percentage form, so 20 is equivalent to 20%.after_price float After-hours price. after_high_price float Highest price after-hours. after_low_price float Lowest price after-hours. after_volume int After-hours trading volume. The Sci-tech Innovation Board supports this data.after_turnover float After-hours turnover. The Sci-tech Innovation Board supports this data.after_change_val float After-hours change. after_change_rate float After-hours change rate. This field is in percentage form, so 20 is equivalent to 20%.after_amplitude float After-hours amplitude. This field is in percentage form, so 20 is equivalent to 20%.future_valid bool Is futures or not. future_last_settle_price float Yesterday's close. future_position float Holding position. future_position_change float Change in position. future_main_contract bool Is future main contract or not. future_last_trade_time str The last trading time. Main, current month and next month futures do not have this field.trust_valid bool Is fund or not. trust_dividend_yield float Dividend rate. This field is in percentage form, so 20 is equivalent to 20%.trust_aum float Asset scale. Unit: yuantrust_outstanding_units int Total circulation. trust_netAssetValue float Net asset value. trust_premium float Premium. This field is in percentage form, so 20 is equivalent to 20%.trust_assetClass AssetClass Asset class.
- Stock snapshot data format as follows:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_market_snapshot(['SH.600000', 'HK.00700'])
if ret == RET_OK:
print(data)
print(data['code'][0]) # Take the first stock code
print(data['code'].values.tolist()) # Convert to list
else:
print('error:', data)
quote_ctx.close() # After using the connection, remember to close it to prevent the number of connections from running out
2
3
4
5
6
7
8
9
10
11
- Output
code name update_time last_price open_price high_price low_price prev_close_price volume turnover turnover_rate suspension listing_date lot_size price_spread stock_owner ask_price bid_price ask_vol bid_vol enable_margin mortgage_ratio long_margin_initial_ratio enable_short_sell short_sell_rate short_available_volume short_margin_initial_ratio amplitude avg_price bid_ask_ratio volume_ratio highest52weeks_price lowest52weeks_price highest_history_price lowest_history_price close_price_5min after_volume after_turnover sec_status equity_valid issued_shares total_market_val net_asset net_profit earning_per_share outstanding_shares circular_market_val net_asset_per_share ey_ratio pe_ratio pb_ratio pe_ttm_ratio dividend_ttm dividend_ratio_ttm dividend_lfy dividend_lfy_ratio wrt_valid wrt_conversion_ratio wrt_type wrt_strike_price wrt_maturity_date wrt_end_trade
0 SH.600000 Shanghai Pudong Development Bank 2023-07-19 15:00:00 7.41 7.36 7.43 7.36 7.39 18189577 1.346770e+08 0.062 False 1999-11-10 100 0.01 NaN 7.41 7.4 44513 215500 True 0.0 40.0 False NaN NaN NaN 0.947 7.404 -24.004 1.046 8.22 6.630000 12.080000 -2.898137 7.41 0 0.0 NORMAL True 29352175642 2.174996e+11 6.011913e+11 5.116084e+10 1.743 29352175642 2.174996e+11 20.482 0.079 4.251 0.361 4.568 0.320 4.32 0.000 0.000 False NaN N/A NaN NaN NaN \
1 HK.00700 TENCENT 2023-07-19 16:08:14 333.00 330.60 333.80 327.00 336.40 21913296 7.240461e+09 0.229 False 2004-06-16 100 0.20 NaN 333.00 332.8 2393100 4700 True 0.0 30.0 True 0.93 4990000.0 30.0 2.021 330.414 -52.783 1.025 414.20 186.226308 709.500065 -9.802011 332.60 0 0.0 NORMAL True 9574268633 3.188231e+12 8.892772e+11 2.107392e+11 22.011 9574268633 3.188231e+12 92.882 0.244 15.128 3.585 14.638 20.523 6.16 20.523 6.163 False NaN N/A NaN NaN NaN
wrt_recovery_price wrt_street_vol wrt_issue_vol wrt_street_ratio wrt_delta wrt_implied_volatility wrt_premium wrt_leverage wrt_ipop wrt_break_even_point wrt_conversion_price wrt_price_recovery_ratio wrt_score wrt_upper_strike_price wrt_lower_strike_price wrt_inline_price_status wrt_issuer_code option_valid option_type strike_time option_strike_price option_contract_size option_open_interest option_implied_volatility option_premium option_delta option_gamma option_vega option_theta option_rho option_net_open_interest option_expiry_date_distance option_contract_nominal_value option_owner_lot_multiplier option_area_type option_contract_multiplier index_option_type index_valid index_raise_count index_fall_count index_equal_count plate_valid plate_raise_count plate_fall_count plate_equal_count future_valid future_last_settle_price future_position future_position_change future_main_contract future_last_trade_time trust_valid
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN False N/A NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN N/A False NaN NaN NaN False NaN NaN NaN False NaN NaN NaN NaN NaN False \
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN False N/A NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN N/A False NaN NaN NaN False NaN NaN NaN False NaN NaN NaN NaN NaN False
trust_dividend_yield trust_aum trust_outstanding_units trust_netAssetValue trust_premium trust_assetClass pre_price pre_high_price pre_low_price pre_volume pre_turnover pre_change_val pre_change_rate pre_amplitude after_price after_high_price after_low_price after_change_val after_change_rate after_amplitude
0 NaN NaN NaN NaN NaN N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
1 NaN NaN NaN NaN NaN N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
SH.600000
['SH.600000', 'HK.00700']
2
3
4
5
6
7
8
9
10
11
12
13
# Qot_GetSecuritySnapshot.proto
Description
Get snapshot data
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Protocol ID
3203
uint GetSecuritySnapshot(QotGetSecuritySnapshot.Request req);
virtual void OnReply_GetSecuritySnapshot(FTAPI_Conn client, uint nSerialNo, QotGetSecuritySnapshot.Response rsp);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- Example
public class Program : FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //Set client information
qot.SetConnCallback(this); //Set connection callback
qot.SetQotCallback(this); //Set transaction callback
}
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 sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetSecuritySnapshot.C2S c2s = QotGetSecuritySnapshot.C2S.CreateBuilder()
.AddSecurityList(sec)
.Build();
QotGetSecuritySnapshot.Request req = QotGetSecuritySnapshot.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetSecuritySnapshot(req);
Console.Write("Send QotGetSecuritySnapshot: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetSecuritySnapshot(FTAPI_Conn client, uint nSerialNo, QotGetSecuritySnapshot.Response rsp)
{
Console.Write("Reply: QotGetSecuritySnapshot: {0} \n", nSerialNo);
Console.Write("basic price: {0}\n", rsp.S2C.SnapshotListList[0].Basic.CurPrice);
Console.Write("equityExData issuedShares: {0}\n", rsp.S2C.SnapshotListList[0].EquityExData.IssuedShares);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6825619056039643630
Send QotGetSecuritySnapshot: 3
Reply: QotGetSecuritySnapshot: 3
basic price: 474.2
equityExData issuedShares: 9595900007
2
3
4
5
int getSecuritySnapshot(QotGetSecuritySnapshot.Request req);
void onReply_GetSecuritySnapshot(FTAPI_Conn client, int nSerialNo, QotGetSecuritySnapshot.Response rsp);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //Set client information
qot.setConnSpi(this); //Set connection callback
qot.setQotSpi(this); //Set transaction callback
}
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 sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetSecuritySnapshot.C2S c2s = QotGetSecuritySnapshot.C2S.newBuilder()
.addSecurityList(sec)
.build();
QotGetSecuritySnapshot.Request req = QotGetSecuritySnapshot.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getSecuritySnapshot(req);
System.out.printf("Send QotGetSecuritySnapshot: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetSecuritySnapshot(FTAPI_Conn client, int nSerialNo, QotGetSecuritySnapshot.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetSecuritySnapshot failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetSecuritySnapshot: %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
- Output
Send QotGetSecuritySnapshot: 2
Receive QotGetSecuritySnapshot: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"snapshotList": [{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.5,
"updateTime": "2021-06-24 16:08:14",
"highPrice": 587.5,
"openPrice": 584.0,
"lowPrice": 580.0,
"lastClosePrice": 582.5,
"curPrice": 583.0,
"volume": "10947302",
"turnover": 6.387238277E9,
"turnoverRate": 0.114,
"listTimestamp": 1.0873152E9,
"updateTimestamp": 1.624522094E9,
"askPrice": 583.5,
"bidPrice": 583.0,
"askVol": "142300",
"bidVol": "52800",
"enableMargin": true,
"mortgageRatio": 0.0,
"longMarginInitialRatio": 35.0,
"enableShortSell": true,
"shortSellRate": 0.9,
"shortAvailableVolume": "2006700",
"shortMarginInitialRatio": 60.0,
"amplitude": 1.288,
"avgPrice": 583.453,
"bidAskRatio": -5.273,
"volumeRatio": 0.553,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 479.4,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 583.5
},
"equityExData": {
"issuedShares": "9595206625",
"issuedMarketVal": 5.594005462375E12,
"netAsset": 9.17675966408375E11,
"netProfit": 1.90378494646625E11,
"earningsPershare": 19.841,
"outstandingShares": "9595206625",
"outstandingMarketVal": 5.594005462375E12,
"netAssetPershare": 95.639,
"eyRate": 0.232,
"peRate": 29.383,
"pbRate": 6.095,
"peTTMRate": 26.249,
"dividendTTM": 1.6,
"dividendRatioTTM": 0.27,
"dividendLFY": 1.6,
"dividendLFYRatio": 0.274
}
}]
}
}
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
Futu::u32_t GetSecuritySnapshot(const Qot_GetSecuritySnapshot::Request &stReq);
virtual void OnReply_GetSecuritySnapshot(Futu::u32_t nSerialNo, const Qot_GetSecuritySnapshot::Response &stRsp) = 0;
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- 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;
// construct request message
Qot_GetSecuritySnapshot::Request req;
Qot_GetSecuritySnapshot::C2S *c2s = req.mutable_c2s();
auto secList = c2s->mutable_securitylist();
Qot_Common::Security *sec = secList->Add();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
m_GetSecuritySnapshotSerialNo = m_pQotApi->GetSecuritySnapshot(req);
cout << "Request GetSecuritySnapshot SerialNo: " << m_GetSecuritySnapshotSerialNo << endl;
}
virtual void OnReply_GetSecuritySnapshot(Futu::u32_t nSerialNo, const Qot_GetSecuritySnapshot::Response &stRsp){
if(nSerialNo == m_GetSecuritySnapshotSerialNo)
{
cout << "OnReply_GetSecuritySnapshot SerialNo: " << nSerialNo << endl;
// print response
// ProtoBufToBodyData and UTF8ToLocal refer to tool.h in Samples
// ProtoBufToBodyData和UTF8ToLocal函数的定义参见Sample中的tool.h文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetSecuritySnapshotSerialNo;
};
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
72
73
- Output
connect
Request GetSecuritySnapshot SerialNo: 4
OnReply_GetSecuritySnapshot SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"snapshotList": [
{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.5,
"updateTime": "2021-06-09 14:12:30",
"highPrice": 606,
"openPrice": 600,
"lowPrice": 597.5,
"lastClosePrice": 601,
"curPrice": 600.5,
"volume": "4382292",
"turnover": 2638928979,
"turnoverRate": 0.046,
"listTimestamp": 1087315200,
"updateTimestamp": 1623219150,
"askPrice": 601,
"bidPrice": 600.5,
"askVol": "24200",
"bidVol": "1400",
"enableMargin": true,
"mortgageRatio": 0,
"longMarginInitialRatio": 35,
"enableShortSell": true,
"shortSellRate": 0.9,
"shortAvailableVolume": "1860000",
"shortMarginInitialRatio": 60,
"amplitude": 1.414,
"avgPrice": 602.18,
"bidAskRatio": 38.289,
"volumeRatio": 0.418,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 430.6,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 601.5
},
"equityExData": {
"issuedShares": "9595206625",
"issuedMarketVal": 5761921578312.5,
"netAsset": 917675966408.375,
"netProfit": 190378494646.625,
"earningsPershare": 19.841,
"outstandingShares": "9595206625",
"outstandingMarketVal": 5761921578312.5,
"netAssetPershare": 95.639,
"eyRate": 0.232,
"peRate": 30.265,
"pbRate": 6.278,
"peTTMRate": 27.037,
"dividendTTM": 1.6,
"dividendRatioTTM": 0.27,
"dividendLFY": 1.6,
"dividendLFYRatio": 0.266
}
}
]
}
}
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
72
73
74
75
76
GetSecuritySnapshot(req);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- 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 QotGetSecuritySnapshot(){
const { RetType } = Common
const { SubType, QotMarket } = 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: {
securityList: [
{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
],
},
};
websocket.GetSecuritySnapshot(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("Snapshot: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let snapshot = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(snapshot);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
// After using the connection, remember to close it to prevent the number of connections from running out
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // Set the script to receive OpenD push duration to 5 seconds
}
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
- Output
Snapshot: errCode 0, retMsg , retType 0
{
"snapshotList": [{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.2,
"updateTime": "2021-09-09 16:08:17",
"highPrice": 511.5,
"openPrice": 509,
"lowPrice": 479,
"lastClosePrice": 524.5,
"curPrice": 480,
"volume": "54090872",
"turnover": 26716845932,
"turnoverRate": 0.563,
"listTimestamp": 1087315200,
"updateTimestamp": 1631174897,
"askPrice": 480.4,
"bidPrice": 480,
"askVol": "700",
"bidVol": "55300",
"enableMargin": true,
"mortgageRatio": 0,
"longMarginInitialRatio": 35,
"enableShortSell": true,
"shortSellRate": 0.92,
"shortAvailableVolume": "3059000",
"shortMarginInitialRatio": 50,
"amplitude": 6.196,
"avgPrice": 493.925,
"bidAskRatio": 22.703,
"volumeRatio": 1.775,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 412.2,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 483.4
},
"equityExData": {
"issuedShares": "9599810645",
"issuedMarketVal": 4607909109600,
"netAsset": 1016063158288.09,
"netProfit": 190383444711.64,
"earningsPershare": 19.832,
"outstandingShares": "9599810645",
"outstandingMarketVal": 4607909109600,
"netAssetPershare": 105.842,
"eyRate": 0.22,
"peRate": 24.203,
"pbRate": 4.535,
"peTTMRate": 20.532,
"dividendTTM": 1.599,
"dividendRatioTTM": 0.33,
"dividendLFY": 1.599,
"dividendLFYRatio": 0.333
}
}]
}
stop
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
Interface Limitations
- Request up to 60 snapshots every 30 seconds
- For each request, the maximum number of stock codes supported by the parameter code_list is 400.
- Under the authority of Hong Kong stock BMP, the maximum number of snapshots of Hong Kong securities (including warrants, CBBC, and Inline Warrants) for a single request is 20
- Under the authority of Hong Kong futures and options BMP, the maximum number of snapshots of Hong Kong futures and options for a single request is 20
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_market_snapshot(code_list)
Description
Get market snapshot
Parameters
Parameter Type Description code_list list Stock list Up to 400 targets can be requested each time.
Data type of elements in the list is str.
Return
Field Type Description ret RET_CODE Interface result. data pd.DataFrame If ret == RET_OK, stock snapshot data is returned. str If ret != RET_OK, error description is returned. - Stock snapshot data format as follows:
Field Type Description code str Stock code. name str Stock name. update_time str Current update time. yyyy-MM-dd HH:mm:ss.
The default of HK stock market and A-share market is Beijing time, while that of US stock market is US Eastern time.last_price float Latest price. open_price float Open. high_price float High. low_price float Low. prev_close_price float Yesterday's close. volume int Volume. turnover float Turnover. turnover_rate float Turnover rate. This field is in percentage form, so 20 is equivalent to 20%.suspension bool Is suspended or not. True: suspension.listing_date str Listing date. yyyy-MM-ddequity_valid bool Is stock or not. The following equity-related fields will be legal only if this field is True.issued_shares int Total shares. total_market_val float Total market value. Unit: yuannet_asset int Net asset value. net_profit int Net profit. earning_per_share float Earnings per share. outstanding_shares int Shares outstanding. net_asset_per_share float Net assets per share. circular_market_val float Circulation market value. Unit: yuaney_ratio float Yield rate. This field is a ratio field, and % is not displayed.pe_ratio float P/E ratio. This field is a ratio field, and % is not displayed.pb_ratio float P/B ratio. This field is a ratio field, and % is not displayed.pe_ttm_ratio float P/E ratio TTM. This field is a ratio field, and % is not displayed.dividend_ttm float Dividend TTM, dividend. dividend_ratio_ttm float Dividend rate TTM. This field is in percentage form, so 20 is equivalent to 20%.dividend_lfy float Dividend LFY, dividend of the previous year. dividend_lfy_ratio float Dividend rate LFY. This field is in percentage form, so 20 is equivalent to 20%.stock_owner str The code of the underlying stock to which the warrant belongs or the code of the underlying stock of the option. wrt_valid bool Is warrant or not. The following warrant related fields will be legal if this field is True.wrt_conversion_ratio float Conversion ratio. wrt_type WrtType Warrant type. wrt_strike_price float Strike price. wrt_maturity_date str Maturity date. wrt_end_trade str Last trading time. wrt_leverage float Leverage ratio. Unit: timeswrt_ipop float in/out of the money. This field is in percentage form, so 20 is equivalent to 20%.wrt_break_even_point float Breakeven point. wrt_conversion_price float Conversion price. wrt_price_recovery_ratio float Price recovery ratio. This field is in percentage form, so 20 is equivalent to 20%.wrt_score float Comprehensive score of warrant. wrt_code str The underlying stock of the warrant (This field has been deprecated and changed to stock_owner.). wrt_recovery_price float Warrant recovery price. wrt_street_vol float Warrant Outstanding quantity. wrt_issue_vol float Warrant issuance. wrt_street_ratio float Outstanding percentage. This field is in percentage form, so 20 is equivalent to 20%.wrt_delta float Delta value of warrant. wrt_implied_volatility float Warrant implied volatility. wrt_premium float Warrant premium. This field is in percentage form, so 20 is equivalent to 20%.wrt_upper_strike_price float Upper bound price. Only Inline Warrant supports this field.wrt_lower_strike_price float lower bound price. Only Inline Warrant supports this field.wrt_inline_price_status PriceType in/out of bounds Only Inline Warrant supports this field.wrt_issuer_code str Issuer code. option_valid bool Is option or not. The following option related fields will be legal when this field is True.option_type OptionType Option type. strike_time str The option exercise date. Format: yyyy-MM-dd
The default of HK stock market and A-share market is Beijing time, while that of US stock market is US Eastern time.option_strike_price float Strike price. option_contract_size float Number of stocks per contract. option_open_interest int Total open contract number. option_implied_volatility float Implied volatility. option_premium float Premium. option_delta float Greek value Delta. option_gamma float Greek value Gamma. option_vega float Greek value Vega. option_theta float Greek value Theta. option_rho float Greek value Rho. index_option_type IndexOptionType Index option type. option_net_open_interest int Net open contract number. Only HK options support this field.option_expiry_date_distance int The number of days from the expiry date, a negative number means it has expired. option_contract_nominal_value float Contract nominal amount. Only HK options support this field.option_owner_lot_multiplier float Equal number of underlying stocks. Index options do not have this field, only HK options support this field.option_area_type OptionAreaType Option type (by exercise time). option_contract_multiplier float Contract multiplier. plate_valid bool Is plate or not. The following plate related fields will be legal when this field is True.plate_raise_count int Number of stocks that raises in the plate. plate_fall_count int Number of stocks that falls in the plate. plate_equal_count int Number of stocks that dose not change in price in the plate. index_valid bool Is index or not. The following index related fields will be legal when this field is True.index_raise_count int Number of stocks that raises in the plate. index_fall_count int Number of stocks that falls in the plate. index_equal_count int Number of stocks that dose not change in the plate. lot_size int The number of shares per lot, stock options represent the number of shares per contract Index options do not have this field.price_spread float The current upward price difference. That is, the quotation difference between ask price and sell 1.ask_price float Ask price. bid_price float Bid price. ask_vol float Ask volume. bid_vol float Bid volume. enable_margin bool Whether financing is available (Deprecated). Please use Get Margin Data.mortgage_ratio float Stock mortgage rate (Deprecated). long_margin_initial_ratio float The initial margin rate of financing (Deprecated). Please use Get Margin Data.enable_short_sell bool Whether short-selling is available (Deprecated). Please use Get Margin Data.short_sell_rate float Short-selling reference rate (Deprecated). Please use Get Margin Data.short_available_volume int Remaining quantity that can be sold short (Deprecated). Please use Get Margin Data.short_margin_initial_ratio float The initial margin rate for short selling (Deprecated). Please use Get Margin Data.sec_status SecurityStatus Stock status. amplitude float Amplitude. This field is in percentage form, so 20 is equivalent to 20%.avg_price float Average price. bid_ask_ratio float The Committee. This field is in percentage form, so 20 is equivalent to 20%.volume_ratio float Volume ratio. highest52weeks_price float Highest price in 52 weeks. lowest52weeks_price float Lowest price in 52 weeks . highest_history_price float Highest historical price. lowest_history_price float Lowest historical price. pre_price float Pre-market price. pre_high_price float Highest pre-market price. pre_low_price float Lowest pre-market price. pre_volume int Pre-market volume. pre_turnover float Pre-market turnover. pre_change_val float Pre-market change. pre_change_rate float Pre-market change rate. This field is in percentage form, so 20 is equivalent to 20%.pre_amplitude float Pre-market amplitude. This field is in percentage form, so 20 is equivalent to 20%.after_price float After-hours price. after_high_price float Highest price after-hours. after_low_price float Lowest price after-hours. after_volume int After-hours trading volume. The Sci-tech Innovation Board supports this data.after_turnover float After-hours turnover. The Sci-tech Innovation Board supports this data.after_change_val float After-hours change. after_change_rate float After-hours change rate. This field is in percentage form, so 20 is equivalent to 20%.after_amplitude float After-hours amplitude. This field is in percentage form, so 20 is equivalent to 20%.future_valid bool Is futures or not. future_last_settle_price float Yesterday's close. future_position float Holding position. future_position_change float Change in position. future_main_contract bool Is future main contract or not. future_last_trade_time str The last trading time. Main, current month and next month futures do not have this field.trust_valid bool Is fund or not. trust_dividend_yield float Dividend rate. This field is in percentage form, so 20 is equivalent to 20%.trust_aum float Asset scale. Unit: yuantrust_outstanding_units int Total circulation. trust_netAssetValue float Net asset value. trust_premium float Premium. This field is in percentage form, so 20 is equivalent to 20%.trust_assetClass AssetClass Asset class.
- Stock snapshot data format as follows:
Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_market_snapshot(['SH.600000', 'HK.00700'])
if ret == RET_OK:
print(data)
print(data['code'][0]) # Take the first stock code
print(data['code'].values.tolist()) # Convert to list
else:
print('error:', data)
quote_ctx.close() # After using the connection, remember to close it to prevent the number of connections from running out
2
3
4
5
6
7
8
9
10
11
- Output
code name update_time last_price open_price high_price low_price prev_close_price volume turnover turnover_rate suspension listing_date lot_size price_spread stock_owner ask_price bid_price ask_vol bid_vol enable_margin mortgage_ratio long_margin_initial_ratio enable_short_sell short_sell_rate short_available_volume short_margin_initial_ratio amplitude avg_price bid_ask_ratio volume_ratio highest52weeks_price lowest52weeks_price highest_history_price lowest_history_price close_price_5min after_volume after_turnover sec_status equity_valid issued_shares total_market_val net_asset net_profit earning_per_share outstanding_shares circular_market_val net_asset_per_share ey_ratio pe_ratio pb_ratio pe_ttm_ratio dividend_ttm dividend_ratio_ttm dividend_lfy dividend_lfy_ratio wrt_valid wrt_conversion_ratio wrt_type wrt_strike_price wrt_maturity_date wrt_end_trade
0 SH.600000 Shanghai Pudong Development Bank 2023-07-19 15:00:00 7.41 7.36 7.43 7.36 7.39 18189577 1.346770e+08 0.062 False 1999-11-10 100 0.01 NaN 7.41 7.4 44513 215500 True 0.0 40.0 False NaN NaN NaN 0.947 7.404 -24.004 1.046 8.22 6.630000 12.080000 -2.898137 7.41 0 0.0 NORMAL True 29352175642 2.174996e+11 6.011913e+11 5.116084e+10 1.743 29352175642 2.174996e+11 20.482 0.079 4.251 0.361 4.568 0.320 4.32 0.000 0.000 False NaN N/A NaN NaN NaN \
1 HK.00700 TENCENT 2023-07-19 16:08:14 333.00 330.60 333.80 327.00 336.40 21913296 7.240461e+09 0.229 False 2004-06-16 100 0.20 NaN 333.00 332.8 2393100 4700 True 0.0 30.0 True 0.93 4990000.0 30.0 2.021 330.414 -52.783 1.025 414.20 186.226308 709.500065 -9.802011 332.60 0 0.0 NORMAL True 9574268633 3.188231e+12 8.892772e+11 2.107392e+11 22.011 9574268633 3.188231e+12 92.882 0.244 15.128 3.585 14.638 20.523 6.16 20.523 6.163 False NaN N/A NaN NaN NaN
wrt_recovery_price wrt_street_vol wrt_issue_vol wrt_street_ratio wrt_delta wrt_implied_volatility wrt_premium wrt_leverage wrt_ipop wrt_break_even_point wrt_conversion_price wrt_price_recovery_ratio wrt_score wrt_upper_strike_price wrt_lower_strike_price wrt_inline_price_status wrt_issuer_code option_valid option_type strike_time option_strike_price option_contract_size option_open_interest option_implied_volatility option_premium option_delta option_gamma option_vega option_theta option_rho option_net_open_interest option_expiry_date_distance option_contract_nominal_value option_owner_lot_multiplier option_area_type option_contract_multiplier index_option_type index_valid index_raise_count index_fall_count index_equal_count plate_valid plate_raise_count plate_fall_count plate_equal_count future_valid future_last_settle_price future_position future_position_change future_main_contract future_last_trade_time trust_valid
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN False N/A NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN N/A False NaN NaN NaN False NaN NaN NaN False NaN NaN NaN NaN NaN False \
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN False N/A NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN N/A NaN N/A False NaN NaN NaN False NaN NaN NaN False NaN NaN NaN NaN NaN False
trust_dividend_yield trust_aum trust_outstanding_units trust_netAssetValue trust_premium trust_assetClass pre_price pre_high_price pre_low_price pre_volume pre_turnover pre_change_val pre_change_rate pre_amplitude after_price after_high_price after_low_price after_change_val after_change_rate after_amplitude
0 NaN NaN NaN NaN NaN N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
1 NaN NaN NaN NaN NaN N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
SH.600000
['SH.600000', 'HK.00700']
2
3
4
5
6
7
8
9
10
11
12
13
# Qot_GetSecuritySnapshot.proto
Description
Get snapshot data
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Protocol ID
3203
uint GetSecuritySnapshot(QotGetSecuritySnapshot.Request req);
virtual void OnReply_GetSecuritySnapshot(MMAPI_Conn client, uint nSerialNo, QotGetSecuritySnapshot.Response rsp);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- Example
public class Program : MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //Set client information
qot.SetConnCallback(this); //Set connection callback
qot.SetQotCallback(this); //Set transaction callback
}
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 sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetSecuritySnapshot.C2S c2s = QotGetSecuritySnapshot.C2S.CreateBuilder()
.AddSecurityList(sec)
.Build();
QotGetSecuritySnapshot.Request req = QotGetSecuritySnapshot.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetSecuritySnapshot(req);
Console.Write("Send QotGetSecuritySnapshot: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetSecuritySnapshot(MMAPI_Conn client, uint nSerialNo, QotGetSecuritySnapshot.Response rsp)
{
Console.Write("Reply: QotGetSecuritySnapshot: {0} \n", nSerialNo);
Console.Write("basic price: {0}\n", rsp.S2C.SnapshotListList[0].Basic.CurPrice);
Console.Write("equityExData issuedShares: {0}\n", rsp.S2C.SnapshotListList[0].EquityExData.IssuedShares);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6825619056039643630
Send QotGetSecuritySnapshot: 3
Reply: QotGetSecuritySnapshot: 3
basic price: 474.2
equityExData issuedShares: 9595900007
2
3
4
5
int getSecuritySnapshot(QotGetSecuritySnapshot.Request req);
void onReply_GetSecuritySnapshot(MMAPI_Conn client, int nSerialNo, QotGetSecuritySnapshot.Response rsp);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //Set client information
qot.setConnSpi(this); //Set connection callback
qot.setQotSpi(this); //Set transaction callback
}
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 sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetSecuritySnapshot.C2S c2s = QotGetSecuritySnapshot.C2S.newBuilder()
.addSecurityList(sec)
.build();
QotGetSecuritySnapshot.Request req = QotGetSecuritySnapshot.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getSecuritySnapshot(req);
System.out.printf("Send QotGetSecuritySnapshot: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetSecuritySnapshot(MMAPI_Conn client, int nSerialNo, QotGetSecuritySnapshot.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetSecuritySnapshot failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetSecuritySnapshot: %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
- Output
Send QotGetSecuritySnapshot: 2
Receive QotGetSecuritySnapshot: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"snapshotList": [{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.5,
"updateTime": "2021-06-24 16:08:14",
"highPrice": 587.5,
"openPrice": 584.0,
"lowPrice": 580.0,
"lastClosePrice": 582.5,
"curPrice": 583.0,
"volume": "10947302",
"turnover": 6.387238277E9,
"turnoverRate": 0.114,
"listTimestamp": 1.0873152E9,
"updateTimestamp": 1.624522094E9,
"askPrice": 583.5,
"bidPrice": 583.0,
"askVol": "142300",
"bidVol": "52800",
"enableMargin": true,
"mortgageRatio": 0.0,
"longMarginInitialRatio": 35.0,
"enableShortSell": true,
"shortSellRate": 0.9,
"shortAvailableVolume": "2006700",
"shortMarginInitialRatio": 60.0,
"amplitude": 1.288,
"avgPrice": 583.453,
"bidAskRatio": -5.273,
"volumeRatio": 0.553,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 479.4,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 583.5
},
"equityExData": {
"issuedShares": "9595206625",
"issuedMarketVal": 5.594005462375E12,
"netAsset": 9.17675966408375E11,
"netProfit": 1.90378494646625E11,
"earningsPershare": 19.841,
"outstandingShares": "9595206625",
"outstandingMarketVal": 5.594005462375E12,
"netAssetPershare": 95.639,
"eyRate": 0.232,
"peRate": 29.383,
"pbRate": 6.095,
"peTTMRate": 26.249,
"dividendTTM": 1.6,
"dividendRatioTTM": 0.27,
"dividendLFY": 1.6,
"dividendLFYRatio": 0.274
}
}]
}
}
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
moomoo::u32_t GetSecuritySnapshot(const Qot_GetSecuritySnapshot::Request &stReq);
virtual void OnReply_GetSecuritySnapshot(moomoo::u32_t nSerialNo, const Qot_GetSecuritySnapshot::Response &stRsp) = 0;
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- 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;
// construct request message
Qot_GetSecuritySnapshot::Request req;
Qot_GetSecuritySnapshot::C2S *c2s = req.mutable_c2s();
auto secList = c2s->mutable_securitylist();
Qot_Common::Security *sec = secList->Add();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
m_GetSecuritySnapshotSerialNo = m_pQotApi->GetSecuritySnapshot(req);
cout << "Request GetSecuritySnapshot SerialNo: " << m_GetSecuritySnapshotSerialNo << endl;
}
virtual void OnReply_GetSecuritySnapshot(moomoo::u32_t nSerialNo, const Qot_GetSecuritySnapshot::Response &stRsp){
if(nSerialNo == m_GetSecuritySnapshotSerialNo)
{
cout << "OnReply_GetSecuritySnapshot SerialNo: " << nSerialNo << endl;
// print response
// ProtoBufToBodyData and UTF8ToLocal refer to tool.h in Samples
// ProtoBufToBodyData和UTF8ToLocal函数的定义参见Sample中的tool.h文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetSecuritySnapshotSerialNo;
};
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
72
73
- Output
connect
Request GetSecuritySnapshot SerialNo: 4
OnReply_GetSecuritySnapshot SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"snapshotList": [
{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.5,
"updateTime": "2021-06-09 14:12:30",
"highPrice": 606,
"openPrice": 600,
"lowPrice": 597.5,
"lastClosePrice": 601,
"curPrice": 600.5,
"volume": "4382292",
"turnover": 2638928979,
"turnoverRate": 0.046,
"listTimestamp": 1087315200,
"updateTimestamp": 1623219150,
"askPrice": 601,
"bidPrice": 600.5,
"askVol": "24200",
"bidVol": "1400",
"enableMargin": true,
"mortgageRatio": 0,
"longMarginInitialRatio": 35,
"enableShortSell": true,
"shortSellRate": 0.9,
"shortAvailableVolume": "1860000",
"shortMarginInitialRatio": 60,
"amplitude": 1.414,
"avgPrice": 602.18,
"bidAskRatio": 38.289,
"volumeRatio": 0.418,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 430.6,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 601.5
},
"equityExData": {
"issuedShares": "9595206625",
"issuedMarketVal": 5761921578312.5,
"netAsset": 917675966408.375,
"netProfit": 190378494646.625,
"earningsPershare": 19.841,
"outstandingShares": "9595206625",
"outstandingMarketVal": 5761921578312.5,
"netAssetPershare": 95.639,
"eyRate": 0.232,
"peRate": 30.265,
"pbRate": 6.278,
"peTTMRate": 27.037,
"dividendTTM": 1.6,
"dividendRatioTTM": 0.27,
"dividendLFY": 1.6,
"dividendLFYRatio": 0.266
}
}
]
}
}
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
72
73
74
75
76
GetSecuritySnapshot(req);
Description
Get market snapshot
Parameters
message C2S
{
repeated Qot_Common.Security securityList = 1; //Security list
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- For stock structure, refer to Security
- Return
// Additional data of underlying stock type
message EquitySnapshotExData
{
required int64 issuedShares = 1; //Total shares
required double issuedMarketVal = 2; //Total market value = total number of shares * current price
required double netAsset = 3; //Net asset value
required double netProfit = 4; //Profit or loss
required double earningsPershare = 5; //Earnings per share
required int64 outstandingShares = 6; //Shares outstanding
required double outstandingMarketVal = 7; //Market value of shares outstanding = number of shares outstanding * current price
required double netAssetPershare = 8; //Net asset per share
required double eyRate = 9; //Yield rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double peRate = 10; //P/E ratio
required double pbRate = 11; //P/B ratio
required double peTTMRate = 12; //P/E ratio TTM
optional double dividendTTM = 13; //Dividend TTM, dividend
optional double dividendRatioTTM = 14; //Dividend rate TTM (This field is in percentage form, so 20 is equivalent to 20%.)
optional double dividendLFY = 15; //Dividend LFY, last year's dividend
optional double dividendLFYRatio = 16; //Dividend rate LFY (This field is in percentage form, so 20 is equivalent to 20%.)
}
// Additional data for warrant type
message WarrantSnapshotExData
{
required double conversionRate = 1; //Share conversion ratio
required int32 warrantType = 2; //Qot_Common.WarrantType, warrant type
required double strikePrice = 3; //Strike price
required string maturityTime = 4; //Time string of expiration date
required string endTradeTime = 5; //Time string of the last trading day
required Qot_Common.Security owner = 6; //The underlying stock
required double recoveryPrice = 7; //Call price, only CBBC supports this field
required int64 streetVolumn = 8; //Outstanding quantity
required int64 issueVolumn = 9; //Issue volume
required double streetRate = 10; //Outstanding percentage (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 11; //Hedging value, only calls and puts support this field
required double impliedVolatility = 12; //Implied volatility, only calls and puts support this field
required double premium = 13; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
optional double maturityTimestamp = 14; //Maturity date timestamp
optional double endTradeTimestamp = 15; //The last trading day timestamp
optional double leverage = 16; //Leverage ratio (times)
optional double ipop = 17; // In/out of money (This field is in percentage form, so 20 is equivalent to 20%.)
optional double breakEvenPoint = 18; //Breakeven point
optional double conversionPrice = 19; //Conversion price
optional double priceRecoveryRatio = 20; //Stock price recovery ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double score = 21; //Comprehensive score
optional double upperStrikePrice = 22; //Upper bound price, only the Inline Warrants support this field
optional double lowerStrikePrice = 23; //Lower bound price, only the Inline Warrants support this field
optional int32 inLinePriceStatus = 24; //Qot_Common.PriceType, in/out-of bound, only Inline Warrants support this field
optional string issuerCode = 25; //Issuer code
}
// Option type additional data
message OptionSnapshotExData
{
required int32 type = 1; //Qot_Common.OptionType, option type (by direction)
required Qot_Common.Security owner = 2; //Underlying stock
required string strikeTime = 3; //Time string of exercise date (Format: yyyy-MM-dd)
required double strikePrice = 4; //Strike price
required int32 contractSize = 5; //Number of stocks per contract (int type)
optional double contractSizeFloat = 22; //Number of stocks per contract (float type)
required int32 openInterest = 6; //Number of open position
required double impliedVolatility = 7; //Implied volatility (This field is in percentage form, so 20 is equivalent to 20%.)
required double premium = 8; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required double delta = 9; //Greek value Delta
required double gamma = 10; //Greek value Gamma
required double vega = 11; //Greek value Vega
required double theta = 12; //Greek value Theta
required double rho = 13; //Greek value Rho
optional double strikeTimestamp = 14; //Exercise date timestamp
optional int32 indexOptionType = 15; //Qot_Common.IndexOptionType, index option type
optional int32 netOpenInterest = 16; //Net open contract number , only HK options support this field
optional int32 expiryDateDistance = 17; //The number of days from the expiry date, a negative number means it has expired.
optional double contractNominalValue = 18; //Contract nominal amount , only HK options support this field
optional double ownerLotMultiplier = 19; //Equal number of underlying stocks, index options do not have this field , only HK options support this field
optional int32 optionAreaType = 20; //Qot_Common.OptionAreaType, option type (by exercise time).
optional double contractMultiplier = 21; //Contract multiplier
}
// additional data of index type
message IndexSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
// Additional data of the sector type
message PlateSnapshotExData
{
required int32 raiseCount = 1; //Number of stocks that raises
required int32 fallCount = 2; //Number of stocks that falls
required int32 equalCount = 3; //Number of stocks that does not change
}
//Additional data of futures type
message FutureSnapshotExData
{
required double lastSettlePrice = 1; //Yesterday's close
required int32 position = 2; //Holding position
required int32 positionChange = 3; //Daily change in position
required string lastTradeTime = 4; //The last trading day, only future non-main contracts have this field
optional double lastTradeTimestamp = 5; //The last trading day timestamp, only future non-main contracts have this field
required bool isMainContract = 6; //Whether is main-linked contract
}
//Additional data of fund type
message TrustSnapshotExData
{
required double dividendYield = 1; //Dividend rate (This field is in percentage form, so 20 is equivalent to 20%.)
required double aum = 2; //Asset scale
required int64 outstandingUnits = 3; //Total circulation
required double netAssetValue = 4; //Net asset value
required double premium = 5; //Premium (This field is in percentage form, so 20 is equivalent to 20%.)
required int32 assetClass = 6; //Qot_Common.AssetClass, asset class
}
//Basic snapshot data
message SnapshotBasicData
{
required Qot_Common.Security security = 1; //Security
optional string name = 41; //Stock name
required int32 type = 2; //Qot_Common.SecurityType, security type
required bool isSuspend = 3; //Whether is suspended
required string listTime = 4; //String of listed time (Format: yyyy-MM-dd)
required int32 lotSize = 5; //Quantity per lot
required double priceSpread = 6; //Spread
required string updateTime = 7; //String of updated time (Format: yyyy-MM-dd HH:mm:ss)
required double highPrice = 8; //High
required double openPrice = 9; //Open
required double lowPrice = 10; //low
required double lastClosePrice = 11; //Yesterday's close
required double curPrice = 12; //Current price
required int64 volume = 13; //Volume
required double turnover = 14; //Turnover
required double turnoverRate = 15; //Turnover rate (This field is in percentage form, so 20 is equivalent to 20%.)
optional double listTimestamp = 16; //Listing timestamp
optional double updateTimestamp = 17; //Update timestamp
optional double askPrice = 18;//Ask price
optional double bidPrice = 19;//Bid price
optional int64 askVol = 20;//Ask volume
optional int64 bidVol = 21;//Bid volume
optional bool enableMargin = 22; //Whether financing is available (Deprecated. Please use Get Margin Data interface.).
optional double mortgageRatio = 23; //Stock mortgage rate.
optional double longMarginInitialRatio = 24; //Initial margin rate for financing (Deprecated. Please use Get Margin Data interface.).
optional bool enableShortSell = 25; //Whether it can be short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortSellRate = 26; //Reference rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional int64 shortAvailableVolume = 27; //The remaining quantity that is available for short selling (Deprecated. Please use Get Margin Data interface.).
optional double shortMarginInitialRatio = 28; //The initial margin rate for short selling (Deprecated. Please use Get Margin Data interface.).
optional double amplitude = 29; //Amplitude (This field is in percentage form, so 20 is equivalent to 20%.)
optional double avgPrice = 30; //Average price
optional double bidAskRatio = 31; //Commission ratio (This field is in percentage form, so 20 is equivalent to 20%.)
optional double volumeRatio = 32; //Volume ratio
optional double highest52WeeksPrice = 33; //Highest price in 52 weeks
optional double lowest52WeeksPrice = 34; //Lowest price in 52 weeks
optional double highestHistoryPrice = 35; //Highest historical price
optional double lowestHistoryPrice = 36; //Lowest historical price
optional Qot_Common.PreAfterMarketData preMarket = 37; //Qot_Common::PreAfterMarketData data pre-market
optional Qot_Common.PreAfterMarketData afterMarket = 38; //Qot_Common::PreAfterMarketData data after-hourrs
optional int32 secStatus = 39; //Qot_Common::SecurityStatus stock status
optional double closePrice5Minute = 40; //Close for timeframe of 5 minutes
}
message Snapshot
{
required SnapshotBasicData basic = 1; //Snapshot basic data
optional EquitySnapshotExData equityExData = 2; //Stock snapshot additional data
optional WarrantSnapshotExData warrantExData = 3; //Warrant snapshot additional data
optional OptionSnapshotExData optionExData = 4; //Option snapshot additional data
optional IndexSnapshotExData indexExData = 5; //Index snapshot additional data
optional PlateSnapshotExData plateExData = 6; //Plate snapshot additional data
optional FutureSnapshotExData futureExData = 7; //Futures additional data
optional TrustSnapshotExData trustExData = 8; //Fund additional data
}
message S2C
{
repeated Snapshot snapshotList = 1; //Stock snapshot
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, returned value
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
- 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 QotGetSecuritySnapshot(){
const { RetType } = Common
const { SubType, QotMarket } = 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: {
securityList: [
{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
],
},
};
websocket.GetSecuritySnapshot(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("Snapshot: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let snapshot = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(snapshot);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
// After using the connection, remember to close it to prevent the number of connections from running out
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // Set the script to receive OpenD push duration to 5 seconds
}
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
- Output
Snapshot: errCode 0, retMsg , retType 0
{
"snapshotList": [{
"basic": {
"security": {
"market": 1,
"code": "00700"
},
"type": 3,
"isSuspend": false,
"listTime": "2004-06-16",
"lotSize": 100,
"priceSpread": 0.2,
"updateTime": "2021-09-09 16:08:17",
"highPrice": 511.5,
"openPrice": 509,
"lowPrice": 479,
"lastClosePrice": 524.5,
"curPrice": 480,
"volume": "54090872",
"turnover": 26716845932,
"turnoverRate": 0.563,
"listTimestamp": 1087315200,
"updateTimestamp": 1631174897,
"askPrice": 480.4,
"bidPrice": 480,
"askVol": "700",
"bidVol": "55300",
"enableMargin": true,
"mortgageRatio": 0,
"longMarginInitialRatio": 35,
"enableShortSell": true,
"shortSellRate": 0.92,
"shortAvailableVolume": "3059000",
"shortMarginInitialRatio": 50,
"amplitude": 6.196,
"avgPrice": 493.925,
"bidAskRatio": 22.703,
"volumeRatio": 1.775,
"highest52WeeksPrice": 773.9,
"lowest52WeeksPrice": 412.2,
"highestHistoryPrice": 773.9,
"lowestHistoryPrice": -6.381,
"secStatus": 1,
"closePrice5Minute": 483.4
},
"equityExData": {
"issuedShares": "9599810645",
"issuedMarketVal": 4607909109600,
"netAsset": 1016063158288.09,
"netProfit": 190383444711.64,
"earningsPershare": 19.832,
"outstandingShares": "9599810645",
"outstandingMarketVal": 4607909109600,
"netAssetPershare": 105.842,
"eyRate": 0.22,
"peRate": 24.203,
"pbRate": 4.535,
"peTTMRate": 20.532,
"dividendTTM": 1.599,
"dividendRatioTTM": 0.33,
"dividendLFY": 1.599,
"dividendLFYRatio": 0.333
}
}]
}
stop
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
Interface Limitations
- Request up to 60 snapshots every 30 seconds
- For each request, the maximum number of stock codes supported by the parameter code_list is 400.
- Under the authority of Hong Kong stock BMP, the maximum number of snapshots of Hong Kong securities (including warrants, CBBC, and Inline Warrants) for a single request is 20
- Under the authority of Hong Kong futures and options BMP, the maximum number of snapshots of Hong Kong futures and options for a single request is 20