Closed tmiller198 closed 1 year ago
This looks like a Bloomberg specific question related to blpapi not the blp wrapper. I would contact Bloomberg help for this.
Only open the BLPQuery
once, and make multiple bdp
calls. The way you have it now, you are unnecessarily re-initializing it every single time.
Code Sample, a copy-pastable example if possible
Problem description
I have a python script that pulls a bond ISIN, date, and prices in order to calculate the DV01 for the bond using BBG. The script runs fine when I only pull the top 100 rows, but if I increase to the top 3,000 rows for example, I get the below error:
2023-01-18 16:25:29 OWSCNYWKS105 root[39332] INFO bond data Downloaded
18JAN2023_16:27:08.808 39332:38476 WARN apicm_apiconnector.cpp:573 ApiConnector::negotiatorCallback localhost: Session negotiation failed for 127.0.0.1:8194 result = 1
18JAN2023_16:27:08.809 39332:38476 WARN blpapi_apicmadapter.cpp:336 blpapi.session.transporttcp.apicmadapter.{476} Failed BBCOMM session negotiation localhost:8194 <127.0.0.1:8194>
18JAN2023_16:27:08.809 39332:38476 WARN blpapi_platformtransporttcp.cpp:151 blpapi.session.transporttcp.{476}. { platformId=0 } 127.0.0.1, session pool state=Failed
18JAN2023_16:27:08.810 39332:38476 WARN blpapi_platformcontroller.cpp:634 blpapi.session.platformcontroller.{476} Platform failed 1 consecutive connect attempts, stopped trying to reconnect. { PlatformId=0 }
18JAN2023_16:27:08.811 39332:6728 ERROR blpapi_sessionimpl.cpp:2445 blpapi.session.{476} Failed to start session: Failed to connect 2023-01-18 16:27:08 OWSCNYWKS105 blp.blp[39332] INFO Failed to connect to Bloomberg: SessionStartupFailure = { reason = { source = "Session" category = "IO_ERROR" errorCode = 3 description = "Failed to connect" } }
Traceback (most recent call last): File "s:\tmiller\Script\Python\test.py", line 45, in
main()
File "s:\tmiller\Script\Python\test.py", line 39, in main
df['dv01'] = df.apply(lambda row : get_dv01(row['bond_lookup'],row['midprice'], row['bbg_date']), axis = 1)
File "C:\Users\timmiller\Anaconda3\envs\singlesdash\lib\site-packages\pandas\core\frame.py", line 8740, in apply
return op.apply()
File "C:\Users\timmiller\Anaconda3\envs\singlesdash\lib\site-packages\pandas\core\apply.py", line 688, in apply
return self.apply_standard()
File "C:\Users\timmiller\Anaconda3\envs\singlesdash\lib\site-packages\pandas\core\apply.py", line 812, in apply_standard
results, res_index = self.apply_series_generator()
File "C:\Users\timmiller\Anaconda3\envs\singlesdash\lib\site-packages\pandas\core\apply.py", line 828, in apply_series_generator
results[i] = self.f(v)
File "s:\tmiller\Script\Python\test.py", line 39, in
df['dv01'] = df.apply(lambda row : get_dv01(row['bond_lookup'],row['midprice'], row['bbg_date']), axis = 1)
File "s:\tmiller\Script\Python\test.py", line 27, in get_dv01
bquery = blp.BlpQuery().start()
File "C:\Users\timmiller\Anaconda3\envs\singlesdash\lib\site-packages\blp\blp.py", line 546, in start
raise ConnectionError(f"Failed to start {self!r}")
ConnectionError: Failed to start <class 'blp.blp.BlpQuery'> with
For reference owscipy is a self developed module to pull database data via SQL into a dataframe, of which frame is the function used to pull it and context is the connection profile. To make it replicable, I attached the exports of these dataframes. I'm not worried about the SQL part, as it works when there's only 100 entries.
Expected Output
top_100_examples.xlsx top_3k_examples.xlsx