Public API Reference

Standard API Requests

BLPData.bdhFunction
bdh(session::Session, security::AbstractString, fields, date_start::Date, date_end::Date;
        periodicity=nothing, # periodicitySelection option
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0),
        error_handling::ErrorHandling=Unwrap()

Runs a query for historical data. Returns a Vector of named tuples.

Internally, it issues a HistoricalDataRequest in //blp/refdata service.

See also bds.

Arguments

  • fields argument is either a single string or an array of string values.

  • options argument expects a key->value pairs or a Dict.

  • periodicity expects the string value for the periodicitySelection option.

Simple query example

using BLPData, DataFrames, Dates

# opens a session
session = BLPData.Session()

# query historical data
result = BLPData.bdh(session, "IBM US Equity", ["PX_LAST", "VWAP_VOLUME"], Date(2020, 1, 2), Date(2020, 1, 30))

# format result as a `DataFrame`
df = DataFrame(result)

Query with optional parameters

ticker = "PETR4 BS Equity"
field = "PX_LAST"
options = Dict(
    "periodicityAdjustment" => "CALENDAR",
    "periodicitySelection" => "DAILY",
    "currency" => "BRL",
    "pricingOption" => "PRICING_OPTION_PRICE",
    "nonTradingDayFillOption" => "ACTIVE_DAYS_ONLY",
    "nonTradingDayFillMethod" => "NIL_VALUE",
    "adjustmentFollowDPDF" => false,
    "adjustmentNormal" => true,
    "adjustmentAbnormal" => true,
    "adjustmentSplit" => true
)

# query for adjusted stock price
df = DataFrame(BLPData.bdh(session, ticker, field, Date(2019, 1, 1), Date(2019, 2, 10), options=options))
bdh(session::Session, securities::Vector{T1}, fields::Vector{T2}, date_start::Date, date_end::Date;
        periodicity=nothing, # periodicitySelection option
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0),
        error_handling::ErrorHandling=Unwrap()
    ) where {T1<:AbstractString, T2<:AbstractString}

Runs a query for historical data. Returns a Dict where the key is the security name and value is a Vector of named tuples.

Internally, BLPData will process a ReferenceDataRequest request for each security in parallel.

BLPData.bdh_intraday_ticksFunction
bdh_intraday_ticks(session, security, event_types, date_start, date_end;
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0)
    )

Runs a IntradayTickRequest request.

Example

# use a recent date
d0 = DateTime(2022, 3, 22, 13)
d1 = DateTime(2022, 3, 22, 13, 5)
res = BLPData.bdh_intraday_ticks(session, "PETR4 BS Equity", ["TRADE", "BID", "ASK"], d0, d1)
df = DataFrame(res)
show(df)
BLPData.bdsFunction
bds(session::Session, security::AbstractString, field::AbstractString;
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0)

Runs a query for reference data of a security. Returns a Vector of named tuples.

Internally, it issues a ReferenceDataRequest in //blp/refdata service.

See also bdh.

Example

using BLPData, DataFrames
session = BLPData.Session()
result = BLPData.bds(session, "PETR4 BS Equity", "COMPANY_ADDRESS")
df = DataFrame(result)
bds(session::Session, securities::Vector{T}, field::AbstractString;
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0)
    ) where {T<:AbstractString}

Runs a query for reference data of a security. Returns a Dict where the key is the security name and value is a Vector of named tuples.

Internally, BLPData will process a ReferenceDataRequest request for each security in parallel.

BLPData.bdpFunction
bdp(session::Session, security::AbstractString, fields;
        options=nothing, # expects key->value pairs or Dict
        verbose::Bool=false,
        timeout_milliseconds::Integer=UInt32(0),
        error_handling::ErrorHandling=Unwrap()
    )

Given a single field name or vector of field names at the fields argument, return a single named tuple with the result of a ReferenceDataRequest request.

See ErrorHandling for error_handling argument behavior.

For bulk data, bds method should be used instead.

Example

julia> BLPData.bdp(session, "PETR4 BS Equity", "PX_LAST")
(PX_LAST = 15.95,)

julia> BLPData.bdp(session, "PETR4 BS Equity", ["PX_LAST", "VOLUME"])
(PX_LAST = 15.95, VOLUME = 1.601771e8)

Error Handling

BLPData.ErrorHandlingType

Unwrap

If BLPResult holds an Err, panics. If BLPResult holds Ok result, returns underlying result.

NoUnwrap

Always returns the BLPResult itself.

Session, Services and Events

BLPData.SessionType
Session(services;
        host=nothing,
        port=nothing,
        client_mode=nothing,
        service_check_timeout_msecs=nothing
        service_download_timeout_msecs=nothing,
        session_start_timeout_msecs=DEFAULT_SESSION_START_TIMEOUT_MSECS,
        verbose::Bool=false
    )

Creates a new session for Bloomberg API and opens the services listed in the services argument.

