How can I use a CSV file for Python pdblp instead of a ticker reference for getting API from con.ref

278 Views Asked by At

I very new to Python and I want to replace an exact ticker with a reference to a column of a Data Frame I created from a CVS file, can this be done. i'm using:

import pandas as pd 
import numpy as np 
import pdblp as pdblp
import blpapi as blp
con = pdblp.BCon(debug=False, port=8194, timeout=5000)
con.start()
con.ref("CLF0CLH0 Comdty","PX_LAST")
tickers = pd.read_csv("Tick.csv")

so "tickers" has a colum 'ticker1' which is a list of tickers, i want to replace
con.ref("CLF0CLH0 Comdty","PX_LAST") with somthing like

con.ref([tickers('ticker1')],"PX_LAST")

any ideas?

2

There are 2 best solutions below

1
On

assuming you would want to load all tickers into one df, i think it would look something like this:

df = pd.DataFrame(columns=["set your columns"])

for ticker in tickers.tickers1:
   df_tmp = pd.DataFrame()
   con.ref(ticker,"PX_LAST")
   df_tmp = con.fetch #you'll have to fetch the records into a df
   df.append(df_tmp) 
0
On

Ended up using the following .tolist() function, and worked well.

      tickers = pd.read_csv("Tick.csv")                                                                                                                  
      tickers1=tickers['ticker'].tolist()                                                                                                                     
      con.ref(tickers1,[PX_LAST])