Пример #1
0
 public Subscription(string security, IList <string> fields, IList <string> options, CorrelationID correlationID)
 {
     this._security           = security.ToUpper();
     this._fields             = fields.Select(s => s.ToUpper()).ToList();
     this._corr               = correlationID;
     this._conflationInterval = this.ReadConflationInterval(options);
 }
Пример #2
0
 public Subscription(string security, IList <string> fields)
 {
     this._security           = security.ToUpper();
     this._fields             = fields.Select(s => s.ToUpper()).ToList();
     this._corr               = new CorrelationID();
     this._conflationInterval = null;
 }
Пример #3
0
 public Subscription(string security, IList<string> fields)
 {
     this._security = security.ToUpper();
     this._fields = fields.Select(s => s.ToUpper()).ToList();
     this._corr = new CorrelationID();
     this._conflationInterval = null;
 }
Пример #4
0
 public Subscription(string security, IList<string> fields, IList<string> options, CorrelationID correlationID)
 {
     this._security = security.ToUpper();
     this._fields = fields.Select(s => s.ToUpper()).ToList();
     this._corr = correlationID;
     this._conflationInterval = this.ReadConflationInterval(options);
 }
Пример #5
0
 public Subscription(string security, string field, CorrelationID correlationID)
 {
     this._security = security.ToUpper();
     this._fields = new List<string>();
     this._fields.Add(field);
     this._corr = correlationID;
     this._conflationInterval = null;
 }
Пример #6
0
 public Subscription(string security, string field, CorrelationID correlationID)
 {
     this._security = security.ToUpper();
     this._fields   = new List <string>();
     this._fields.Add(field);
     this._corr = correlationID;
     this._conflationInterval = null;
 }
Пример #7
0
        public CorrelationID SendRequest(Request request, CorrelationID correlationId)
        {
            if (request is HistoricalDataRequest.RequestHistoric)
            {
                if (!((HistoricalDataRequest.RequestHistoric)request).DtStart.HasValue)
                    throw new ArgumentException("Historic requests must have start dates");
            }

            request.correlationId = correlationId;
            this._sentRequests.Enqueue(request);
            return correlationId;
        }
Пример #8
0
        public CorrelationID SendRequest(Request request, CorrelationID correlationId)
        {
            if (request is HistoricalDataRequest.RequestHistoric)
            {
                if (!((HistoricalDataRequest.RequestHistoric)request).DtStart.HasValue)
                {
                    throw new ArgumentException("Historic requests must have start dates");
                }
            }

            request.correlationId = correlationId;
            this._sentRequests.Enqueue(request);
            return(correlationId);
        }
Пример #9
0
 public void Cancel(CorrelationID corr)
 {
     lock (this._syncroot) //protect _subscriptions
     {
         for (int i = this._subscriptions.Count - 1; i >= 0; i--)
         {
             if (this._subscriptions[i].CorrelationID.Value == corr.Value && this._subscriptions[i].CorrelationID.IsInternal == corr.IsInternal)
             {
                 MarketDataRequest.EventMarket evtSubCancel = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, this._subscriptions[i]);
                 if (this._asyncHandler != null)
                 {
                     this._asyncHandler(evtSubCancel, this);
                 }
                 this._subscriptions.RemoveAt(i);
             }
         }
     }
 }