See also stop, ClientMode, DEFAULT_SERVICE_NAMES, ALL_SERVICE_NAMES.

Example

# starts a session with default parameters:
# * host=127.0.0.1, port=8194
# * client_mode = BLPAPI_CLIENTMODE_AUTO.
# * services = BLPData.DEFAULT_SERVICE_NAMES
session = Blpapi.Session()

# session with customized parameters
customized_session = Blpapi.Session("//blp/refdata",
    host="my_host",
    port=4444,
    client_mode=Blpapi.BLPAPI_CLIENTMODE_DAPI)
BLPData.DEFAULT_SERVICE_NAMESConstant

List of service names that the default Session constructor uses. See also Session.

julia> BLPData.Session()
Session services available: Set(["//blp/refdata", "//blp/mktdata"])

julia> BLPData.DEFAULT_SERVICE_NAMES
Set{String} with 2 elements:
  "//blp/refdata"
  "//blp/mktdata"
BLPData.ALL_SERVICE_NAMESConstant

List of all serice names based on the BLPAPI documentation. See also Session.

julia> session = BLPData.Session(BLPData.ALL_SERVICE_NAMES)
Session services available: Set(["//blp/mktlist", "//blp/mktdata", "//blp/mktdepthdata", "//blp/instruments", "//blp/pagedata", "//blp/mktvwap", "//blp/mktbar", "//blp/refdata", "//blp/irdctk3", "//blp/tasvc", "//blp/srcref", "//blp/apiflds"])
BLPData.get_opened_services_namesFunction
get_opened_services_names(session::Session) :: Set{String}

Returns the set of names for opened services for this session.

BLPData.is_service_openFunction
is_service_open(session::Session, service_name::AbstractString) :: Bool

Returns true if service_name is opened in the session.

BLPData.stopFunction
stop(session::Session)

Stops a session.

Once a Session has been stopped it can only be destroyed.

BLPData.ClientModeType

Sets how to connect to the Bloomberg API.

  • BLPAPI_CLIENTMODE_AUTO tries to

connect to Desktop API, and falls back to Server API.

  • BLPAPI_CLIENTMODE_DAPI connects to Desktop API.

  • BLPAPI_CLIENTMODE_SAPI connects to Server API.

The default when creating SessionOptions is BLPAPI_CLIENTMODE_AUTO.

See also Session.

BLPData.ServiceType

A Service provides access to API data. A service is obtained from a Session and gives access to operations.

session = BLPData.Session()
service = session["//blp/refdata"]
println(BLPData.list_operation_names(service))
operation = service["HistoricalDataRequest"]
println(operation)
BLPData.list_operation_namesFunction
list_operation_names(service::Service) :: Vector{String}

List operation names available for service.

BLPData.get_version_infoFunction
get_version_info() :: VersionInfo

Returns the version of the shared library for Bloomberg API.

BLPData.next_eventFunction
next_event(event_source; timeout_milliseconds::Integer=UInt32(0)) :: Event

Reads the next event in the stream events of the event_source. This method blocks until an event is available.

See also try_next_event.

Event Sources

The event_source can be either a Session or an EventQueue.

next_event(queue::EventQueue; timeout_milliseconds::Integer=Cint(0)) :: Event

Returns the next event available in the queue. If timeout_milliseconds is zero, waits forever until an event is available.

BLPData.try_next_eventFunction
try_next_event(event_source) :: Union{Nothing, Event}

Reads the next event in the stream events of the event_source. If no event is available, returns nothing. This method never blocks.

See also next_event.

Event Sources

The event_source can be either a Session or an EventQueue.

Subscription

BLPData.subscribeFunction
subscribe(session::Session, topics) :: SubscriptionList

Subscribes to real-time events on a single topic or a list of topics. The topics argument should be an AbstractString or a Vector{AbstractString}.

See also unsubscribe, SubscriptionList.

Example

topic = "//blp/mktdata/ticker/PETR4 BS Equity?fields=BID,ASK"
subscription_list = BLPData.subscribe(session, topic)

i = 1 # event counter
evn = BLPData.try_next_event(session)
while evn != nothing
    println("event $i")
    println(evn)
    i += 1
    sleep(2) # let's wait for events
    evn = BLPData.try_next_event(session)
end

BLPData.unsubscribe(session, subscription_list)
BLPData.SubscriptionListType

A list of SubscriptionTopics. This struct supports the basic vector API.

Examples

list = BLPData.SubscriptionList() # creates an empty list
append!(list, ["//blp/mktdata/ticker/PETR4 BS Equity?fields=BID,ASK", "//blp/mktdata/ticker/VALE3 BS Equity?fields=BID,ASK"])

for topic in list
    println(topic)
end

See also SubscriptionTopic.

BLPData.SubscriptionTopicType

Represents a Topic related to the subscription API.

Fields

  • correlation_id: unique identifier for tracking events in the event stream related to this subscription.

  • topic: a valid subscription string for the BLPAPI.

See also subscribe.