Example #1
0
        public virtual bool SendMessage(MessageTypes type, long source, long dest, long msgid, string request, string response)
        {
            if (_tl == null)
            {
                return(false);
            }
            if (!_tl.RequestFeatureList.Contains(type))
            {
                SendDebug(type.ToString() + " not supported by " + _tl.Name);
                return(false);
            }
            try
            {
                // prepare message
                switch (type)
                {
                case MessageTypes.DOMREQUEST:
                    request = request.Replace(Book.EMPTYREQUESTOR, _tl.Name);
                    break;

                case MessageTypes.BARREQUEST:
                {
                    BarRequest br = BarImpl.ParseBarRequest(request);
                    br.Client = _tl.Name;
                    request   = BarImpl.BuildBarRequest(br);
                }
                break;

                case MessageTypes.FEATUREREQUEST:
                    request = _tl.Name;
                    break;

                case MessageTypes.IMBALANCEREQUEST:
                    request = _tl.Name;
                    break;
                }
                // send it
                long   result = _tl.TLSend(type, request);
                string res    = result.ToString();
                // pass along result
                if ((SendMessageResponse != null) && (result != 0))
                {
                    SendMessageResponse(type, source, dest, msgid, request, ref res);
                }
                return(true);
            }
            catch (Exception ex)
            {
                debug("Error on: " + type.ToString() + source + dest + msgid + request + response);
                debug(ex.Message + ex.StackTrace);
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// send a message to providers
        /// </summary>
        /// <param name="type"></param>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <param name="msgid"></param>
        /// <param name="message"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public long TLSend(MessageTypes type, long source, long dest, long msgid, string message, ref string result)
        {
            v(type.ToString() + " sending to all providers: " + message);
            for (int i = 0; i < _pcon.Count; i++)
            {
                if (_pcon[i].RequestFeatureList.Contains(type))
                {
                    bool showret = false;
                    // prepare message
                    switch (type)
                    {
                    case MessageTypes.DOMREQUEST:
                        message = message.Replace(Book.EMPTYREQUESTOR, _pcon[i].Name);
                        showret = true;
                        break;

                    case MessageTypes.BARREQUEST:
                    {
                        BarRequest br = BarImpl.ParseBarRequest(message);
                        br.Client = _pcon[i].Name;
                        message   = BarImpl.BuildBarRequest(br);
                        showret   = true;
                    }
                    break;

                    case MessageTypes.FEATUREREQUEST:
                        message = _pcon[i].Name;
                        showret = true;
                        break;
                    }
                    long res = _pcon[i].TLSend(type, message);
                    result = res.ToString();
                    if (gotUnknownMessage != null)
                    {
                        gotUnknownMessage(type, source, dest, msgid, message, ref result);
                    }

                    return(res);
                }
                else if (VerboseDebugging)
                {
                    v(_pcon[i].BrokerName + " " + _pcon[i].Name + " does not support feature " + type + ", dropping message.");
                }
            }
            return(0);
        }
Example #3
0
        /// <summary>
        /// build bar request for certain # of bars back from present
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="barsback"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static string BuildBarRequestBarsBack(string sym, int barsback, int interval)
        {
            DateTime n = DateTime.Now;

            return(BarImpl.BuildBarRequest(new BarRequest(sym, interval, Util.ToTLDate(BarImpl.DateFromBarsBack(barsback, interval, n)), Util.ToTLTime(BarImpl.DateFromBarsBack(barsback, interval, n)), Util.ToTLDate(n), Util.ToTLTime(n), string.Empty)));
        }