FutunnOpen / py-futu-api

富途 OpenAPI Python SDK
Apache License 2.0
1.03k stars 221 forks source link

Connect fail: conn_id=4; msg=ECONNREFUSED #112

Open RayCooo opened 2 years ago

RayCooo commented 2 years ago

pip install futu-api from futu import * quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111) # 这行出了下面的ERROR ret, data = quote_ctx.get_market_state(['HK.00700']) if ret == RET_OK: print(data) else: print('error:', data)

ERROR: 2022-01-14 01:50:46,683 | 62 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=4; msg=ECONNREFUSED 2022-01-14 01:50:54,695 | 62 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=5; msg=ECONNREFUSED

初学Futu API 与 Python. 已 login 及 connect FutuOpenD。 请教如何解决?

byblehua commented 2 years ago

是否已经解决,还有问题可以通过下面的渠道找我们解决

aiot-tech commented 2 years ago

出现了同样的问题,请问这是什么原因呢?在输入以下代码时,需要做什么前提操作吗?

In [1]: from futu import * 
   ...: trd_ctx = OpenHKTradeContext(host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUSECURITIES) 
   ...: ret, data = trd_ctx.get_acc_list() 
   ...: if ret == RET_OK: 
   ...:     print(data) 
   ...: else: 
   ...:     print('get_acc_list error: ', data) 
   ...: trd_ctx.close()                                                                                                                                                                                     

2022-06-22 17:54:41,892 | 11772 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=1; msg=ECONNREFUSED
2022-06-22 17:54:49,902 | 11772 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=2; msg=ECONNREFUSED
2022-06-22 17:54:57,909 | 11772 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=3; msg=ECONNREFUSED
2022-06-22 17:55:05,919 | 11772 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=4; msg=ECONNREFUSED
2022-06-22 17:55:13,929 | 11772 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=5; msg=ECONNREFUSED
Benny-LL commented 2 years ago

this is my first try on FUTU api, and the below code is directly copied from FUTU's official guideline (https://openapi.futunn.com/futu-api-doc/quick/demo.html), but in vain, the Connect fail errors keep showing. are the host and port wrong? thanks!

from futu import *

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)  # 创建行情对象
print(quote_ctx.get_market_snapshot('HK.00700'))  # 获取港股 HK.00700 的快照数据
quote_ctx.close() # 关闭对象,防止连接条数用尽

trd_ctx = OpenSecTradeContext(host='127.0.0.1', port=11111)  # 创建交易对象
print(trd_ctx.place_order(price=500.0, qty=100, code="HK.00700", trd_side=TrdSide.BUY, trd_env=TrdEnv.SIMULATE))  # 模拟交易,下单(如果是真实环境交易,在此之前需要先解锁交易密码)

trd_ctx.close()  # 关闭对象,防止连接条数用尽

2022-06-22 09:57:27,354 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=9; msg=ECONNREFUSED 2022-06-22 09:57:35,365 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=10; msg=ECONNREFUSED 2022-06-22 09:57:43,375 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=11; msg=ECONNREFUSED

yezhengli-Mr9 commented 1 year ago

this is my first try on FUTU api, and the below code is directly copied from FUTU's official guideline (https://openapi.futunn.com/futu-api-doc/quick/demo.html), but in vain, the Connect fail errors keep showing. are the host and port wrong? thanks!

from futu import *

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)  # 创建行情对象
print(quote_ctx.get_market_snapshot('HK.00700'))  # 获取港股 HK.00700 的快照数据
quote_ctx.close() # 关闭对象,防止连接条数用尽

trd_ctx = OpenSecTradeContext(host='127.0.0.1', port=11111)  # 创建交易对象
print(trd_ctx.place_order(price=500.0, qty=100, code="HK.00700", trd_side=TrdSide.BUY, trd_env=TrdEnv.SIMULATE))  # 模拟交易,下单(如果是真实环境交易,在此之前需要先解锁交易密码)

trd_ctx.close()  # 关闭对象,防止连接条数用尽

2022-06-22 09:57:27,354 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=9; msg=ECONNREFUSED 2022-06-22 09:57:35,365 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=10; msg=ECONNREFUSED 2022-06-22 09:57:43,375 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=11; msg=ECONNREFUSED

Hi @Benny-LL , @byblehua , @aiot-tech, @RayCooo have you resolved it? Do not feel following conduct reconnect? https://github.com/FutunnOpen/py-futu-api/blob/5a8064a09f4456657e746655f3164cdbc22aa606/futu/common/open_context_base.py#L478-L495

byblehua commented 1 year ago

Please check if your opend is working properly. If not , make it work. If it don’t work, you can contract us with qq group. https://openapi.futunn.com/futu-api-doc/qa/other.html#8274

byblehua(华柏波) 互联网业务研发部-数据应用研发中心-Open API开发组

2022年11月26日 上午11:22,Yezheng Li @.**@.>> 写道:

this is my first try on FUTU api, and the below code is directly copied from FUTU's official guideline (https://openapi.futunn.com/futu-api-doc/quick/demo.html), but in vain, the Connect fail errors keep showing. are the host and port wrong? thanks!

from futu import *

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111) # 创建行情对象 print(quote_ctx.get_market_snapshot('HK.00700')) # 获取港股 HK.00700 的快照数据 quote_ctx.close() # 关闭对象,防止连接条数用尽

trd_ctx = OpenSecTradeContext(host='127.0.0.1', port=11111) # 创建交易对象 print(trd_ctx.place_order(price=500.0, qty=100, code="HK.00700", trd_side=TrdSide.BUY, trd_env=TrdEnv.SIMULATE)) # 模拟交易,下单(如果是真实环境交易,在此之前需要先解锁交易密码)

trd_ctx.close() # 关闭对象,防止连接条数用尽

2022-06-22 09:57:27,354 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=9; msg=ECONNREFUSED 2022-06-22 09:57:35,365 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=10; msg=ECONNREFUSED 2022-06-22 09:57:43,375 | 58 | [open_context_base.py] _connect_sync:287: Connect fail: conn_id=11; msg=ECONNREFUSED

Hi @Benny-LLhttps://github.com/Benny-LL , @byblehuahttps://github.com/byblehua , have you resolved it?

— Reply to this email directly, view it on GitHubhttps://github.com/FutunnOpen/py-futu-api/issues/112#issuecomment-1327970381, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ5GVITEKBNGH36SIPERKD3WKF675ANCNFSM5L5QSJSA. You are receiving this because you were mentioned.Message ID: @.***>

jiunaing commented 1 year ago

Has the above issue been resolved? I tried. And I got the same error

samw212 commented 1 year ago

Facing same issue here

bransonngai commented 6 months ago

Same here

cottrellam commented 2 months ago

Did anyone find a solution for this? I am having the same issue.