Python 试图从TWS API请求基本数据
一般来说,我对这个api和python非常陌生,我正试图通过交互式代理从TWSAPI导入基础数据Python 试图从TWS API请求基本数据,python,api,import,python-requests,Python,Api,Import,Python Requests,一般来说,我对这个api和python非常陌生,我正试图通过交互式代理从TWSAPI导入基础数据 from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.contract import Contract wrapper = EWrapper() app = EClient(wrapper) app.connect('127.0.0.1', 7497, clientId=123) print(
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
wrapper = EWrapper()
app = EClient(wrapper)
app.connect('127.0.0.1', 7497, clientId=123)
print("serverVersion:%s connectionTime:%s" % (app.serverVersion(), app.twsConnectionTime()))
contract = Contract()
contract.symbol = 'SQ'
contract.secType = 'STK'
contract.currency = 'USD'
app.reqFundamentalData(8001, contract, 'RESC', [])
以下是文档:
我无法找到此请求的数据是否已导入以及导入到何处
非常感谢任何能提供帮助的人。请尝试以下“ReportsInstances”代码:
交互式代理API中有两个主要类处理客户端和服务器之间的消息,它们是: 1。EClient:负责向IB服务器发送请求强> 2。EWrapper:负责接收IB服务器返回的消息。 reqFundamentalData()函数位于EClient类中,它负责向IB的服务器发送基本数据请求 IB服务器收到请求后,会将文本数据发送回EWrapper类,供其处理。调用EWrapper类中的另一个函数fundamentalData(),以处理返回的数据 在向IB的服务器发送任何请求之前,必须初始化EWrapper和EClient类,并覆盖相关的接收函数以实现其他个性化功能。例如打印接收到的数据,或将返回的数据保存到任何数据库等
# Import EWrapper and EClient
from ibapi.Contract import Contract
from ibapi.wrapper import EWrapper
from ibapi.client import EClient
# Initilizing
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
# Error handling function
def error(self, reqId, errorCode, errorString):
print("error: ", reqId, " ", errorCode, " ", errorString)
# Inherite and overwrite fundamentalData() function in EWrapper
def fundamentalData(self, reqId: int, data: str):
super().fundamentalData(reqId, data)
print("FundamentalData Returned. ReqId: {}, Symbol: {}, XML Data: {}".format(
reqId, contr.symbol, data))
# Implement other personalized functions here
tws = IBapi()
tws.connect("127.0.0.1",port=7496, clientId=997)
time.sleep(2)
c = Contract()
c.m_symbol = 'MMM'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
tws.reqFundamentalData(1, c, 'RESC', [])
time.sleep(4)
# Implement other requests
tws.disconnect()
希望能有帮助
# Import EWrapper and EClient
from ibapi.Contract import Contract
from ibapi.wrapper import EWrapper
from ibapi.client import EClient
# Initilizing
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
# Error handling function
def error(self, reqId, errorCode, errorString):
print("error: ", reqId, " ", errorCode, " ", errorString)
# Inherite and overwrite fundamentalData() function in EWrapper
def fundamentalData(self, reqId: int, data: str):
super().fundamentalData(reqId, data)
print("FundamentalData Returned. ReqId: {}, Symbol: {}, XML Data: {}".format(
reqId, contr.symbol, data))
# Implement other personalized functions here
tws = IBapi()
tws.connect("127.0.0.1",port=7496, clientId=997)
time.sleep(2)
c = Contract()
c.m_symbol = 'MMM'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
tws.reqFundamentalData(1, c, 'RESC', [])
time.sleep(4)
# Implement other requests
tws.disconnect()