当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Fundamental Data Using IbPy

问题描述:

I am trying to use IbPY to pull the price of a stock along with its financial statements. I'm new to python and don't entirely understand the complexities of calling some of the different methods within IbPy.

I wrote some code to loop through the SP 500 and pull the bid/ask for each stock. I was hoping someone might be able to help me figure out the next step to pull the financial statements.

Thoughts on the best way to do that?

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()

分享给朋友:
您可能感兴趣的文章:
随机阅读: