我正在尝试使用 IbPY 来拉动股票价格及其财务报表。我是 python 新手,并不完全理解在 IbPy 中调用一些不同方法的复杂性。
我编写了一些代码来遍历 SP 500 并为每只股票拉出出价/要价。我希望有人能帮我弄清楚下一步如何提取财务报表。
想到最好的方法来做到这一点?
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from ib.ext.EWrapper import EWrapper
from time import sleep
import csv
with open(r'C:\Users\User\folder\sp500-symbol-list.txt') as f:
reader = csv.reader(f)
lst = list(reader)
bid_lst=[]
ask_lst = []
start = -1
for x in range(len(lst)):
start = start +1
def my_callback_handler(msg):
#print(start)
inside_mkt_bid = ''
inside_mkt_ask = ''
if msg.field == 1:
inside_mkt_bid = msg.price
z = ('bid', inside_mkt_bid)
print(z)
bid_lst.append(z[1])
elif msg.field == 2:
inside_mkt_ask = msg.price
k=['ask', inside_mkt_ask]
print(k)
ask_lst.append(k[1])
tws = ibConnection(port=1111, clientId=000)
tws.register(my_callback_handler, message.tickSize, message.tickPrice)
tws.connect()
c = Contract()
c.m_symbol = lst[start][0]
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
print(c.m_symbol)
tws.reqMktData(1,c,"",False)
tws.reqFundamentalData(1,c,'ReportsFinStatements')
sleep(1)
tws.disconnect()