Пример #10
0
        public static void RunExample()
        {
            SessionOptions sessionOptions = new SessionOptions();
            sessionOptions.ServerHost = "127.0.0.1";
            sessionOptions.ServerPort = 8194;

            Session session = new Session(sessionOptions);
            session.Start();
            session.OpenService("//blp/refdata");

            Service service = session.GetService("//blp/refdata");

            Request request = service.CreateRequest("HistoricalDataRequest");

            //request information for the following securities
            request.Append("securities", "MSFT US EQUITY");
            //request.Append("securities", "ZYZZ US EQUITY"); //the code treats securities that start with a "Z" as non-existent
            request.Append("securities", "C A COMDTY");
            request.Append("securities", "AAPL 150117C00600000 EQUITY"); //this is a stock option: TICKER yyMMdd[C/P]\d{8} EQUITY

            //include the following simple fields in the result
            //request.Append("fields", "ZBID"); //the code treats a field that starts with a "Z" as a bad field
            request.Append("fields", "BID");
            request.Append("fields", "ASK");

            //Historical requests allow a few overrides.  See the developer's guide A.2.4 for more information.

            request.Set("startDate", DateTime.Today.AddMonths(-1).ToString("yyyyMMdd")); //Request that the information start three months ago from today.  This override is required.
            request.Set("endDate", DateTime.Today.AddDays(10).ToString("yyyyMMdd")); //Request that the information end three days before today.  This is an optional override.  The default is today.

            //Determine the frequency and calendar type of the output. To be used in conjunction with Period Selection.
            request.Set("periodicityAdjustment", "CALENDAR"); //Optional string.  Valid values are ACTUAL (default), CALENDAR, and FISCAL.

            //Determine the frequency of the output. To be used in conjunction with Period Adjustment.
            request.Set("periodicitySelection", "DAILY"); //Optional string.  Valid values are DAILY (default), WEEKLY, MONTHLY, QUARTERLY, SEMI_ANNUALLY, and YEARLY

            //Sets quote to Price or Yield for a debt instrument whose default value is quoted in yield (depending on pricing source).
            request.Set("pricingOption", "PRICING_OPTION_PRICE"); //Optional string.  Valid values are PRICING_OPTION_PRICE (default) and PRICING_OPTION_YIELD

            //Adjust for "change on day"
            request.Set("adjustmentNormal", true); //Optional bool. Valid values are true and false (default = false)

            //Adjusts for Anormal Cash Dividends
            request.Set("adjustmentAbnormal", false); //Optional bool. Valid values are true and false (default = false)

            //Capital Changes Defaults
            request.Set("adjustmentSplit", true); //Optional bool. Valid values are true and false (default = false)

            //The maximum number of data points to return, starting from the startDate
            //request.Set("maxDataPoints", 5); //Optional integer.  Valid values are positive integers.  The default is unspecified in which case the response will have all data points between startDate and endDate

            //Indicates whether to use the average or the closing price in quote calculation.
            request.Set("overrideOption", "OVERRIDE_OPTION_CLOSE"); //Optional string.  Valid values are OVERRIDE_OPTION_GPA for an average and OVERRIDE_OPTION_CLOSE (default) for the closing price

            CorrelationID requestID = new CorrelationID(1);
            session.SendRequest(request, requestID);

            bool continueToLoop = true;
            while (continueToLoop)
            {
                Event eventObj = session.NextEvent();
                switch (eventObj.Type)
                {
                    case Event.EventType.RESPONSE: // final event
                        continueToLoop = false;
                        handleResponseEvent(eventObj);
                        break;
                    case Event.EventType.PARTIAL_RESPONSE:
                        handleResponseEvent(eventObj);
                        break;
                    default:
                        handleOtherEvent(eventObj);
                        break;
                }
            }
        }
Пример #11
0
 public void Cancel(CorrelationID corr)
 {
     lock (this._syncroot) //protect _subscriptions
     {
         for (int i = this._subscriptions.Count - 1; i >= 0; i--)
         {
             if (this._subscriptions[i].CorrelationID.Value == corr.Value && this._subscriptions[i].CorrelationID.IsInternal == corr.IsInternal)
             {
                 MarketDataRequest.EventMarket evtSubCancel = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, this._subscriptions[i]);
                 if (this._asyncHandler != null)
                 {
                     this._asyncHandler(evtSubCancel, this);
                 }
                 this._subscriptions.RemoveAt(i);
             }
         }
     }
 }
Пример #12
0
 public void OpenServiceAsync(string uri, CorrelationID correlationId)
 {
     this._sessionUri = SessionUriType.mktData;
     this._sessionState = SessionStateType.serviceOpened;
     this._asyncOpenCorrelation = correlationId;
 }
Пример #13
0
 protected Message(Name messageType, CorrelationID corr, Service service)
 {
     this._correlationId = corr;
     this._messageType = messageType;
     this._service = service;
 }
Пример #14
0
 public void OpenServiceAsync(string uri, CorrelationID correlationId)
 {
     this._sessionUri           = SessionUriType.mktData;
     this._sessionState         = SessionStateType.serviceOpened;
     this._asyncOpenCorrelation = correlationId;
 }
Пример #15
0
 protected Message(Name messageType, CorrelationID corr, Service service)
 {
     this._correlationId = corr;
     this._messageType   = messageType;
     this._service       = service;
 }
