إصلاح أخطاء اتصال TWS API بتحديد المنفذ
مقال Quant Q&A · المؤلف: user3064222
الملخص
تصف الوثيقة اتصالًا ببرنامج Interactive Brokers Trader Workstation كان قادرًا على إرسال الأوامر عبر ibPy، لكنه أعاد خطأ اتصال عند طلب تحديثات الحساب. وأشارت رسالة الخطأ إلى إعداد عميل المقبس، الذي كان المستخدم قد فعّله بالفعل، فظل السبب غير واضح.
يحدد الرد وسيط المنفذ المفقود في إعداد الاتصال، ويذكر أن المنفذ 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 هذا الملخص استنادًا إلى المصدر الأصلي؛ وهو ليس نسخة منه.