【发布时间】:2019-09-05 05:38:12
【问题描述】:
Python 和 IB API 的新手,坚持这个简单的事情。 This application 工作正常并打印 IB 服务器回复。但是,我无法弄清楚如何将这些数据放入熊猫的数据框或任何其他变量中。您如何“获取数据”?谢谢!
在论坛、文档或 youtube 上我找不到任何有用的示例。我认为答案必须是将 accountSummary 返回到 pd.Series,但不知道如何。
预期的输出将是可以在应用程序之外进行操作的数据系列或变量。
from ibapi import wrapper
from ibapi.client import EClient
from ibapi.utils import iswrapper #just for decorator
from ibapi.common import *
import pandas as pd
class TestApp(wrapper.EWrapper, EClient):
def __init__(self):
wrapper.EWrapper.__init__(self)
EClient.__init__(self, wrapper=self)
@iswrapper
def nextValidId(self, orderId:int):
print("setting nextValidOrderId: %d", orderId)
self.nextValidOrderId = orderId
# here is where you start using api
self.reqAccountSummary(9002, "All", "$LEDGER")
@iswrapper
def error(self, reqId:TickerId, errorCode:int, errorString:str):
print("Error. Id: " , reqId, " Code: " , errorCode , " Msg: " , errorString)
@iswrapper
def accountSummary(self, reqId:int, account:str, tag:str, value:str, currency:str):
print("Acct Summary. ReqId:" , reqId , "Acct:", account,
"Tag: ", tag, "Value:", value, "Currency:", currency)
#IB API data returns here, how to pass it to a variable or pd.series
@iswrapper
def accountSummaryEnd(self, reqId:int):
print("AccountSummaryEnd. Req Id: ", reqId)
# now we can disconnect
self.disconnect()
def main():
app = TestApp()
app.connect("127.0.0.1", 4001, clientId=123)
test = app.accountSummary
app.run()
if __name__ == "__main__":
main()
【问题讨论】:
标签: python-3.x pandas api interactive-brokers