我試圖使用下面的代碼嘗試發送訂單到TWS放置在谷歌共享。我不明白爲什麼它不斷要求一個帳戶,我有TWS打開,並已檢查啓用ActiveX等。我也檢查了插座號碼和客戶端ID是正確的。IbPy無法發送訂單 - 必須指定一個賬戶
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
import time
def error_handler(msg):
print "Server Error: %s" % msg
def reply_handler(msg):
print "Server Response: %s, %s" % (msg.typeName, msg)
def create_contract(symbol, sec_type, exch, prim_exch, curr):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
def create_order(order_type, quantity, action):
order = Order()
order.m_orderType = order_type
order.m_totalQuantity = quantity
order.m_action = action
return order
if __name__ == "__main__":
tws_conn = Connection.create(port=7496, clientId=100)
tws_conn.connect()
tws_conn.register(error_handler, 'Error')
tws_conn.registerAll(reply_handler)
order_id = 200
goog_contract = create_contract('GOOG', 'STK', 'SMART', 'SMART', 'USD')
goog_order = create_order('MKT', 5, 'BUY')
tws_conn.placeOrder(order_id, goog_contract, goog_order)
time.sleep(1)
tws_conn.disconnect()
我收到以下錯誤
Server Response: error, <error id=200, errorCode=321, errorMsg=Error validating request:-'ie' : cause - You must specify an account.
如果我在一個演示運行代碼IB賬戶的順序被放置和填充,所以一切正常!但是當我在我的紙幣交易賬戶中運行相同的代碼時,那就是當我收到上述錯誤消息時。
是否有人知道要「指定一個帳戶」,即在某處輸入我的帳號?
你有子賬戶嗎?你可以指定order.m_account,但我從來沒有。 https://www.interactivebrokers.com/en/software/api/apiguide/java/order.htm – brian
沒有子帳戶。我確實看到了order.m_account,但它的內容是「僅適用於機構客戶」。順便說一句,我將如何使用該order.m_account?即時通訊蟒蛇/ ibpy/IB api的東西很新。 –
你只需要嘗試不同的帳號。我讀過FA賬戶也使用它。 – brian