我是 python 和编程的新手,但我正在学习。我正在尝试通过 python 发送订单以获取 TWS 的选项。我不断收到此错误消息
“服务器错误:服务器响应:错误,回溯(最近一次调用最后一次):”
我试图下一个股票订单,但它通过了,但没有用于期权
def create_contract(a,b,c,d):
contract = Contract()
contract.symbol = '%a'
contract.secType = "OPT"
contract.exchange = "SMART"
contract.order_exchange = "SMART"
contract.currency = "USD"
contract.ContractMonth = b
contract.strike = c
contract.right = '%d'
contract.multiplier = "100"
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("127.0.0.1", port=7495)
tws_conn.connect()
tws_conn.register(error_handler, 'Error')
tws_conn.registerAll(reply_handler)
order_id = 1
goog_contract = create_contract(tic,hup.cell(2,3).value,hup.cell(2,4).value,hup.cell(2,13).value)
goog_order = create_order('MKT', 1, 'BUY')
tws_conn.placeOrder(order_id, goog_contract, goog_order)
我希望看到期权订单通过 TWS。我也很想看到一些关于 placeorder 参数应该如何具有的适当示例。