futu-sdk
Version:
futu-api 的高性能精简易用版;基于*.proto静态编译,提供高性能的多层封装但层层开放的易用接口,获取最原始最完整的量化数据;相较于Python, nodejs更接近Web, 从而轻而易举搭建一个可视化交易站点,这是进行可控量化交易的不二选择。
2 lines (1 loc) • 14.8 kB
JavaScript
;var T=Object.create;var I=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var k=(s,e)=>{for(var t in e)I(s,t,{get:e[t],enumerable:!0})},N=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!O.call(s,i)&&i!==t&&I(s,i,{get:()=>e[i],enumerable:!(n=f(e,i))||n.enumerable});return s};var y=(s,e,t)=>(t=s!=null?T(U(s)):{},N(e||!s||!s.__esModule?I(t,"default",{value:s,enumerable:!0}):t,s)),g=s=>N(I({},"__esModule",{value:!0}),s);var C={};k(C,{getFutuApi:()=>M});module.exports=g(C);var P=y(require("crypto"),1);var w="ft-v1.0",B=1,K=new TextEncoder,H=new TextDecoder,F=(s,e)=>{let t=B++,n=K.encode(w),i=20+e.byteLength,d=new ArrayBuffer(i),p=new Uint8Array(d),l=new DataView(d);p.set(n,0);for(let a=n.length;a<8;a++)p[a]=0;return l.setUint32(8,s,!1),l.setBigUint64(12,BigInt(t),!1),p.set(e,20),{message:d,session:t}},h=s=>{let e=new DataView(s),t=new Uint8Array(s),n=e.getUint32(8,!1),i=Number(e.getBigUint64(12,!1)),d=e.getInt32(20,!1),p=t.subarray(24,44),l=p.indexOf(0),a=l===-1?p:p.subarray(0,l),u=a.length>0?H.decode(a):"",m=t.subarray(44).slice();return{session:i,cmd:n,message:{errorCode:d,errorMessage:u,protobuf:m}}};var o=y(require("futu-proto"),1),r={InitWebSocket:{cmd:1,name:o.InitWebSocket,description:"\u521D\u59CB\u5316\u8FDE\u63A5"},GetGlobalState:{cmd:1002,name:o.GetGlobalState,description:"\u83B7\u53D6\u5168\u5C40\u72B6\u6001"},KeepAlive:{cmd:1004,name:o.KeepAlive,description:"\u5FC3\u8DF3"},GetUserInfo:{cmd:1005,name:o.GetUserInfo,description:"\u83B7\u53D6\u7528\u6237\u4FE1\u606F"},GetDelayStatistics:{cmd:1007,name:o.GetDelayStatistics,description:"\u83B7\u53D6\u5EF6\u8FDF\u7EDF\u8BA1"},QotSub:{cmd:3001,name:o.Qot_Sub,description:"\u8BA2\u9605\u6216\u8005\u53CD\u8BA2\u9605"},QotRegQotPush:{cmd:3002,name:o.Qot_RegQotPush,description:"\u6CE8\u518C\u63A8\u9001"},QotGetSubInfo:{cmd:3003,name:o.Qot_GetSubInfo,description:"\u83B7\u53D6\u8BA2\u9605\u4FE1\u606F"},QotGetBasicQot:{cmd:3004,name:o.Qot_GetBasicQot,description:"\u83B7\u53D6\u57FA\u672C\u884C\u60C5"},QotGetKL:{cmd:3006,name:o.Qot_GetKL,description:"\u83B7\u53D6K\u7EBF"},QotGetRT:{cmd:3008,name:o.Qot_GetRT,description:"\u83B7\u53D6\u5206\u65F6"},QotGetTicker:{cmd:3010,name:o.Qot_GetTicker,description:"\u83B7\u53D6\u9010\u7B14"},QotGetOrderBook:{cmd:3012,name:o.Qot_GetOrderBook,description:"\u83B7\u53D6\u4E70\u5356\u76D8"},QotGetBroker:{cmd:3014,name:o.Qot_GetBroker,description:"\u83B7\u53D6\u7ECF\u7EAA\u961F\u5217"},QotGetHistoryKL:{cmd:3100,name:o.Qot_GetHistoryKL,description:"\u83B7\u53D6\u5386\u53F2K\u7EBF"},QotGetHistoryKLPoints:{cmd:3101,name:o.Qot_GetHistoryKLPoints,description:"\u83B7\u53D6\u591A\u53EA\u80A1\u7968\u5386\u53F2\u5355\u70B9K\u7EBF"},QotGetRehab:{cmd:3102,name:o.Qot_GetRehab,description:"\u83B7\u53D6\u590D\u6743\u4FE1\u606F"},QotRequestHistoryKL:{cmd:3103,name:o.Qot_RequestHistoryKL,description:"\u5728\u7EBF\u62C9\u53D6\u5386\u53F2K\u7EBF\uFF0C\u4E0D\u8BFB\u672C\u5730\u5386\u53F2\u6570\u636EDB"},QotRequestHistoryKLQuota:{cmd:3104,name:o.Qot_RequestHistoryKLQuota,description:"\u62C9\u53D6\u5386\u53F2K\u7EBF\u5DF2\u7ECF\u7528\u6389\u7684\u989D\u5EA6"},QotRequestRehab:{cmd:3105,name:o.Qot_RequestRehab,description:"\u5728\u7EBF\u62C9\u53D6\u590D\u6743\u4FE1\u606F\uFF0C\u4E0D\u8BFB\u672C\u5730\u5386\u53F2\u6570\u636EDB"},QotGetSuspend:{cmd:3201,name:o.Qot_GetSuspend,description:"\u83B7\u53D6\u80A1\u7968\u505C\u724C\u4FE1\u606F"},QotGetStaticInfo:{cmd:3202,name:o.Qot_GetStaticInfo,description:"\u83B7\u53D6\u80A1\u7968\u9759\u6001\u4FE1\u606F"},QotGetSecuritySnapshot:{cmd:3203,name:o.Qot_GetSecuritySnapshot,description:"\u83B7\u53D6\u80A1\u7968\u5FEB\u7167"},QotGetPlateSet:{cmd:3204,name:o.Qot_GetPlateSet,description:"\u83B7\u53D6\u677F\u5757\u96C6\u5408\u4E0B\u7684\u677F\u5757"},QotGetPlateSecurity:{cmd:3205,name:o.Qot_GetPlateSecurity,description:"\u83B7\u53D6\u677F\u5757\u4E0B\u7684\u80A1\u7968"},QotGetReference:{cmd:3206,name:o.Qot_GetReference,description:"\u83B7\u53D6\u6B63\u80A1\u76F8\u5173\u80A1\u7968\uFF0C\u6682\u65F6\u53EA\u6709\u7A9D\u8F6E"},QotGetOwnerPlate:{cmd:3207,name:o.Qot_GetOwnerPlate,description:"\u83B7\u53D6\u80A1\u7968\u6240\u5C5E\u677F\u5757"},QotGetHoldingChangeList:{cmd:3208,name:o.Qot_GetHoldingChangeList,description:"\u83B7\u53D6\u5927\u80A1\u4E1C\u6301\u80A1\u53D8\u5316\u5217\u8868"},QotGetOptionChain:{cmd:3209,name:o.Qot_GetOptionChain,description:"\u83B7\u53D6\u671F\u6743\u94FE"},QotGetWarrant:{cmd:3210,name:o.Qot_GetWarrant,description:"\u83B7\u53D6\u6DA1\u8F6E"},QotGetCapitalFlow:{cmd:3211,name:o.Qot_GetCapitalFlow,description:"\u83B7\u53D6\u8D44\u91D1\u6D41\u5411"},QotGetCapitalDistribution:{cmd:3212,name:o.Qot_GetCapitalDistribution,description:"\u83B7\u53D6\u8D44\u91D1\u5206\u5E03"},QotGetUserSecurity:{cmd:3213,name:o.Qot_GetUserSecurity,description:"\u83B7\u53D6\u81EA\u9009\u80A1\u5206\u7EC4\u4E0B\u7684\u80A1\u7968"},QotModifyUserSecurity:{cmd:3214,name:o.Qot_ModifyUserSecurity,description:"\u4FEE\u6539\u81EA\u9009\u80A1\u5206\u7EC4\u4E0B\u7684\u80A1\u7968"},QotStockFilter:{cmd:3215,name:o.Qot_StockFilter,description:"\u6761\u4EF6\u9009\u80A1"},QotGetCodeChange:{cmd:3216,name:o.Qot_GetCodeChange,description:"\u83B7\u53D6\u80A1\u7968\u4EE3\u7801\u53D8\u5316\u4FE1\u606F"},QotGetIpoList:{cmd:3217,name:o.Qot_GetIpoList,description:"\u83B7\u53D6\u65B0\u80A1IPO"},QotGetFutureInfo:{cmd:3218,name:o.Qot_GetFutureInfo,description:"\u83B7\u53D6\u671F\u8D27\u5408\u7EA6\u8D44\u6599"},QotRequestTradeDate:{cmd:3219,name:o.Qot_RequestTradeDate,description:"\u83B7\u53D6\u5E02\u573A\u4EA4\u6613\u65E5"},QotSetPriceReminder:{cmd:3220,name:o.Qot_SetPriceReminder,description:"\u8BBE\u7F6E\u5230\u4EF7\u63D0\u9192"},QotGetPriceReminder:{cmd:3221,name:o.Qot_GetPriceReminder,description:"\u83B7\u53D6\u5230\u4EF7\u63D0\u9192"},QotGetUserSecurityGroup:{cmd:3222,name:o.Qot_GetUserSecurityGroup,description:"\u83B7\u53D6\u81EA\u9009\u80A1\u5206\u7EC4\u5217\u8868"},QotGetMarketState:{cmd:3223,name:o.Qot_GetMarketState,description:"\u83B7\u53D6\u80A1\u7968\u5BF9\u5E94\u5E02\u573A\u72B6\u6001"},QotGetOptionExpirationDate:{cmd:3224,name:o.Qot_GetOptionExpirationDate,description:"\u83B7\u53D6\u671F\u6743\u94FE\u5230\u671F\u65E5"},TrdGetAccList:{cmd:2001,name:o.Trd_GetAccList,description:"\u83B7\u53D6\u4EA4\u6613\u8D26\u6237\u5217\u8868"},TrdUnlockTrade:{cmd:2005,name:o.Trd_UnlockTrade,description:"\u89E3\u9501\u6216\u9501\u5B9A\u4EA4\u6613"},TrdSubAccPush:{cmd:2008,name:o.Trd_SubAccPush,description:"\u8BA2\u9605\u63A5\u6536\u63A8\u9001\u6570\u636E\u7684\u4EA4\u6613\u8D26\u6237"},TrdGetFunds:{cmd:2101,name:o.Trd_GetFunds,description:"\u83B7\u53D6\u8D26\u6237\u8D44\u91D1"},TrdGetPositionList:{cmd:2102,name:o.Trd_GetPositionList,description:"\u83B7\u53D6\u8D26\u6237\u6301\u4ED3"},TrdGetMaxTrdQtys:{cmd:2111,name:o.Trd_GetMaxTrdQtys,description:"\u83B7\u53D6\u6700\u5927\u4EA4\u6613\u6570\u91CF"},TrdGetOrderList:{cmd:2201,name:o.Trd_GetOrderList,description:"\u83B7\u53D6\u8BA2\u5355\u5217\u8868"},TrdPlaceOrder:{cmd:2202,name:o.Trd_PlaceOrder,description:"\u4E0B\u5355"},TrdModifyOrder:{cmd:2205,name:o.Trd_ModifyOrder,description:"\u4FEE\u6539\u8BA2\u5355"},TrdGetOrderFillList:{cmd:2211,name:o.Trd_GetOrderFillList,description:"\u83B7\u53D6\u6210\u4EA4\u5217\u8868"},TrdGetHistoryOrderList:{cmd:2221,name:o.Trd_GetHistoryOrderList,description:"\u83B7\u53D6\u5386\u53F2\u8BA2\u5355\u5217\u8868"},TrdGetHistoryOrderFillList:{cmd:2222,name:o.Trd_GetHistoryOrderFillList,description:"\u83B7\u53D6\u5386\u53F2\u6210\u4EA4\u5217\u8868"},TrdGetMarginRatio:{cmd:2223,name:o.Trd_GetMarginRatio,description:"\u83B7\u53D6\u878D\u8D44\u878D\u5238\u6570\u636E"},TrdGetOrderFee:{cmd:2225,name:o.Trd_GetOrderFee,description:"\u83B7\u53D6\u8BA2\u5355\u6536\u8D39\u660E\u7EC6\u6570\u636E"},TrdFlowSummary:{cmd:2226,name:o.Trd_FlowSummary,description:"\u83B7\u53D6\u8D44\u91D1\u6D41\u6C34"}};var c=y(require("futu-proto"),1),G={Notify:{cmd:1003,name:c.Notify,description:"\u63A8\u9001\u901A\u77E5"},QotUpdateBasicQot:{cmd:3005,name:c.Qot_UpdateBasicQot,description:"\u63A8\u9001\u57FA\u672C\u884C\u60C5"},QotUpdateKL:{cmd:3007,name:c.Qot_UpdateKL,description:"\u63A8\u9001K\u7EBF"},QotUpdateRT:{cmd:3009,name:c.Qot_UpdateRT,description:"\u83B7\u53D6\u5206\u65F6"},QotUpdateTicker:{cmd:3011,name:c.Qot_UpdateTicker,description:"\u63A8\u9001\u9010\u7B14"},QotUpdateOrderBook:{cmd:3013,name:c.Qot_UpdateOrderBook,description:"\u63A8\u9001\u4E70\u5356\u76D8"},QotUpdateBroker:{cmd:3015,name:c.Qot_UpdateBroker,description:"\u63A8\u9001\u7ECF\u7EAA\u961F\u5217"},QotUpdatePriceReminder:{cmd:3019,name:c.Qot_UpdatePriceReminder,description:"\u63A8\u9001\u5230\u4EF7\u63D0\u9192"},TrdUpdateOrder:{cmd:2208,name:c.Trd_UpdateOrder,description:"\u8BA2\u5355\u72B6\u6001\u53D8\u52A8\u901A\u77E5(\u63A8\u9001)"},TrdUpdateOrderFill:{cmd:2218,name:c.Trd_UpdateOrderFill,description:"\u6210\u4EA4\u901A\u77E5(\u63A8\u9001)"}};var S=({protobuf:s,errorCode:e,errorMessage:t},n)=>{if(e)throw new Error(`errorCode: ${e}, errorMessage: ${t}`);let{s2c:i,retMsg:d,retType:p}=n(s);if(p)throw new Error(`retType: ${p}, retMsg: ${d}`);return i},_=class{reqFn;subFn;constructor(e,t){this.reqFn=({name:n,cmd:i,description:d},p,l=5e3)=>new Promise(async(a,u)=>{let m=n.Request.encode(n.Request.create(p)).finish(),Q=(await e)(i,m,b=>{try{a(S(b,n.Response.decode))}catch({message:q}){u(new Error(`${d}, ${q}`))}finally{clearTimeout(R),Q()}}),R=setTimeout(()=>{u(new Error(`${d} timeout`)),Q()},l)}),this.subFn=({name:n,cmd:i,description:d},p)=>t(i,l=>{try{p(S(l,n.Response.decode))}catch({message:a}){console.error(`${d}, ${a}`)}})}InitWebSocket=(e,t=5e3)=>this.reqFn(r.InitWebSocket,{c2s:e},t);GetGlobalState=(e,t=5e3)=>this.reqFn(r.GetGlobalState,{c2s:e},t);KeepAlive=(e,t=5e3)=>this.reqFn(r.KeepAlive,{c2s:e},t);GetUserInfo=(e,t=5e3)=>this.reqFn(r.GetUserInfo,{c2s:e},t);GetDelayStatistics=(e,t=5e3)=>this.reqFn(r.GetDelayStatistics,{c2s:e},t);Sub=e=>this.reqFn(r.QotSub,{c2s:e});RegQotPush=(e,t=5e3)=>this.reqFn(r.QotRegQotPush,{c2s:e},t);GetSubInfo=(e,t=5e3)=>this.reqFn(r.QotGetSubInfo,{c2s:e},t);GetBasicQot=(e,t=5e3)=>this.reqFn(r.QotGetBasicQot,{c2s:e},t);GetKL=(e,t=5e3)=>this.reqFn(r.QotGetKL,{c2s:e},t);GetRT=(e,t=5e3)=>this.reqFn(r.QotGetRT,{c2s:e},t);GetTicker=(e,t=5e3)=>this.reqFn(r.QotGetTicker,{c2s:e},t);GetOrderBook=(e,t=5e3)=>this.reqFn(r.QotGetOrderBook,{c2s:e},t);GetBroker=(e,t=5e3)=>this.reqFn(r.QotGetBroker,{c2s:e},t);GetHistoryKL=(e,t=5e3)=>this.reqFn(r.QotGetHistoryKL,{c2s:e},t);GetHistoryKLPoints=(e,t=5e3)=>this.reqFn(r.QotGetHistoryKLPoints,{c2s:e},t);GetRehab=(e,t=5e3)=>this.reqFn(r.QotGetRehab,{c2s:e},t);RequestHistoryKL=(e,t=5e3)=>this.reqFn(r.QotRequestHistoryKL,{c2s:e},t);RequestHistoryKLQuota=(e,t=5e3)=>this.reqFn(r.QotRequestHistoryKLQuota,{c2s:e},t);RequestRehab=(e,t=5e3)=>this.reqFn(r.QotRequestRehab,{c2s:e},t);GetSuspend=(e,t=5e3)=>this.reqFn(r.QotGetSuspend,{c2s:e},t);GetStaticInfo=(e,t=5e3)=>this.reqFn(r.QotGetStaticInfo,{c2s:e},t);GetSecuritySnapshot=(e,t=5e3)=>this.reqFn(r.QotGetSecuritySnapshot,{c2s:e},t);GetPlateSet=(e,t=5e3)=>this.reqFn(r.QotGetPlateSet,{c2s:e},t);GetPlateSecurity=(e,t=5e3)=>this.reqFn(r.QotGetPlateSecurity,{c2s:e},t);GetReference=(e,t=5e3)=>this.reqFn(r.QotGetReference,{c2s:e},t);GetOwnerPlate=(e,t=5e3)=>this.reqFn(r.QotGetOwnerPlate,{c2s:e},t);GetHoldingChangeList=(e,t=5e3)=>this.reqFn(r.QotGetHoldingChangeList,{c2s:e},t);GetOptionChain=(e,t=5e3)=>this.reqFn(r.QotGetOptionChain,{c2s:e},t);GetWarrant=(e,t=5e3)=>this.reqFn(r.QotGetWarrant,{c2s:e},t);GetCapitalFlow=(e,t=5e3)=>this.reqFn(r.QotGetCapitalFlow,{c2s:e},t);GetCapitalDistribution=(e,t=5e3)=>this.reqFn(r.QotGetCapitalDistribution,{c2s:e},t);GetUserSecurity=(e,t=5e3)=>this.reqFn(r.QotGetUserSecurity,{c2s:e},t);ModifyUserSecurity=(e,t=5e3)=>this.reqFn(r.QotModifyUserSecurity,{c2s:e},t);StockFilter=(e,t=5e3)=>this.reqFn(r.QotStockFilter,{c2s:e},t);GetCodeChange=(e,t=5e3)=>this.reqFn(r.QotGetCodeChange,{c2s:e},t);GetIpoList=(e,t=5e3)=>this.reqFn(r.QotGetIpoList,{c2s:e},t);GetFutureInfo=(e,t=5e3)=>this.reqFn(r.QotGetFutureInfo,{c2s:e},t);RequestTradeDate=(e,t=5e3)=>this.reqFn(r.QotRequestTradeDate,{c2s:e},t);SetPriceReminder=(e,t=5e3)=>this.reqFn(r.QotSetPriceReminder,{c2s:e},t);GetPriceReminder=(e,t=5e3)=>this.reqFn(r.QotGetPriceReminder,{c2s:e},t);GetUserSecurityGroup=(e,t=5e3)=>this.reqFn(r.QotGetUserSecurityGroup,{c2s:e},t);GetMarketState=(e,t=5e3)=>this.reqFn(r.QotGetMarketState,{c2s:e},t);GetOptionExpirationDate=(e,t=5e3)=>this.reqFn(r.QotGetOptionExpirationDate,{c2s:e},t);GetAccList=(e,t=5e3)=>this.reqFn(r.TrdGetAccList,{c2s:e},t);UnlockTrade=(e,t=5e3)=>this.reqFn(r.TrdUnlockTrade,{c2s:e},t);SubAccPush=e=>this.reqFn(r.TrdSubAccPush,{c2s:e});GetFunds=(e,t=5e3)=>this.reqFn(r.TrdGetFunds,{c2s:e},t);GetPositionList=(e,t=5e3)=>this.reqFn(r.TrdGetPositionList,{c2s:e},t);GetMaxTrdQtys=(e,t=5e3)=>this.reqFn(r.TrdGetMaxTrdQtys,{c2s:e},t);GetOrderList=(e,t=5e3)=>this.reqFn(r.TrdGetOrderList,{c2s:e},t);PlaceOrder=(e,t=5e3)=>this.reqFn(r.TrdPlaceOrder,{c2s:e},t);ModifyOrder=(e,t=5e3)=>this.reqFn(r.TrdModifyOrder,{c2s:e},t);GetOrderFillList=(e,t=5e3)=>this.reqFn(r.TrdGetOrderFillList,{c2s:e},t);GetHistoryOrderList=(e,t=5e3)=>this.reqFn(r.TrdGetHistoryOrderList,{c2s:e},t);GetHistoryOrderFillList=(e,t=5e3)=>this.reqFn(r.TrdGetHistoryOrderFillList,{c2s:e},t);GetMarginRatio=(e,t=5e3)=>this.reqFn(r.TrdGetMarginRatio,{c2s:e},t);GetOrderFee=(e,t=5e3)=>this.reqFn(r.TrdGetOrderFee,{c2s:e},t);FlowSummary=(e,t=5e3)=>this.reqFn(r.TrdFlowSummary,{c2s:e},t);Notify=e=>this.subFn(G.Notify,e);UpdateBasicQot=e=>this.subFn(G.QotUpdateBasicQot,e);UpdateKL=e=>this.subFn(G.QotUpdateKL,e);UpdateRT=e=>this.subFn(G.QotUpdateRT,e);UpdateTicker=e=>this.subFn(G.QotUpdateTicker,e);UpdateOrderBook=e=>this.subFn(G.QotUpdateOrderBook,e);UpdateBroker=e=>this.subFn(G.QotUpdateBroker,e);UpdatePriceReminder=e=>this.subFn(G.QotUpdatePriceReminder,e);UpdateOrder=e=>this.subFn(G.TrdUpdateOrder,e);UpdateOrderFill=e=>this.subFn(G.TrdUpdateOrderFill,e)};var M=(s,e)=>{let t=new Map,n={},i=typeof window>"u"?new(require("ws"))(s):new WebSocket(s);i.binaryType="arraybuffer";let d=(a,u,m)=>{let{session:Q,message:R}=F(a,u);if(i.readyState!==WebSocket.OPEN)throw new Error("WebSocket closed");return i.send(R),t.set(Q,m),()=>{t.delete(Q)}},p=(a,u)=>(n[a]||(n[a]=[]),n[a].push(u),()=>{n[a]=n[a].filter(m=>m!==u)}),l=new Promise((a,u)=>{i.addEventListener("open",()=>{new _(Promise.resolve(d),p).InitWebSocket({websocketKey:e?P.default.createHash("md5").update(e).digest("hex"):"",programmingLanguage:"JavaScript"}).then(()=>a(d)).catch(u)}),i.addEventListener("message",m=>{let{session:Q,cmd:R,message:b}=h(m.data);if(n[R])for(let q of n[R])q(b);else t.get(Q)?.(b)}),i.addEventListener("close",m=>{u(m)})});return{webSocket:i,webRequest:new _(l,p)}};0&&(module.exports={getFutuApi});