這是使用 Python 在 IB 上下訂單的代碼。此代碼有效,但出現一個錯誤。最后我嘗試下訂單,但出現錯誤:Traceback (most recent call last):Getting the time from the server... File "C:/Users/B/PycharmProject/1/api1.py", line 117, in <module> order1 = order.Order()AttributeError: type object 'Order' has no attribute 'Order' IB error id -1 errorcode 2104 string Market data farm connection is OK:usfarm.njIB error id -1 errorcode 2104 string Market data farm connection is OK:usfutureIB error id -1 errorcode 2104 string Market data farm connection is OK:cashfarmIB error id -1 errorcode 2104 string Market data farm connection is OK:usfarmIB error id -1 errorcode 2106 string HMDS data farm connection is OK:ushmds.usIB error id -1 errorcode 2106 string HMDS data farm connection is OK:ilhmdsIB error id -1 errorcode 2106 string HMDS data farm connection is OK:njhmds1544354853 我想問題出在第 5 行和第 6 行。當我刪除它們時,我得到“名稱'訂單'未定義”。我想我只是錯誤地定義了它。也許有人面臨類似的問題/錯誤?
2 回答

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
該錯誤告訴您,您有一個order
沒有屬性的類Order
。那是因為這一行:
from ibapi.order import Order as order
在其中導入類 Order,但將其重命名為order
. 我不知道你為什么這樣做,但不要這樣做。要么導入模塊:
from ibapi import order
并保留您現有的實例化代碼:
order1 = order.Order()
或者,在不重命名的情況下導入類:
from ibapi.order import Order
并做
order1 = Order()

慕運維8079593
TA貢獻1876條經驗 獲得超5個贊
問題是您的導入:
from ibapi.order import Order as order
您將班級重命名Order
為order
.
不用嘗試,正確的方法應該是:
order1 = order()
添加回答
舉報
0/150
提交
取消