Ejemplo n.º 1
0
        private IEnumerable <SystemPropertyRow> GetGenericResponse(O2GSystemPropertiesReader reader)
        {
            var rows = new List <SystemPropertyRow>();

            foreach (var item in reader.Properties)
            {
                var ar = new SystemPropertyRow();
                ar.Name  = item.Key;
                ar.Value = item.Value;
                rows.Add(ar);
            }

            return(rows);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public PriceUpdateController(O2GSession session, string instrument)
        {
            mSyncOfferEvent = new EventWaitHandle(false, EventResetMode.AutoReset);

            mInstrument = instrument;
            mSession    = session;
            mInitFailed = false;

            mSession.subscribeResponse(this);

            mTZConverter = session.getTimeConverter();

            // get the trading day offset
            O2GLoginRules             loginRules = session.getLoginRules();
            O2GResponse               response   = loginRules.getSystemPropertiesResponse();
            O2GSystemPropertiesReader reader     = session.getResponseReaderFactory().createSystemPropertiesReader(response);
            string   eod  = reader.Properties["END_TRADING_DAY"];
            DateTime time = DateTime.ParseExact("01.01.1900_" + eod, "MM.dd.yyyy_HH:mm:ss", CultureInfo.InvariantCulture);

            // convert Trading day start to EST time because the trading day is always closed by New York time
            // so to avoid handling different hour depending on daylight saying time - use EST always
            // for candle calculations
            time = mTZConverter.convert(time, O2GTimeConverterTimeZone.UTC, O2GTimeConverterTimeZone.EST);
            // here we have the date when trading day begins, e.g. 17:00:00
            // please note that if trading day begins before noon - it begins AFTER calendar date is started,
            // so the offset is positive (e.g. 03:00 is +3 offset).
            // if trading day begins after noon, it begins BEFORE calendar date is istarted,
            // so the offset is negative (e.g. 17:00 is -7 offset).
            if (time.Hour <= 12)
            {
                mTradingDayOffset = time.Hour;
            }
            else
            {
                mTradingDayOffset = time.Hour - 24;
            }

            // get latest offer for the instrument
            GetLatestOffer();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Listener: When Trading session status is changed
        /// </summary>
        /// <param name="status"></param>
        public void onSessionStatusChanged(O2GSessionStatusCode status)
        {
            switch (status)
            {
            case    O2GSessionStatusCode.TradingSessionRequested:
                // If the trading session requires the session name or pin code...
                if (OnErrorEvent != null)
                {
                    OnErrorEvent("Multi-session connectors aren't supported by this example\n");
                }
                mTradingSession.logout();
                break;

            case    O2GSessionStatusCode.Connected:
                // login is completed

                // now we need collect data about the system properties
                O2GLoginRules loginRules = mTradingSession.getLoginRules();
                mTZConverter = mTradingSession.getTimeConverter();
                // get the trading day offset.
                O2GResponse response;
                response = loginRules.getSystemPropertiesResponse();
                O2GSystemPropertiesReader reader = mTradingSession.getResponseReaderFactory().createSystemPropertiesReader(response);
                string   eod  = reader.Properties["END_TRADING_DAY"];
                DateTime time = DateTime.ParseExact("01.01.1900_" + eod, "MM.dd.yyyy_HH:mm:ss", CultureInfo.InvariantCulture);
                // convert Trading day start to EST time because the trading day is always closed by New York time
                // so to avoid handling different hour depending on daylight saying time - use EST always
                // for candle calculations
                time = mTZConverter.convert(time, O2GTimeConverterTimeZone.UTC, O2GTimeConverterTimeZone.EST);
                // here we have the date when trading day begins, e.g. 17:00:00
                // please note that if trading day begins before noon - it begins AFTER calendar date is started,
                // so the offset is positive (e.g. 03:00 is +3 offset).
                // if trading day begins after noon, it begins BEFORE calendar date is istarted,
                // so the offset is negative (e.g. 17:00 is -7 offset).
                if (time.Hour <= 12)
                {
                    mTradingDayOffset = time.Hour;
                }
                else
                {
                    mTradingDayOffset = time.Hour - 24;
                }

                // ...and now get the list of the offers to which the user is subscribed
                if (loginRules.isTableLoadedByDefault(O2GTableType.Offers))
                {
                    // if it is already loaded - just handle them
                    response = loginRules.getTableRefreshResponse(O2GTableType.Offers);
                    onRequestCompleted(null, response);
                }
                else
                {
                    // otherwise create the request to get offers from the server
                    O2GRequestFactory factory      = mTradingSession.getRequestFactory();
                    O2GRequest        offerRequest = factory.createRefreshTableRequest(O2GTableType.Offers);
                    mTradingSession.sendRequest(offerRequest);
                }
                break;

            default:
                if (OnStateChange != null)
                {
                    OnStateChange(false);
                }
                break;
            }
        }