תיקון שגיאות חיבור TWS API באמצעות ציון הפורט
מאמר Quant Q&A · מחבר: user3064222
סיכום
המסמך מתאר חיבור ל-Trader Workstation של Interactive Brokers שהיה מסוגל לשלוח הוראות דרך ibPy, אך החזיר שגיאת חיבור בעת בקשת עדכוני חשבון. הודעת השגיאה הצביעה על הגדרת לקוח ה-socket, שהמשתמש כבר הפעיל, ולכן הסיבה לא הייתה ברורה.
התשובה מזהה את ארגומנט הפורט החסר בהגדרת החיבור ומציינת שפורט 7497 עבד במקרה של אותו משתמש. זהו טיפ נקודתי לפתרון תקלות, ולא הסבר כללי לעדכוני חשבון או להגדרת API. הפורט עשוי להיות תלוי בהגדרות TWS או בהגדרות של מסחר מדומה, והמסמך אינו מספק שלבי אימות רחבים יותר או ראיות מעבר לדיווח המשיב שהפתרון עבד.
רעיונות מרכזיים
- שגיאת TWS API במהלך עדכוני חשבון עשויה להימשך גם כאשר לקוחות socket מופעלים.
- הפתרון המוצע הוא לציין את פורט החיבור בעת יצירת חיבור 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 על סמך המקור; הוא אינו העתק של המקור.