how to use Bloomberg API?

mfran2002

Junior Member
Apr 3, 2017
7
1
6
Hello,
I have to write a program to extract data from bloomberg.
I checked out that I can use Python (no chance for me with C++ or java... :(), I'm not so skilled but I have to try with Python...

Note that I have installed, on my PC, only the Python environment, nothing else (it isn't the PC with bloomberg): do I need something else?

Someone can give me some help to get started?
Someone already did something like this?

thanks a lot
michele
 
Last edited:

KB

Diamond Member
Nov 8, 1999
5,406
389
126
You can start by going to https://www.bloomberglabs.com/api/libraries/
and downloading the python SDK. They should have examples in there.

It looks to me like you need to be a "paying" customer so I hope you have some inside connection because I am sure its no cheap.
 

mfran2002

Junior Member
Apr 3, 2017
7
1
6
Thank you KB.
We have some blp clients, if you mean that...o_O...but not me, I simply manage the IT, they asked me to develop a program to extract data from there..
I checked out the Python SDK, but the README file says that the SDK requires the following products:

- CPython version 2.6 or 2.7
- Bloomberg C++ SDK version 3.5 or later
- Visual C++ 2008 or 2010 (Windows) or GCC 4.1+ (Linux)

and the installation requires a working C compiler and the C headers distributed as part of the Bloomberg C++ SDK.

ARGH! :eek:

I would like to proceed with Python just to AVOID C++...

Are the above requirements ALL MANDATORY? :(
 
Last edited:

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
It only means you need to install those stuff since they includes the library files you can (need) use/call.

You can write program in Python. CPython = original Python which is written in C. Since there is python that's implemented in Java and other languages.

Just download Python v2.6/2.7 from python.org

Pyhon examples are included in the Bloomberg Python SDK you downloaded.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
1st, I'm not programmer. I did program before, but I haven't programmed for a long time.

I can only help to some degree. Forgive me if I'm wrong. Other members are welcomed to correct me.

the sequence is kind of important

1st: Install VC++ 2010 Express : http://filehippo.com/download_visualc_2010_express_edition

2nd: download Bloomberg C++ SDK https://bloomberg.bintray.com/BLPAPI-Stable-Generic/blpapi_cpp_3.8.18.1-windows.zip and unzip it to somewhere like C:\BLPAPI\CPP

3rd: Set the `BLPAPI_ROOT` system environment variable to C:\BLPAPI\CPP (This PC, Properties, Advanced System Settings, Advanced, Environment Variables, System Variables, New)

4th: install CPython : https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi, make sure search path option is selected.

5th: download Bloomberg Python SDK and unzip to folder like C:\blpapi\python, open command prompt in that folder and run "python setup.py install", Bloomberg Python examples should be in C:\blpapi\python\examples

I get some warnings in last step, but don't know if it's severe.

That's probably it.

Developer's Guide
https://data.bloomberglp.com/labs/sites/2/2014/07/blpapi-developers-guide-2.54.pdf

P:\blpapi-3.5.5>python setup.py install
running install
running build
running build_py
running build_ext
building 'blpapi._internals' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
creating build\temp.win32-2.7\Release\blpapi
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IP:\blpapi_cpp_3.8.18.1\include -IC:\Python27\include -IC:\Python27\PC /Tpblpapi/internals_wrap.cxx /Fobuild\temp.win32-2.7\Release\blpapi/internals_wrap.obj
internals_wrap.cxx
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
blpapi/internals_wrap.cxx(3907) : warning C4244: 'argument' : conversion from 'blpapi_Float64_t' to 'blpapi_Float32_t', possible loss of data
blpapi/internals_wrap.cxx(3921) : warning C4244: 'argument' : conversion from 'blpapi_Float64_t' to 'blpapi_Float32_t', possible loss of data
blpapi/internals_wrap.cxx(3940) : warning C4244: 'argument' : conversion from 'blpapi_Float64_t' to 'blpapi_Float32_t', possible loss of data
blpapi/internals_wrap.cxx(3994) : warning C4244: 'argument' : conversion from 'blpapi_Float64_t' to 'blpapi_Float32_t', possible loss of data
blpapi/internals_wrap.cxx(4011) : warning C4244: 'argument' : conversion from 'blpapi_Float64_t' to 'blpapi_Float32_t', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:p:\blpapi_cpp_3.8.18.1\lib /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild /LIBPATH:C:\Python27\PC\VS9.0 blpapi3_32.lib /EXPORT:init_internals build\temp.win32-2.7\Release\blpapi/internals_wrap.obj /OUT:build\lib.win32-2.7\blpapi\_internals.pyd /IMPLIB:build\temp.win32-2.7\Release\blpapi\_internals.lib /MANIFESTFILE:build\temp.win32-2.7\Release\blpapi\_internals.pyd.manifest /MANIFEST
Creating library build\temp.win32-2.7\Release\blpapi\_internals.lib and object build\temp.win32-2.7\Release\blpapi\_internals.exp
running install_lib
creating C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\abstractsession.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\constant.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\datatype.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\datetime.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\element.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\event.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\eventdispatcher.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\eventformatter.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\exception.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\identity.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\internals.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\message.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\name.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\providersession.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\request.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\resolutionlist.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\schema.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\service.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\session.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\sessionoptions.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\subscriptionlist.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\topic.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\topiclist.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\utils.py -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\_internals.pyd -> C:\Python27\Lib\site-packages\blpapi
copying build\lib.win32-2.7\blpapi\__init__.py -> C:\Python27\Lib\site-packages\blpapi
byte-compiling C:\Python27\Lib\site-packages\blpapi\abstractsession.py to abstractsession.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\constant.py to constant.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\datatype.py to datatype.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\datetime.py to datetime.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\element.py to element.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\event.py to event.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\eventdispatcher.py to eventdispatcher.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\eventformatter.py to eventformatter.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\exception.py to exception.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\identity.py to identity.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\internals.py to internals.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\message.py to message.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\name.py to name.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\providersession.py to providersession.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\request.py to request.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\resolutionlist.py to resolutionlist.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\schema.py to schema.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\service.py to service.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\session.py to session.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\sessionoptions.py to sessionoptions.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\subscriptionlist.py to subscriptionlist.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\topic.py to topic.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\topiclist.py to topiclist.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\utils.py to utils.pyc
byte-compiling C:\Python27\Lib\site-packages\blpapi\__init__.py to __init__.pyc
running install_egg_info
Writing C:\Python27\Lib\site-packages\blpapi-3.5.5-py2.7.egg-info
 
Last edited:

mfran2002

Junior Member
Apr 3, 2017
7
1
6
GREAT mxnerd THANK YOU VERY MUCH!!!

I will be your friend forever! :p

just to consider also another way, may you please tell me the steps in case I use C++ instead of Python?

Then I will go and process each step of your helpful guide!
 
Last edited:

mfran2002

Junior Member
Apr 3, 2017
7
1
6
Hi,
I followed the steps and it seems all right about the installation.

But when I try to run an example .py file (i.e. SimpleHistoryExample.py) I get this error:


Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:\BLPAPI\python\examples\SimpleHistoryExample.py =========

Traceback (most recent call last):
File "C:\BLPAPI\python\examples\SimpleHistoryExample.py", line 3, in <module>
import blpapi
File "C:\Python27\lib\site-packages\blpapi\__init__.py", line 5, in <module>
from .internals import CorrelationId
File "C:\Python27\lib\site-packages\blpapi\internals.py", line 50, in <module>
_internals = swig_import_helper()
File "C:\Python27\lib\site-packages\blpapi\internals.py", line 46, in swig_import_helper
_mod = imp.load_module('_internals', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found
>>>

The error was solved including the Bloomberg C++ SDK (C:\BLPAPI\CPP\BIN) into the PATH environment variable.

Once included this location I run again but I get this error:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:\BLPAPI\python\examples\SimpleHistoryExample.py =========
SimpleHistoryExample
Connecting to localhost:8194
Failed to start session.
>>>

Is it maybe due to the fact that I have not bloomberg client installed on my PC? or what else?
if so, how can I solve this?
 
Last edited:

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
They are super expensive.

https://www.google.com/search?q=bloomberg+monthly+cost

Most Bloomberg setups have between two and six displays. It is available for an annual fee of $20,000 per user ($25,080 per year for the small number of firms that use only one terminal). As of October 2016, there were 325,000 Bloomberg Terminal subscribers worldwide.

===

No trading company will provide free realtime data. Bloomberg probably is the most expensive one. And each data provider / trading company has its own API.

You can extract free delayed data from Yahoo/Google or somewhere else.
 
Last edited:

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
GREAT mxnerd THANK YOU VERY MUCH!!!

I will be your friend forever! :p

just to consider also another way, may you please tell me the steps in case I use C++ instead of Python?

Then I will go and process each step of your helpful guide!

Sorry, I only leaned C long time ago. I have no idea about C++. I think you have to look into Developer's guide for help.

If you need to learn any computer languages, youtube also has tons of resources.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
Ahh, notice that Python SDK README said
Windows users may need to set the `PATH` variable to the
directory containing `blpapi3_32.dll` or `blpapi3_64.dll`

I search the net and managed to obtain a copy of Bloomberg Pro here https://www.blpprofessional.com/ and install it in C:\blp folder
And I can add C:\blp\DAPI into PATH system variables for Environment Variables

C:\blp\DAPI is exactly where those 2 dll files located.

You set the PATH to C:\BLPAPI\CPP\BIN also works.

Then I can run the Python program SimpleHistoryExample.py as you and get a Python console :

SimpleHistoryExample
Connecting to localhost:8194
and stuck

Apparently 8194 is the data streaming port provided by Bloomberg Professional software.

Don't have any Bloomberg account. Can't go any further.

This is as far as I can get, just like you.
 
Last edited:

mfran2002

Junior Member
Apr 3, 2017
7
1
6
thanks again mxnerd, very helpful your suggestions! ;)

I checked out the net and found a blp api emulator, but it runs only with c++, c#, .net (no chance for python)

so now:

1. I can ask a blp user to my collegues, but if I access the client I disconnect one of them (so, very difficult they accept..)
:D

2. I can try to find a "blp api emulator" for python (mmmm....very difficult, maybe mission impossible...)

3. write my program in C++ (I know C, but never developed in visual c++, and not so skilled in object oriented...)

Ehm...mxnerd...what can you tell me about your skilling in visual studio for c++?

:D:D:D:D:D:D:D:D

please help me!
 
Last edited:

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
I'm mostly a networking & software installation guy, not a programmer. I learned C programming while I was a student. After I work, the languages I touched were dBase/Clipper/Foxpro, VB6/Access, but that's also long, long time ago. Never, ever learned C++, just like you. It's hard for me to comprehend the object oriented languages like C++, Java or C#.

I'm still interested in the progress of programming languages of recent years . So I installed free Visual Studio Express several times along the years, but that's about it. Tried to learned VB.NET and C#, but gave up immediately. C++ is completely out of my realm.

I looked at the emulator, bu I have no idea what it really does. How it emulates the function of Bloomberg's data service and how it can provide data to external program request.

You have to tell your boss to let you access your working colleagues' Bloomberg account during their lunch time or off working hours.

If you already tried to avoid C++, then avoid it. I know it's complex to me, probably is also complex to you.

Just stick with Python and you will be a lot happier.
 
Last edited:

mfran2002

Junior Member
Apr 3, 2017
7
1
6
ahahahaha great mxnerd!

you are really right!

I'm now a bit over 40s (argh, closer to 50s), I started with basic and assembler :eek:, and I also tried lot of time to start with object oriented languages...abandoned soon...each and every time!

Maybe also for me they are too much, out of range

thanks anyway for your help, patient and courtesy

I will let you know my choice :(
michele
 
  • Like
Reactions: mxnerd