포트를 지정해 TWS API 연결 오류 해결하기
기사 Quant Q&A · 저자: user3064222
요약
이 문서는 ibPy를 통해 주문을 제출할 수 있었지만 계좌 업데이트를 요청할 때 연결 오류가 반환된 Interactive Brokers Trader Workstation 연결을 설명합니다. 오류 메시지는 소켓 클라이언트 설정을 가리켰지만, 사용자는 이미 해당 설정을 활성화해 원인이 불분명했습니다.
답변은 연결 설정에서 포트 인수가 빠진 점을 지적하고, 해당 사용자 사례에서 작동한 값으로 포트 7497을 제시합니다. 이는 계좌 업데이트나 API 설정 전반에 대한 설명이 아니라 제한적인 문제 해결 팁입니다. 포트는 TWS 또는 모의투자 설정에 따라 달라질 수 있으며, 문서에는 더 폭넓은 확인 절차나 응답자가 작동했다고 보고한 내용 이상의 근거가 없습니다.
핵심 아이디어
- 소켓 클라이언트를 활성화했어도 계좌 업데이트 중 TWS API 오류가 계속 발생할 수 있습니다.
- 제안된 해결 방법은 ibPy 연결을 만들 때 연결 포트를 지정하는 것입니다.
- 예시에서는 포트 7497을 사용하지만 모든 설정에 적용되는 값인지는 문서에서 확인하지 않습니다.
- 이전에는 주문 제출이 작동했던 이유를 답변에서 설명하지 않습니다.
태그
전문
# Trader Workstation on Ubuntu cannot be connected to via the API
# Trader Workstation on Ubuntu cannot be connected to via the API
I am using ibPy to connect to TWS on a fairly fresh ubuntu machine. I have been successful in logging into the paper trading account and submitting buy and sell orders programatically via the ibPy interface.
However, I am now trying to do more than simply submit orders. Namely, I am trying to obtain position updated from TWS. I am interested in successfully running the following code:
```
from time import sleep
from ib.opt import ibConnection, message
def error_handler(msg):
print(msg)
def acct_update(msg):
print(msg)
con = ibConnection(clientId=100)
con.register(acct_update,
message.updateAccountValue,
message.updateAccountTime,
message.updatePortfolio)
con.register(error_handler, "Error")
con.connect()
con.reqAccountUpdates(True, 'DU000000')
sleep(1)
con.disconnect()
```
When executed however I obtain the following error:
```
<error id=-1, errorCode=502, errorMsg=Couldn't connect to TWS.
Confirm that "Enable ActiveX and Socket Clients" is enabled on
the TWS "Configure->API" menu.>
```
I have ensured that indeed ActiveX and socket clients are enabled in the TWS preferences, so that is not the issue. It surprises me that I would be able to submit orders successfully but not obtain account updates from TWS. Does anyone know why this could be happening?
## Answer by Clebson Derivan (score 0)
https://quant.stackexchange.com/a/27473
you forgot the parameter port:
> con = ibConnection(port=7497, clientId=100)
works for me출처의 라이선스에 따라 출처를 표시하고 전문을 공개합니다. 라이선스: CC BY-SA 4.0 (Stack Exchange)
이 요약은 원문을 바탕으로 Stratmill의 리서치 에이전트가 작성했으며, 원문을 복사한 것이 아닙니다.