futunnopen / py-futu-api Goto Github PK
View Code? Open in Web Editor NEW富途 OpenAPI Python SDK
License: Apache License 2.0
富途 OpenAPI Python SDK
License: Apache License 2.0
您好:
我在pycharm 载入了 futu library 后再打包成.exe
.exe 开启后未能如常运作,打开任务管理器后发现.exe 程序在不停自我复制。
即使仅仅加载library 而不使用亦出现此问题。
我的测试python code 如下:
from futu import *
if name == "main":
print('Hello')
input()
但是用pycharm 运作完全正常。
转了新版后,debug信息怎样停止显示?
为什么以下的信息不停的显示?可否禁止?
[network_manager.py] do_send:283: Send: conn_id=1; proto_id=3001; serial_no=2583; total_len=66;
[network_manager.py] _on_packet:563: Recv: conn_id=1; proto_id=3011; serial_no=0; data_len=84; msg=;
[network_manager.py] _on_packet:563: Recv: conn_id=1; proto_id=3001; serial_no=2583; data_len=6; msg=;
[network_manager.py] _on_read:496: conn_id=1; elapsed=0.002033233642578125; recv_len=178; buf_len=178;
Traceback (most recent call last):
File "./hk_ipo_history_price.py", line 1, in
import futu as ft
File "/usr/local/lib/python3.6/dist-packages/futu/init.py", line 22, in
from futu.quote.open_quote_context import OpenQuoteContext
File "/usr/local/lib/python3.6/dist-packages/futu/quote/open_quote_context.py", line 11, in
from futu.common.open_context_base import OpenContextBase, ContextStatus
File "/usr/local/lib/python3.6/dist-packages/futu/common/open_context_base.py", line 11, in
from futu.common.utils import *
File "/usr/local/lib/python3.6/dist-packages/futu/common/utils.py", line 8, in
from futu.common.conn_mng import *
File "/usr/local/lib/python3.6/dist-packages/futu/common/conn_mng.py", line 5, in
from futu.common.constant import *
File "/usr/local/lib/python3.6/dist-packages/futu/common/constant.py", line 140, in
from futu.common.pb import Trd_Common_pb2
File "/usr/local/lib/python3.6/dist-packages/futu/common/pb/Trd_Common_pb2.py", line 17, in
import Common_pb2 as Common__pb2
File "/usr/local/lib/python3.6/dist-packages/futu/common/pb/Common_pb2.py", line 107, in
options=None, file=DESCRIPTOR),
TypeError: new() got an unexpected keyword argument 'file'
示例代码
import futu as ft
quote_ctx = ft.OpenQuoteContext(host='127.0.0.1', port=11111)
print(quote_ctx.get_market_snapshot('HK.00700'))
quote_ctx.close()
官方接口文档404了。
I tried history_order_list_query()/history_deal_list_query()/order_list_query()/deal_list_query(), and none of them show me conditional orders.
Is conditional orders query supported?
什么时候能把咨询api开放出来啊?快讯这些是实时的么,像twitter的tweepy一样,可以获得一些实时资讯。
futu-api version 3.21.0
macos 10.13.3
Is this an individual case?
print(quote_ctx.get_market_snapshot(['SH.600031']))
Connected to pydev debugger (build 193.6494.30)
2020-04-25 17:52:02,844 [open_context_base.py] _socket_reconnect_and_wait_ready:256: Start connecting: host=127.0.0.1; port=11111;
2020-04-25 17:52:02,845 [open_context_base.py] on_connected:344: Connected : conn_id=1;
2020-04-25 17:52:02,848 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=1; info={'server_version': 209, 'login_user_id': 14701153, 'conn_id': 6659931993677367405, 'conn_key': '98F7980C6A904006', 'conn_iv': 'FAF155F15A241BAC', 'keep_alive_interval': 10, 'is_encrypt': False};
(0, code update_time ... after_change_rate after_amplitude
0 SH.600031 2020-04-24 15:00:00 ... N/A N/A
[1 rows x 123 columns])
1) 显示有123 列,但是都是省略号,看不见股票信息,如何才能显示全部信息呢,打印到csv 也是省略号,没有实际信息;
2) 存到CSV 文件中的时候,所有内容都在一行一列里面,怎么能让123 columns 分别显示在123 列里面呢?
ssh免密码登录
1、客户端即A端生成RSA公钥和私钥
2、我们自己(A端)保留自己的私钥,然后把公钥id_rsa.pub存放到B端
富途的openapiD的登录配置方式有6种(富途intro文档 https://futunnopen.github.io/futu-api-doc/intro/FutuOpenDGuide.html#id7)
1.命令行证书登录
2.命令行帐号密码密文登录
3.命令行帐号密码明文登录
4.配置文件证书登录
5.配置文件帐号密码密文登录
6.配置文件帐号密码明文登录
第4中就是类同于ssh免密码登录吧,请问,公钥id_rsa.pub需要上传到富途的服务器上吗?如何传?
Hello there, I am new to programming as well as the API. I was wondering how I could make use of the data existing on FUTU and import the data into Multicharts. In short, I am trying to use Multicharts for my decision making tools and help me do the trades automatically, with my FUTU account linked with it.
get_market_snapshot()接口获取美股数据时95%概率失败,少数股票才成功。
例如:quote_ctx.get_market_snapshot(['US.TSLA'])
得到返回:(-1, 'NN_ProtoRet_TimeOut')
获取A股和港股正常。
限制1000笔基本上只能获取到下午的数据, 上午的就获取不了了
如果我用回以前futuqant 的module 的話則沒有問題
但用futu這個module 的話 他會顯示沒有OpenQuoteContext
import futu as ft
quote_ctx = ft.OpenQuoteContext(host='127.0.0.1', port=11111)
print(quote_ctx.get_market_snapshot('HK.00700'))
quote_ctx.close()
找不到这个模块
Qot_Sub.proto - 3001订阅或者反订阅
Qot_RegQotPush.proto - 3002注册行情推送
这两个协议看起来十分相似,似乎订阅后的 security 还需要再注册推送后才可以获得推送。
请问将 3001 3002 区分设计的考量是什么?可否合并成一个?
在vntrader gateway连接好之后,输入代码,回车
可以查询到 代码对应的名称
futu log :
03-19 18:27:39(1584613659.580950) | 10420 | F3C | Info | Quote | SendSubReq By LasSubFailed
03-19 18:27:39(1584613659.580950) | 10420 | F3C | Info | Quote | SubQot 6211 Ret=1 UID=636726 AID=0 RK=3967188186676871702 SNO=16918 , enMktType = 2
03-19 18:27:39(1584613659.581963) | 10420 | F3C | Info | Quote | SubQot 6211 Ret=1 UID=636726 AID=0 RK=3967188186676871703 SNO=16919 , enMktType = 11
BlockingStatusThread 0 1584613662 class OMTcpServerImpl 9812
BlockingStatusThread 0 1584613662 class GTWWebSocket 10268
03-19 18:27:46(1584613666.629723) | 10420 | F3C | Info | Quote | OnReply_SubOrUnSub 6211 nReqKey=3967188186676871701 nSenderID=923682979 nSerialNo=16917 enProtoRet=-10000 nSvrRet=0
......\Src\NNProtoCenter\Quote\NNBiz_Qot_PushQot.cpp 488
03-19 18:27:46(1584613666.678607) | 10420 | F3C | Info | Quote | SendSubReq By LasSubFailed
03-19 18:27:46(1584613666.679602) | 10420 | F3C | Info | Quote | SubQot 6211 Ret=1 UID=636726 AID=0 RK=3967188186676871704 SNO=16920 , enMktType = 2
没法获得美股行情快照
运行一段时间挂死了,通过python trace功能看到是在调用这个函数时挂死的(没有返回),没有继续往下追踪,希望能及时解决。
unsubscribe(self, code_list, subtype_list)
Since now FUTU is on the US market, it makes sense to provide English translation for everything as well.
In the returning data of OrderBookHandlerBase
.on_recv_rsp
, for example
{'code': 'HK.MHI2005', 'svr_recv_time_bid': '2020-05-07 15:07:42.8', 'svr_recv_time_ask': '2020-05-07 15:07:42.8', 'Bid': [...], 'Ask': [...]}
I receive time string of svr_recv_time_bid
and svr_recv_time_ask
like the following
2020-05-07 15:07:42
2020-05-07 15:07:42.8
2020-05-07 15:07:42.88
2020-05-07 15:07:42.888
Originally, I thought that 2020-05-07 15:07:42.8
means 2020-05-07 15:07:42.800
. However, when I collected data later. I found statistically there are no timestamp that mili-second is starting with 0, i.e. format like yyyy-MM-dd hh:mm:ss.0zz
or yyyy-MM-dd hh:mm:ss.00z
.
So I infer that 2020-05-07 15:07:42.8
actually means 2020-05-07 15:07:42.008
. This is not a conventional format of time! And should be considered as a bug.
缺少市值,发行股数等信息,请补充
print(quote_ctx.get_market_snapshot('US.AAPL'))
(-1, 'NN_ProtoRet_TimeOut')
Suppressed: java.lang.UnsatisfiedLinkError: dlopen(/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib, 9): no suitable image found. Did find:
/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib: code signature invalid for '/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib'
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
... 57 more
Suppressed: java.lang.UnsatisfiedLinkError: dlopen(/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib, 9): no suitable image found. Did find:
/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib: code signature invalid for '/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib'
/Users/.../GIT/futu-open-api/libFTAPIChannel.dylib: stat() failed with errno=1
python == 3.6.5
futu-api == 3.6.3
FutuOpenD == 1.08_Mac
美股 request_history_kline 返回 (-1, 'NN_ProtoRet_TimeOut').
code = 'US.AAPL'
# code = 'HK.00700'
start_date = '2018-12-01'
end_date = '2018-12-28'
ret, data, page_req_key = quote_ctx.request_history_kline(
code,
start=start_date,
end=end_date,
ktype=KLType.K_1M,
max_count=50,
) # 请求开头50个数据
但是港股就没问题。
按照说明操作,但是配上rsa_private_key连接就会异常。提示
[network_manager.py] _on_packet:532: Recv: conn_id=1; proto_id=1001; serial_no=9429; data_len=128; msg=proto id:1001 conn_id:0 check sha error!;
即使用示例的RSA文件也不行,怀疑哪里有问题。
获取市场快照,股票代码设置成港股时可以正常返回,设置成美股时就无法正常返回。
代码如下:
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
print(quote_ctx.get_market_snapshot('US.AAPL'))
quote_ctx.close()
报错:
(-1, 'NN_ProtoRet_TimeOut')
這個this.state.login根本沒有用,因為就算是密碼不正確也是true.
if (response.buff != null && response.error == 0) {
console.debug("登录成功");
if (!this.state.closing) {
this.state.login = true;
// 登录成功了回调一下
if (this.onlogin != undefined && typeof this.onlogin == 'function') {
this.onlogin(true, response);
}
}
}
RTRT
这个项目和 futuquant 项目是什么关系?
在期货帐号中,Trd_GetPositionList返回的持仓列表中包含港期和美期,但没有币种字段,只能再从Qot_GetFutureInfo中获取币种。
请问一下, 我运行涉及到高频行情的demo就报这个错,怎么解决?
代码如下:
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
quote_ctx.subscribe('SZ.002170', [ft.SubType.QUOTE, ft.SubType.TICKER, ft.SubType.K_DAY, ft.SubType.ORDER_BOOK, ft.SubType.RT_DATA, ft.SubType.BROKER])
print(quote_ctx.get_rt_ticker('SZ.002170'))
报错如下:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/Users/chenkai/Desktop/TestProject/futu-test/futu/common/network_manager.py", line 247, in _thread_func
self.poll()
File "/Users/chenkai/Desktop/TestProject/futu-test/futu/common/network_manager.py", line 197, in poll
self._on_read(conn)
File "/Users/chenkai/Desktop/TestProject/futu-test/futu/common/network_manager.py", line 487, in _on_read
self._on_packet(conn, head_dict, Err.Ok.code, '', rsp_body)
File "/Users/chenkai/Desktop/TestProject/futu-test/futu/common/network_manager.py", line 550, in _on_packet
rsp_pb = binary2pb(rsp_body, head_dict['proto_id'], head_dict['proto_fmt_type'])
File "/Users/chenkai/Desktop/TestProject/futu-test/futu/common/utils.py", line 485, in binary2pb
return json2pb(type(rsp), b.decode('utf-8'))
NameError: name 'json2pb' is not defined
如上,謝謝
用get_rehab
在线获取复权因子表,表中如下字段精度不足:
虽然数据类型是float
,但是小数部分都是0,看起来像是float(int(ratio))
,而且document中对此字段的解释是错误的,例如per_share_trans_ratio并不是每股转增股比例,并不是一个百分比,比如说SH.600489在2009-06-05每10股转增12股,这个ratio是用10.0 / 12.0 = 0.8333
,如果是10股配3股,这个ratio是10.0 / 3.0 = 3.3333
,通常这种类型的数据要保留四位小数,精度不够则无法使用。在futuquant版本中,get_autype_list
得到的数据还是有很多位小数的。
烦请尽快检查下
futu-api 3.19.0
import futu as ft
quote_ctx = ft.OpenQuoteContext(host='127.0.0.1', port=11111)
print(quote_ctx.get_market_snapshot('HK.00700'))
quote_ctx.close()
trade_us_ctx.place_order(price=1.1, qty=1, code='US.AAPL190215P140000', trd_side=ft.TrdSide.BUY, order_type=ft.OrderType.NORMAL, trd_env=ft.TrdEnv.SIMULATE)
return (-1, '不是可交易的证券类型')
美股期权的code是US.AAPL190215P140000这样填写吗
FutuOpenD version 1.08
python futu api version 3.6.3
参考这个 demo:
def handle_data(self):
"""
handle stock data for trading signal, and make order
"""
# 读取历史数据,使用sma方式计算均线准确度和数据长度无关,但是在使用ema方式计算均线时建议将历史数据窗口适当放大,结果会更加准确
today = datetime.datetime.today()
pre_day = (today - datetime.timedelta(days=self.observation)
).strftime('%Y-%m-%d')
end_dt = today.strftime('%Y-%m-%d')
ret_code, prices, page_req_key = self.quote_ctx.request_history_kline(self.stock, start=pre_day, end=end_dt, ktype=ft.KLType.K_MON)
if ret_code != ft.RET_OK:
print("request_history_kline fail: {}".format(prices))
return
else:
print("====== prices =====")
print(prices)
# 用talib计算MACD取值,得到三个时间序列数组,分别为 macd, signal 和 hist
# macd 是长短均线的差值,signal 是 macd 的均线
# 使用 macd 策略有几种不同的方法,我们这里采用 macd 线突破 signal 线的判断方法
macd, signal, hist = talib.MACD(prices['close'].values,
self.short_period, self.long_period,
self.smooth_period)
print("====== macd =====")
print(macd)
直接把 handle_data()
结果打印出来而已,其中在 request_history_kline
额外加了 ft.KLType.K_MON
,运行结果全身 nan
于此同时,futu 主 app 是可以看到 MACD 的月K线图的:
请问有API获取 MACD 月线数据么?
-1 行情权限不足
这个怎么开通权限? 刚接触,想尝试量化 。获取行情就这个提示。 改怎么提高权限?
2.2.400的新增的自选股接口在新增自选分组股票后也会在默认的"全部"分组增加,删除对应分组股票时不会在"全部"里删除,系统也没有提供"全部"这个默认分组,导致很快达到自选股上限,无法再新增股票。
返回: NN_ProtoRet_TimeOut
你好,如不需要显示debug信息,可以在FutuOpenD.xml文件中修改log_level为info或者更高的日志等级 即可停止debug信息的显示。
如仍有问题,可通过用户反馈群(号码:229850364)找管理员解决,谢谢。
之前问的问题,试过行不通,在群已反馈,还没有答复。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.