from futu import*
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_stock_basicinfo(Market.HK, SecurityType.STOCK)if ret == RET_OK:print(data)else:print('error:', data)print('******************************************')
ret, data = quote_ctx.get_stock_basicinfo(Market.HK, SecurityType.STOCK,['HK.06998','HK.00700'])if ret == RET_OK:print(data)print(data['name'][0])# Take the first stock nameprint(data['name'].values.tolist())# Convert to listelse:print('error:', data)
quote_ctx.close()# After using the connection, remember to close it to prevent the number of connections from running out
messageC2S{// when both market and code_list exist, market is ignored and only code_list is effective.optionalint32 market =1;//Qot_Common.QotMarket, stock marketoptionalint32 secType =2;//Qot_Common.SecurityType, stock typerepeatedQot_Common.Security securityList =3;//Stock, if this field exists, ignore other fields, and only return the static information of the stocks in this field}messageRequest{requiredC2S c2s =1;}
messageC2S{// when both market and code_list exist, market is ignored and only code_list is effective.optionalint32 market =1;//Qot_Common.QotMarket, stock marketoptionalint32 secType =2;//Qot_Common.SecurityType, stock typerepeatedQot_Common.Security securityList =3;//Stock, if this field exists, ignore other fields, and only return the static information of the stocks in this field}messageRequest{requiredC2S c2s =1;}
int getStaticInfo(QotGetStaticInfo.Request req); void onReply_GetStaticInfo(FTAPI_Conn client, int nSerialNo, QotGetStaticInfo.Response rsp);
Introduction
Get Stock Basic Information
Parameters
messageC2S{// when both market and code_list exist, market is ignored and only code_list is effective.optionalint32 market =1;//Qot_Common.QotMarket, stock marketoptionalint32 secType =2;//Qot_Common.SecurityType, stock typerepeatedQot_Common.Security securityList =3;//Stock, if this field exists, ignore other fields, and only return the static information of the stocks in this field}messageRequest{requiredC2S c2s =1;}
messageC2S{// when both market and code_list exist, market is ignored and only code_list is effective.optionalint32 market =1;//Qot_Common.QotMarket, stock marketoptionalint32 secType =2;//Qot_Common.SecurityType, stock typerepeatedQot_Common.Security securityList =3;//Stock, if this field exists, ignore other fields, and only return the static information of the stocks in this field}messageRequest{requiredC2S c2s =1;}
messageC2S{// when both market and code_list exist, market is ignored and only code_list is effective.optionalint32 market =1;//Qot_Common.QotMarket, stock marketoptionalint32 secType =2;//Qot_Common.SecurityType, stock typerepeatedQot_Common.Security securityList =3;//Stock, if this field exists, ignore other fields, and only return the static information of the stocks in this field}messageRequest{requiredC2S c2s =1;}
import ftWebsocket from"futu-api";import{ ftCmdID }from"futu-api";import{ Common, Qot_Common }from"futu-api/proto";import beautify from"js-beautify";functionQotGetStaticInfo(){const{ RetType }= Common
const{ QotMarket, PlateSetType }= Qot_Common
let[addr, port, enable_ssl, key]=["127.0.0.1",33333,false,'7522027ccf5a06b1'];let websocket =newftWebsocket();
websocket.onlogin=(ret, msg)=>{if(ret){const req ={c2s:{securityList:[{market: QotMarket.QotMarket_HK_Security,code:"00700",},],},};
websocket.GetStaticInfo(req).then((res)=>{let{ errCode, retMsg, retType,s2c }= res
console.log("StaticInfo: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);if(retType == RetType.RetType_Succeed){let data =beautify(JSON.stringify(s2c),{indent_size:2,space_in_empty_paren:true,});
console.log(data);}}).catch((error)=>{
console.log("error:", error);});}else{
console.log("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 outsetTimeout(()=>{
websocket.stop();
console.log("stop");},5000);// Set the script to receive FutuOpenD push duration to 5 seconds}
When input stocks are not recognized by the program (including stocks that have been delisted a long time ago and non-existent stocks), this interface still returns stock information. The "delisted" field is used to indicate that the stock does exist or not. The unified processing is: the code is displayed normally, the stock name is displayed as "unknown stock", and the other fields are default values (The integer type defaults to 0, and the string defaults to an empty string.).
This interface is different from other market information interfaces. When other interfaces get input stocks that the program cannot recognize, they will reject the request and return the error description "unknown stock".