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 库但如果我错了请纠正我:)....有什么建议吗?:
File "C:\Users\Heraaizon\Desktop\IBPy_Test.py", line 1, in <module>
from ib.ext.Contract import Contract
File "C:\Users\Heraaizon\AppData\Local\Programs\Python\Python37-32\lib\ib\ext\Contract.py", line 9, in <module>
from ib.lib.overloading import overloaded
File "C:\Users\Heraaizon\AppData\Local\Programs\Python\Python37-32\lib\ib\lib\__init__.py", line 239
except (socket.error, ), ex:
^
SyntaxError: invalid syntax