Пример #16
0
        /// <summary>
        /// This example Bloomberg request starts a session meant for Reference Requests and requests a few fields for several securities.
        /// I pulled this example code almost line-for-line from section C.1 of the Bloomberg API Developer's Guide
        /// </summary>
        public static void RunExample()
        {
            SessionOptions sessionOptions = new SessionOptions();
            sessionOptions.ServerHost = "127.0.0.1";
            sessionOptions.ServerPort = 8194;

            Session session = new Session(sessionOptions);
            session.Start();
            session.OpenService("//blp/refdata");

            Service refDataService = session.GetService("//blp/refdata");
            Request request = refDataService.CreateRequest("IntradayTickRequest");

            string security = "SPY US Equity";
            //security = "ZYZZ US EQUITY";  //the code treats securities that start with a "Z" as non-existent
            request.Set("security", security);

            request.Append("eventTypes", "TRADE"); //One of TRADE (default), BID, ASK, BID_BEST, ASK_BEST, MID_PRICE, AT_TRADE, BEST_BID, BEST_ASK (see documentation A.2.6 for explanations)
            request.Append("eventTypes", "BID"); //A request can have multiple eventTypes
            //Note 1) refDataService.ToString() using the Bloomberg API indicates an additional eventType called "SETTLE".  "SETTLE" doesn't seem to produce any results.
            //Note 2) If you request an eventType that isn't supported, the API will throw a KeyNotSupportedException at the "request.Append("eventType", "XXX")" line
            //Note 3) eventType values are case-sensitive.  Requesting "bid" instead of "BID" will throw a KeyNotSupportedException at the "request.Append("eventType", "bid")" line

            request.Set("startDateTime", new Datetime(DateTime.Today.AddHours(9.5999).ToUniversalTime()));
            request.Set("endDateTime", new Datetime(DateTime.Today.AddHours(9.6).ToUniversalTime())); //goes back at most 140 days (documentation section 7.2.3)

            //A comma delimited list of exchange condition codes associated with the event. Review QR<GO> for more information on each code returned.
            request.Set("includeConditionCodes", false); //Optional bool. Valid values are true and false (default = false)

            //Returns all ticks, including those with condition codes.
            request.Set("includeNonPlottableEvents", false); //Optional bool. Valid values are true and false (default = false)

            //The exchange code where this tick originated. Review QR<GO> for more information.
            request.Set("includeExchangeCodes", false); //Optional bool. Valid values are true and false (default = false)

            //Option on whether to return EIDs for the security.
            request.Set("returnEids", false); //Optional bool. Valid values are true and false (default = false)

            //The broker code for Canadian, Finnish, Mexican, Philippine, and Swedish equities only.
            //  The Market Maker Lookup screen, MMTK<GO>, displays further information on market makers and their corresponding codes.
            request.Set("includeBrokerCodes", false); //Optional bool. Valid values are true and false (default = false)

            //The Reporting Party Side. The following values appear:
            //  -B: A customer transaction where the dealer purchases securities from the customer.
            //  -S: A customer transaction where the dealer sells securities to the customer.
            //  -D: An inter-dealer transaction (always from the sell side).
            request.Set("includeRpsCodes", false); //Optional bool. Valid values are true and false (default = false)

            //The BIC, or Bank Identifier Code, as a 4-character unique identifier for each bank that executed and reported the OTC trade, as required by MiFID.
            //  BICs are assigned and maintained by SWIFT (Society for Worldwide Interbank Financial Telecommunication).
            //  The MIC is the Market Identifier Code, and this indicates the venue on which the trade was executed.
            request.Set("includeBicMicCodes", false); //Optional bool. Valid values are true and false (default = false)

            {
                //refDataService.ToString() using the Bloomberg API specifies several boolean overrides that the API documentation doesn't (doc version 2.40).  These are:
                //   forcedDelay, includeSpreadPrice, includeYield, includeActionCodes, includeIndicatorCodes, includeTradeTime, and includeUpfrontPrice
                //These overrides are optional.  Their meanings may be obvious given their names, but I can't be sure.

                request.Set("forcedDelay", false); //Optional bool. Undocumented. default = ???
                request.Set("includeSpreadPrice", false); //Optional bool. Undocumented. default = ???
                request.Set("includeYield", false); //Optional bool. Undocumented. default = ???
                request.Set("includeActionCodes", false); //Optional bool. Undocumented. default = ???
                request.Set("includeIndicatorCodes", false); //Optional bool. Undocumented. default = ???
                request.Set("includeTradeTime", false); //Optional bool. Undocumented. default = ???
                request.Set("includeUpfrontPrice", true); //Optional bool. Undocumented. default = ???
            }

            CorrelationID corr = new CorrelationID(17);

            session.SendRequest(request, corr);

            bool continueToLoop = true;
            while (continueToLoop)
            {
                Event evt = session.NextEvent();

                switch (evt.Type)
                {
                    case Event.EventType.RESPONSE:
                        IntradayTickDataRequest.ProcessResponse(evt, security);
                        continueToLoop = false;
                        break;
                    case Event.EventType.PARTIAL_RESPONSE:
                        IntradayTickDataRequest.ProcessResponse(evt, security);
                        break;
                }
            }
        }
