根据盈透证券文档,我尝试使用以下代码获取合同详细信息:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
class MyWrapper(EWrapper):
def contractDetails(self, reqId, contractDetails):
super().contractDetails(reqId, contractDetails)
print("ContractDetails. ReqId:", reqId,
contractDetails.summary.symbol,
contractDetails.summary.secType,
"ConId:", contractDetails.summary.conId,
"@", contractDetails.summary.exchange)
def contractDetailsEnd(self, reqId):
super().contractDetailsEnd(reqId)
print("ContractDetailsEnd. ", reqId, "\n")
wrapper = MyWrapper()
app = EClient(wrapper)
app.connect("127.0.0.1", 7497, clientId=0)
print("serverVersion:%s connectionTime:%s" % (app.serverVersion(), app.twsConnectionTime()))
from ibapi.contract import Contract
contract = Contract()
contract.symbol = "XAUUSD"
contract.secType = "CMDTY"
contract.exchange = "SMART"
contract.currency = "USD"
app.reqContractDetails(4444, contract)
app.run()
返回的输出是:
serverVersion:148 connectionTime:b'20190117 17:11:38 AEST'
An exception has occurred, use %tb to see the full traceback.
SystemExit
C:\Users\Greg\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2969: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
如何从盈透证券 API 获取合约详情?我尝试使用%tb
但不认为我把它放在正确的线上。