6

GitHub - bloomberg/blpapi-hs: Haskell interface to BLPAPI

 2 years ago
source link: https://github.com/bloomberg/blpapi-hs
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

blpapi-hs

Bloomberg Open API binding for Haskell.

Find source code in the Github repository.

Dependencies

This module requires:

  • Linux, Microsoft Windows, or Apple Mac OS X (32 or 64-bit)
  • Haskell (ghc >= 7.4)
  • BLPAPI C++ SDK (>= v3.6)

Installation on Linux

First, you will need to install the BLPAPI C++ SDK. Download the appropriate package for your system, and unpack the downloaded file into a suitable directory. These instructions assume you have unpacked the SDK into /opt/blpapi, but if you have chosen another directory, substitute its path in the instructions below.

After unpacking the C++ SDK, you will need to build this project on your system. The cabal tool provided with the Haskell installatin can be used to do that. The tool will need to be told where the C++ SDK header files and libraries are located on your system.

$ cabal install --extra-include-dirs=/opt/blpapi/include --extra-lib-dirs=/opt/blpapi/Linux

Installation on Microsoft Windows

First, you will need to install the BLPAPI C++ SDK. Download the appropriate package for your system, and unpack the downloaded file into a suitable directory. These instructions assume you have unpacked the SDK into C:\blpapi, but if you have chosen another directory, substitute its path in the instructions below.

After unpacking the C++ SDK, you will need to build this project on your system. The cabal tool provided with the Haskell installatin can be used to do that. The tool will need to be told where the C++ SDK header files and libraries are located on your system.

$ cabal install --extra-include-dirs=C:\blpapi\include --extra-lib-dirs=C:\blpapi\lib

Installation on Apple Mac OS X

First, you will need to install the BLPAPI C++ SDK. Download the appropriate package for your system, and unpack the downloaded file into a suitable directory. These instructions assume you have unpacked the SDK into /opt/blpapi, but if you have chosen another directory, substitute its path in the instructions below.

After unpacking the C++ SDK, you will need to build this project on your system. The cabal tool provided with the Haskell installatin can be used to do that. The tool will need to be told where the C++ SDK header files and libraries are located on your system.

$ cabal install --extra-include-dirs=/opt/blpapi/include --extra-lib-dirs=/opt/blpapi/Darwin

Building the examples

This project contains a few example programs in addition to the API wrapper library; they can be built by adding the -fbuildExamples argument to the cabal command when building the project.

Usage

The module design closely follows the BLPAPI SDK design with very slight modifications to make it more 'Haskell-like'. The SDK developer guide should serve as the main guide to understand the API.

Full examples contained in the examples directory demonstrate how to use most SDK functionality. Full descriptions of all availabe requests, responses, and options are contained within the BLPAPI API Developer Guide.

Setting up a Session

setupBlpapi :: Blpapi ()
setupBlpapi c = do
  createSession
    (defaultSessionOptions {serverAddresses = [ServerAddress "127.0.0.1" 8194]})
    (defaultHandler m)

Create a Ref Data Request

createRefDataRequest :: Blpapi ()
createRefDataRequest = do
    ser <- openService "//blp/refdata"
    req <- createRequest ser "ReferenceDataRequest"
    formatRequest req $! do
        formatSubElement "fields" $ do
            appendValue (BT.BlpString "ASK")
            appendValue (BT.BlpString "BID")
        formatSubElement "securities" $ do
            appendValue (BT.BlpString "IBM US Equity")
            appendValue (BT.BlpString "GOOG US Equity")
    e <- getElementFromRequest req
    liftIO $ prettyPrint e
    sendRequest req Nothing

Set up a Subscription

getSubscriptionList :: [Subscription]
getSubscriptionList =
  [Subscription (TopicString "IBM US Equity" ["BID", "ASK"]) Nothing Nothing]

setupSubscription :: Identity -> Blpapi ()
setupSubscription iden = do
  openService "//blp/mktdata"
  subscribeWithIdentity getSubscriptionList iden

Process a Response

defaultHandler :: Event -> Blpapi ()
defaultHandler m e = do
  liftIO $ printEvent e
  parseRefData e

License

MIT-style license. See license text in LICENSE.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK