使用下面的标准代码,我可以使用免费的模拟账户提交市价单(MKT)和限价单(LMT)
from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
def make_contract(symbol, sec_type, exch, prim_exch, curr):
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 make_order(action, quantity, price=None):
if price is not None:
order = Order()
order.m_orderType = 'LMT'
order.m_totalQuantity = quantity
order.m_action = action
order.m_lmtPrice = price
else:
order = Order()
order.m_orderType = 'MKT'
order.m_totalQuantity = quantity
order.m_action = action
return order
def main():
conn = Connection.create(port=7496, clientId=999)
conn.connect()
oid = 100001
cont = make_contract('TSLA', 'STK', 'SMART', 'SMART', 'USD')
offer = make_order('BUY', 100, 315)
conn.placeOrder(oid, cont, offer)
conn.disconnect()
main()
有人有提交 LOO 或 MOO 订单的经验吗?当我改变时:
order.m_orderType = 'LOO'
我没有遇到异常,但是在 IB TWS(演示)中没有显示挂单。