from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
#from ib.lib.overloading import overloaded
def make_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 make_order (action, quantity, price = None):
if price is not None:
order = Order()
order.m_orderType = 'LMT'
order.m_totalQuantity = qiantity
order.m_action = action
order.m_lmtPrice = price
else:
order = Order()
order.m_orderType = 'MKT'
order.m_totalQuantity = qiantity
order.m_action = action
return order
#def error_handler(msg):
#print'Server Error: ',msg
#def server_handler(msg):
#print'Server Msg: ',msg.typeName,'-',msg
def main():
conn = Connection.create(port=7496, clientId=100) #clientID's given are 100 or 999
conn.connect()
oid = 1
cont = make_contract('TSLA', 'STK', 'SMART', 'SMART', 'USD')
offer = make_order('BUY', 1) #or('BUY', 1, 200)
conn.placeOrder(oid, cont, offer)
conn.disconnect()
遇到此错误,不知道为什么我确定我正确安装了ibpy lib,但是如果我错了,请纠正我:).........
File "C:UsersHeraaizonDesktopIBPy_Test.py", line 1, in <module>
from ib.ext.Contract import Contract
File "C:UsersHeraaizonAppDataLocalProgramsPythonPython37-32libibextContract.py", line 9, in <module>
from ib.lib.overloading import overloaded
File "C:UsersHeraaizonAppDataLocalProgramsPythonPython37-32libiblib__init__.py", line 239
except (socket.error, ), ex:
^
SyntaxError: invalid syntax
except
子句的语法在Python 2和Python 3之间发生了变化。
python 2:
except (socket.error, ), ex:
将在Python 3:
中except (socket.error, ) as ex:
看来您的代码是为Python 2编写的。要么使用Python 2运行它,要么找到代码的更新版本。