Introduction
The Per Security WSDL allows to send a request for a financial information to Bloomberg. The request can be shaped in many ways. This example shows how to query closing quotes, volume, and high52weeks for multiple securities in a single call.
Background
Each call needs to have a header, instruments, and fields. It also needs to have an access information - path to the security certificate file on your local machine, and the password (the file and the password are provided by Bloomberg once you sign the service contract).
Using the Code
Login information is placed in PerSecurity.vb file:
Imports System
Imports System.IO
Imports System.Net
Imports System.Configuration
Imports System.Xml
Imports System.Security.Cryptography.X509Certificates
Imports BloomVB
Imports BloomVB.PerSecurityWSDL
Module PerSecurity
Public Const DATA_NOT_AVAILABLE As Integer = 100
Public Const SUCCESS As Integer = 0
Public Const REQUEST_ERROR As Integer = 200
Public Const POLL_INTERVAL As Integer = 5000
Sub Main()
Try
Dim clientCert As New X509Certificate2("c:\Cert\DLWSCert.p12", "PASSWORD")
Dim ps As BloomVB.PerSecurityWSDL.PerSecurityWSClient = _
New PerSecurityWSClient("PerSecurityWSPort")
ps.ClientCredentials.ClientCertificate.Certificate = clientCert
Dim eodReq As New EOD()
eodReq.run(ps)
Catch ex As Exception
WriteToFile(LogFile.ToString, ex.Message & ex.StackTrace)
End Try
End Sub
End Module
The API call is placed in EOD.vb file:
Imports System
Imports System.IO
Imports System.Net
Imports System.Configuration
Imports System.Xml
Imports System.Security.Cryptography.X509Certificates
Imports BloomVB
Imports BloomVB.PerSecurityWSDL
Public Class EOD
Public Sub run(ByVal ps As PerSecurityWSClient, ByVal logfilename As String)
Try
Dim tickerslist As String = "MYO.AU,1530.HK,JPOST.RC,DTEA,VSI,GNC"
Dim tickersymbols As String() = tickerslist.Split(",")
Dim uBound As Integer = tickersymbols.Count
Dim ticker As New Instrument()
Dim tickers As Instrument()
tickers = New Instrument() {ticker}
Dim u As Integer
For u = 0 To uBound - 1
ticker = New Instrument()
ticker.id = tickersymbols(u)
ticker.yellowkey = MarketSector.Equity
ticker.yellowkeySpecified = True
Array.Resize(tickers, tickers.Length + 1)
tickers(u) = ticker
Next
Dim instr As Instrument() = tickers.ToArray()
Dim instrs As New Instruments()
instrs.instrument = instr
Dim getDataHeaders As New GetDataHeaders()
getDataHeaders.secmaster = True
getDataHeaders.secmasterSpecified = True
getDataHeaders.closingvalues = True
getDataHeaders.closingvaluesSpecified = True
getDataHeaders.derived = True
getDataHeaders.derivedSpecified = True
Dim sbmtGtDtReq As New SubmitGetDataRequest()
sbmtGtDtReq.headers = getDataHeaders
sbmtGtDtReq.fields = New String() {"LAST_UPDATE_DATE_EOD", _
"PX_LAST_EOD", "PX_VOLUME_EOD", "HIGH_52WEEK_EOD"}
sbmtGtDtReq.instruments = instrs
Dim sbmtGtDtResp As SubmitGetDataResponse = ps.submitGetDataRequest(sbmtGtDtReq)
Dim rtrvGtDrReq As New RetrieveGetDataRequest()
rtrvGtDrReq.responseId = sbmtGtDtResp.responseId
Dim rtrvGtDrResp As RetrieveGetDataResponse
Do
System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL)
rtrvGtDrResp = ps.retrieveGetDataResponse(rtrvGtDrReq)
Loop While rtrvGtDrResp.statusCode.code = PerSecurity.DATA_NOT_AVAILABLE
If rtrvGtDrResp.statusCode.code = PerSecurity.SUCCESS Then
WriteToFile(LogFile.ToString, "Response ID: " & rtrvGtDrResp.responseId)
For i As Integer = 0 To rtrvGtDrResp.instrumentDatas.Length - 1
WriteToFile(LogFile.ToString, _
rtrvGtDrResp.instrumentDatas(i).instrument.id.ToString)
For j As Integer = 0 To rtrvGtDrResp.instrumentDatas(i).data.Length - 1
If rtrvGtDrResp.instrumentDatas(i).data(j).isArray = True Then
For k As Integer = 0 _
To rtrvGtDrResp.instrumentDatas(i).data(j).bulkarray.Length - 1
WriteToFile(LogFile.ToString, _
"-------------------------")
For l As Integer = 0 _
To rtrvGtDrResp.instrumentDatas(i).data(j).bulkarray(k).data.Length - 1
WriteToFile(LogFile.ToString, _
rtrvGtDrResp.instrumentDatas(i).data(j).bulkarray(k).data(l).value)
Next
Next
Else
WriteToFile(LogFile.ToString, vbTab + rtrvGtDrResp.fields(j) + _
": " + rtrvGtDrResp.instrumentDatas(i).data(j).value)
End If
Next
Next
End If
Catch ex As Exception
End Try
End Sub
End Class
This is a log file produced as a result of running the call:
Response ID: XXXXXXXXXX-XXXXXXXXX
MYO.AU
LAST_UPDATE_DATE_EOD: 06/09/2015
PX_LAST_EOD: 3.480000
PX_VOLUME_EOD: 221871
HIGH_52WEEK_EOD: 3.920000
1530.HK
LAST_UPDATE_DATE_EOD: N.A.
PX_LAST_EOD: N.A.
PX_VOLUME_EOD: 0
HIGH_52WEEK_EOD: N.A.
JPOST.RC
LAST_UPDATE_DATE_EOD:
PX_LAST_EOD:
PX_VOLUME_EOD:
HIGH_52WEEK_EOD:
DTEA
LAST_UPDATE_DATE_EOD: 06/08/2015
PX_LAST_EOD: 28.810000
PX_VOLUME_EOD: 1797455
HIGH_52WEEK_EOD: 29.700000
VSI
LAST_UPDATE_DATE_EOD: 06/08/2015
PX_LAST_EOD: 39.180000
PX_VOLUME_EOD: 391528
HIGH_52WEEK_EOD: 49.040000
GNC
LAST_UPDATE_DATE_EOD: 06/08/2015
PX_LAST_EOD: 44.230000
PX_VOLUME_EOD: 737081
HIGH_52WEEK_EOD: 49.660000
Points of Interest
The LAST_UPDATE_DATE_EOD
in the log file is different for different tickers, because these are international securities, and for some of them, the exchange can close as early as 2am EDT.