Пример #17
0
        /// <summary>
        /// This example Bloomberg request starts a session meant for Reference Requests and requests a few fields for several securities.
        /// I pulled this example code almost line-for-line from section C.1 of the Bloomberg API Developer's Guide
        /// </summary>
        public static void RunExample()
        {
            SessionOptions sessionOptions = new SessionOptions();
            sessionOptions.ServerHost = "localhost";
            sessionOptions.ServerPort = 8194;

            Session session = new Session(sessionOptions);
            if (!session.Start())
            {
                System.Console.WriteLine("Could not start session.");
                System.Environment.Exit(1);
            }
            if (!session.OpenService("//blp/refdata"))
            {
                System.Console.WriteLine("Could not open service //blp/refdata");
                System.Environment.Exit(1);
            }
            CorrelationID requestID = new CorrelationID(1);
            Service refDataSvc = session.GetService("//blp/refdata");
            Request request = refDataSvc.CreateRequest("ReferenceDataRequest");

            //request information for the following securities
            request.Append("securities", "SPY US EQUITY");
            //request.Append("securities", "ZYZZ US EQUITY"); //the code treats securities that start with a "Z" as non-existent
            request.Append("securities", "MSFT US EQUITY");
            request.Append("securities", "AAPL 150117C00600000 EQUITY"); //this is a stock option: TICKER yyMMdd[C/P]\d{8} EQUITY

            //include the following simple fields in the result
            //request.Append("fields", "ZPX_LAST"); //the code treats a field that starts with a "Z" as a bad field
            request.Append("fields", "PX_LAST");
            request.Append("fields", "BID");
            request.Append("fields", "ASK");
            request.Append("fields", "TICKER");
            request.Append("fields", "OPT_EXPIRE_DT");

            //request a field that can be overriden and returns bulk data
            request.Append("fields", "CHAIN_TICKERS");
            Element overrides = request["overrides"];

            //request only puts
            Element ovrdPutCall = overrides.AppendElement();
            ovrdPutCall.SetElement("fieldId", "CHAIN_PUT_CALL_TYPE_OVRD");
            ovrdPutCall.SetElement("value", "P"); //accepts either "C" for calls or "P" for puts

            //request 5 options in the result
            Element ovrdNumStrikes = overrides.AppendElement();
            ovrdNumStrikes.SetElement("fieldId", "CHAIN_POINTS_OVRD");
            ovrdNumStrikes.SetElement("value", 5); //accepts a positive integer

            //request options that expire on Dec. 20, 2014
            Element ovrdDtExps = overrides.AppendElement();
            ovrdDtExps.SetElement("fieldId", "CHAIN_EXP_DT_OVRD");
            ovrdDtExps.SetElement("value", "20141220"); //accepts dates in the format yyyyMMdd

            session.SendRequest(request, requestID);

            bool continueToLoop = true;
            while (continueToLoop)
            {
                Event eventObj = session.NextEvent();
                switch (eventObj.Type)
                {
                    case Event.EventType.RESPONSE: // final event
                        continueToLoop = false;
                        handleResponseEvent(eventObj);
                        break;
                    case Event.EventType.PARTIAL_RESPONSE:
                        handleResponseEvent(eventObj);
                        break;
                    default:
                        handleOtherEvent(eventObj);
                        break;
                }
            }
        }