示例#1
0
        static void settable_SendMessageEvent(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            switch (type)
            {
            case MessageTypes.SENDUSERSETTABLE:
                tmp_settablelist = request;
                break;

            case MessageTypes.BARREQUEST:
            {
                var br = BarRequest.Deserialize(request);
                if (br.isValid)
                {
                    br.symbol = string.Empty;
                    bool addit = true;
                    for (int i = 0; i < tmp_barreqs.Count; i++)
                    {
                        var cmp = tmp_barreqs[i];
                        if ((cmp.CustomInterval == br.CustomInterval) && (cmp.Interval == br.Interval) && (cmp.BarsBackExplicit == br.BarsBackExplicit))
                        {
                            addit = false;
                            break;
                        }
                    }
                    if (addit)
                    {
                        tmp_barreqs.Add(br);
                    }
                }
            }
            break;
            }
        }
示例#2
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);
        }
示例#3
0
 /// <summary>
 /// builds bar request
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public static string BuildBarRequest(BarRequest br)
 {
     string[] r = new string[]
     {
         br.Symbol,
         br.Interval.ToString(),
         br.StartDate.ToString(),
         br.StartTime.ToString(),
         br.EndDate.ToString(),
         br.EndTime.ToString(),
         br.ID.ToString(),
         br.CustomInterval.ToString(),
         br.Client,
     };
     return(string.Join(",", r));
 }
示例#4
0
        /// <summary>
        /// parses message into a structured bar request
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static BarRequest ParseBarRequest(string msg)
        {
            string[]   r  = msg.Split(',');
            BarRequest br = new BarRequest();

            br.Symbol         = r[(int)BarRequestField.Symbol];
            br.Interval       = Convert.ToInt32(r[(int)BarRequestField.BarInt]);
            br.StartDate      = int.Parse(r[(int)BarRequestField.StartDate]);
            br.StartTime      = int.Parse(r[(int)BarRequestField.StartTime]);
            br.EndDate        = int.Parse(r[(int)BarRequestField.EndDate]);
            br.EndTime        = int.Parse(r[(int)BarRequestField.EndTime]);
            br.CustomInterval = int.Parse(r[(int)BarRequestField.CustomInterval]);
            br.ID             = long.Parse(r[(int)BarRequestField.ID]);
            br.Client         = r[(int)BarRequestField.Client];
            return(br);
        }
示例#5
0
 /// <summary>
 /// builds bar request
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public static string Serialize(BarRequest br)
 {
     string[] r = new string[]
     {
         br.symbol,
         br.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.StartDate.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.StartTime.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.EndDate.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.EndTime.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.ID.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.CustomInterval.ToString(System.Globalization.CultureInfo.InvariantCulture),
         br.Client,
         br.BarsBackExplicit.ToString(System.Globalization.CultureInfo.InvariantCulture)
     };
     return(string.Join(",", r));
 }
示例#6
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);
        }
示例#7
0
 public void BarsBackSerializeDeSerialize()
 {
     // build request
     var br = new BarRequest(sym, 300, 300, 100, string.Empty);
     // verify it
     Assert.IsTrue(br.isValid, "original not valid");
     Assert.AreEqual(300, br.Interval, "interval missing");
     Assert.AreEqual(sym, br.symbol, "symbol missing");
     Assert.AreEqual(100, br.BarsBack, "bars back missing");
     // serialize request
     var msg = br.Serialize();
     // deserialize
     var copy = BarRequest.Deserialize(msg);
     // verify valid
     Assert.IsTrue(copy.isValid, "copy not valid");
     // verify same
     Assert.AreEqual(br.symbol, copy.symbol, "symbol mismatch");
     Assert.AreEqual(br.BarsBack, copy.BarsBack, "symbol mismatch");
     Assert.AreEqual(br.Interval, copy.Interval, "symbol mismatch");
 }
示例#8
0
        /// <summary>
        /// parses message into a structured bar request
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static BarRequest Deserialize(string msg)
        {
            string[]   r  = msg.Split(',');
            BarRequest br = new BarRequest();

            try
            {
                br.symbol           = r[(int)BarRequestField.Symbol];
                br.Interval         = Convert.ToInt32(r[(int)BarRequestField.BarInt], System.Globalization.CultureInfo.InvariantCulture);
                br.StartDate        = int.Parse(r[(int)BarRequestField.StartDate], System.Globalization.CultureInfo.InvariantCulture);
                br.StartTime        = int.Parse(r[(int)BarRequestField.StartTime], System.Globalization.CultureInfo.InvariantCulture);
                br.EndDate          = int.Parse(r[(int)BarRequestField.EndDate], System.Globalization.CultureInfo.InvariantCulture);
                br.EndTime          = int.Parse(r[(int)BarRequestField.EndTime], System.Globalization.CultureInfo.InvariantCulture);
                br.CustomInterval   = int.Parse(r[(int)BarRequestField.CustomInterval], System.Globalization.CultureInfo.InvariantCulture);
                br.ID               = long.Parse(r[(int)BarRequestField.ID], System.Globalization.CultureInfo.InvariantCulture);
                br.Client           = r[(int)BarRequestField.Client];
                br.BarsBackExplicit = Convert.ToInt32(r[(int)BarRequestField.BarsBackExplicit], System.Globalization.CultureInfo.InvariantCulture);
            }
            catch (FormatException) { }
            catch (OverflowException) { }
            catch (ArgumentNullException) { }
            return(br);
        }
示例#9
0
 void RequestBars(BarRequest br)
 {
     string command;
     long id = _idt.AssignId;
     if (br.Interval == (int)BarInterval.Day)
     {
         command = String.Format("HDT,{0},{1},,1,{2}\r\n", br.Symbol,br.StartDateTime.ToLongDateString(),br.EndDateTime.ToLongDateString(),id);
     }
     else
     {
         command = String.Format("HIT,{0},{1},{2} {3},{4} {5},,000000,235959,1,{6}\r\n", br.Symbol, br.Interval, br.StartDateTime.ToString("yyyyMMdd"), br.StartDateTime.ToString("HHmmss"), br.EndDateTime.ToString("yyyyMMdd"), br.EndDateTime.ToString("HHmmss"),id);
     }
     reqid2req.Add(id, br);
     // we form a watch command in the form of wSYMBOL\r\n
     byte[] watchCommand = new byte[command.Length];
     watchCommand = Encoding.ASCII.GetBytes(command);
     try
     {
         m_hist.Send(watchCommand, watchCommand.Length, SocketFlags.None);
         debug("Requested historical bars for: " + br.Symbol);
     }
     catch (Exception ex)
     {
         debug("Exception sending barrequest: " + br.ToString());
         debug(ex.Message + ex.StackTrace);
     }
 }
示例#10
0
        public void submitBarRequest(BarRequest br)
        {
            waitforhistorical2complete = true;
            debug("br.Client=" + br.Client);
            string symbol = br.symbol;
            int lRequestID = (int)br.Interval % 100;
            int lPeriod = (int)br.Interval / 100;
            int lMaxRecs = br.CustomInterval / 10;
            bool bUpdate = (br.CustomInterval % 10 == 0) ? false : true;
				bool bExtSession = false;
            int tlDateS = br.StartDate;
            int tlTimeS = br.StartTime;
            DateTime dtStart = TradeLink.Common.Util.ToDateTime(tlDateS, tlTimeS);
            int tlDateE = br.EndDate;
            int tlTimeE = br.EndTime;
            DateTime dtEnd = TradeLink.Common.Util.ToDateTime(tlDateE, tlTimeE);

            if (!_barhandle2barrequest.ContainsKey(lRequestID))
                _barhandle2barrequest.Add(lRequestID, br);
            else
                debug("already had bar request: " + lRequestID + " " + _barhandle2barrequest[lRequestID].ToString());

            int lRequestType = lRequestID % 10;

            switch (lRequestType)
            {
                case 1:
                    MbtHistDayBar moDayBar = m_HistMgr.CreateHistDayBar();
                    moDayBar.Clear();
						  debug(symbol + "Day: lID:" + lRequestID + " lPd:" + lPeriod + " b:" + dtStart + " e:" + dtEnd + " lMax:" + lMaxRecs + " bUp:" + bUpdate);
                    moDayBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
                    break;
                case 2:
                    MbtHistMinBar moMinBar = m_HistMgr.CreateHistMinBar();
                    moMinBar.Clear();
						  debug(symbol + "Min: lID:" + lRequestID + " lPd:" + lPeriod + " b:" + dtStart + " e:" + dtEnd + " lMax:" + lMaxRecs + " bUp:" + bUpdate + " ext:" + bExtSession);
                    moMinBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate, bExtSession);
                    break;
                case 3:
                    MbtHistTick moTickBar = m_HistMgr.CreateHistTick();
                    moTickBar.Clear();
						lPeriod=0; // for all ticks
						debug(symbol + "Tick: lID:" + lRequestID + " filter:" + lPeriod + " b:" + dtStart + " e:" + dtEnd + " lMax:" + lMaxRecs + " bUp:" + bUpdate);
//						  moTickBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
						  moTickBar.SendRequest(symbol, lRequestID, (int)MBTHISTLib.enumTickRequestFilter.trfAllTicks, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
                    break;
						//pmh - 9/13/12 - PV bar
					 case 4:
						  MbtHistPVBar moMinPV = m_HistMgr.CreateHistPVBar();
						  moMinPV.Clear();
						  debug(symbol + "PV: lID:" + lRequestID + " lPd:" + lPeriod + " b:" + dtStart + " e:" + dtEnd + " lMax:" + lMaxRecs);
						  moMinPV.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs);
						  break;
				}
        }
示例#11
0
        bool isrecorddone(string rec, string [] r, string prev, out BarRequest br)
        {
            long reqid = 0;
            br = new BarRequest();
            if (r.Length > 0)
            {
                if (long.TryParse(r[0], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out reqid))
                {
                    // make request invalid if can't be found
                    if (!reqid2req.TryGetValue(reqid, out br))
                    {
                        v("hist no request id found: " + rec);
                        br = new BarRequest();
                    }
                    else
                    {
                        v("hist response to request: " + reqid + " from: " + br.Client);
                    }
                }

            }

            var minexpectrecordcount = br.BarInterval == BarInterval.Day ? 7 : 8;

            // this should get hit on ENDMSG
            if (r.Length < minexpectrecordcount)
            {
                if (rec.Contains(HISTEND))
                {
                    if (br.isIdValid)
                    {
                        debug("hist completed request " + br.ID);
                        tl.TLSend(BarRequest.Serialize(br), MessageTypes.BARRESPONSE_FINAL, br.Client);
                        
                    }
                    else
                        debug("hist unknown request completed: " + rec);
                    return true;
                }
                else // could be a partial record  (that needs buffering) or an error/unknown state
                {
                    v("hist unknown data, id: " + br.ID + " data: " + rec);
                }
                return false;
            }
            if (!br.isValid)
            {
                if (string.IsNullOrWhiteSpace(prev))
                    debug("hist unknown bar request data " + rec);
                else
                    debug("hist unknown bar request data:" + rec + " prev: " + prev + " buf: " + _histbuff);
                return true;
            }
            return false;
        }
示例#12
0
 /// <summary>
 /// parses message into a structured bar request
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static BarRequest Deserialize(string msg)
 {
     string[] r = msg.Split(',');
     BarRequest br = new BarRequest();
     try
     {
         br.symbol = r[(int)BarRequestField.Symbol];
         br.Interval = Convert.ToInt32(r[(int)BarRequestField.BarInt], System.Globalization.CultureInfo.InvariantCulture);
         br.StartDate = int.Parse(r[(int)BarRequestField.StartDate], System.Globalization.CultureInfo.InvariantCulture);
         br.StartTime = int.Parse(r[(int)BarRequestField.StartTime], System.Globalization.CultureInfo.InvariantCulture);
         br.EndDate = int.Parse(r[(int)BarRequestField.EndDate], System.Globalization.CultureInfo.InvariantCulture);
         br.EndTime = int.Parse(r[(int)BarRequestField.EndTime], System.Globalization.CultureInfo.InvariantCulture);
         br.CustomInterval = int.Parse(r[(int)BarRequestField.CustomInterval], System.Globalization.CultureInfo.InvariantCulture);
         br.ID = long.Parse(r[(int)BarRequestField.ID], System.Globalization.CultureInfo.InvariantCulture);
         br.Client = r[(int)BarRequestField.Client];
         br.BarsBackExplicit = Convert.ToInt32(r[(int)BarRequestField.BarsBackExplicit], System.Globalization.CultureInfo.InvariantCulture);
     }
     catch (FormatException) { }
     catch (OverflowException) { }
     catch (ArgumentNullException) { }
     return br;
 }
示例#13
0
        /// <summary>
        /// builds bar request
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        public static string Serialize(BarRequest br)
        {
            
            string[] r = new string[] 
            {
                br.symbol,
                br.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.StartDate.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.StartTime.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.EndDate.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.EndTime.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.ID.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.CustomInterval.ToString(System.Globalization.CultureInfo.InvariantCulture),
                br.Client,
                br.BarsBackExplicit.ToString(System.Globalization.CultureInfo.InvariantCulture)
            };
            return string.Join(",", r);

        }
示例#14
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!_valid) return;
            while (_go)
            {
                try
                {
                    if (qc > qr)
                    {
                        // get requested symbols
                        string[] syms = _tmpregister.Split(',');
                        // go through each one
                        foreach (string sym in syms)
                        {
                            // if we don't have subscription already
                            if (!contains(sym))
                            {
                                // add it to list
                                _mb.Add(sym);
                                // request subscription
                                esig.RequestSymbol(sym, 1);
                            }
                        }
                        if (ReleaseDeadSymbols)
                        {
                            // clone requested basket
                            Basket newbasket = new BasketImpl(syms);
                            // clone existing basket as deadbasket
                            Basket deadbasket = new BasketImpl(_mb);
                            // existing - new = deadsymbols
                            deadbasket.Remove(newbasket);
                            // release dead symbols
                            string symsreleased = string.Empty;
                            foreach (Security dead in deadbasket)
                            {
                                try
                                {
                                    esig.ReleaseSymbol(dead.symbol);
                                    symsreleased += dead.symbol + " ";
                                }
                                catch { }
                            }
                            if (symsreleased!=string.Empty)
                                verb("released unused symbols: " + symsreleased);
                        }
                        qr = qc;
                    }
                    while (_barrequests.hasItems)
                    {
                        BarRequest br = new BarRequest();
                        try
                        {
                            br = _barrequests.Read();
                            BarInterval bi = (BarInterval)br.Interval;
                            string interval = string.Empty;
                            int barsback = DefaultBarsBack;
                            if (bi == BarInterval.CustomTicks)
                                interval = br.CustomInterval + "T";
                            else if (bi == BarInterval.CustomTime)
                                interval = br.CustomInterval + "S";
                            else if (bi == BarInterval.CustomVol)
                                interval = br.CustomInterval + "V";
                            else
                            {
                                if (br.Interval == (int)BarInterval.Day)
                                    interval = "D";
                                else
                                    interval = (br.Interval / 60).ToString();

                                barsback = BarImpl.BarsBackFromDate(bi, br.StartDateTime, br.EndDateTime);
                            }
                            int alldata = BarRequestsGetAllData ? -1 : 0;
                            int hnd = esig.get_RequestHistory(br.symbol, interval, (bi == BarInterval.Day) ? barType.btDAYS : barType.btBARS, barsback, alldata, alldata);
                            verb("requested bar data for " + br.symbol + " on: " + br.Interval.ToString() + " " + br.CustomInterval.ToString() + " reqhandle: " + hnd);
                            // cache request
                            if (!_barhandle2barrequest.ContainsKey(hnd))
                                _barhandle2barrequest.Add(hnd, br);
                            else
                                verb("already had bar request: " + hnd + " " + _barhandle2barrequest[hnd].ToString());
                            if (esig.get_IsHistoryReady(hnd) != 0)
                                processhistory(hnd, br);
                        }
                        catch (Exception ex)
                        {
                            debug("error on historical bar request: " + br.ToString());
                            debug(ex.Message + ex.StackTrace);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (GotDebug != null)
                        GotDebug(ex.Message + ex.StackTrace);
                }
                if (e.Cancel || !_go)
                    break;
                System.Threading.Thread.Sleep(WaitBetweenEvents);
            }
        }
示例#15
0
 /// <summary>
 /// builds bar request
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public static string BuildBarRequest(BarRequest br)
 {
     string[] r = new string[]
     {
         br.Symbol,
         br.Interval.ToString(),
         br.StartDate.ToString(),
         br.StartTime.ToString(),
         br.EndDate.ToString(),
         br.EndTime.ToString(),
         br.ID.ToString(),
         br.CustomInterval.ToString(),
         br.Client,
     };
     return string.Join(",", r);
 }
示例#16
0
        void RequestBars(BarRequest br)
        {
            // for command docs see http://www.iqfeed.net/dev/api/docs/HistoricalviaTCPIP.cfm
            string command = string.Empty;
            // ensure we're connected
            if (m_hist == null)
            {
                ConnectHist();
            }
            
            if (br.BarInterval == BarInterval.Day)
            {
                var previousdays = br.isExplictBarsBack ? br.BarsBackExplicit : BarImpl.BarsBackFromDate(br.BarInterval, br.StartDateTime, br.EndDateTime);
                // HDX,[Symbol],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]
                if (br.isExplictBarsBack)
                {
                    br.Tag = "HDX";
                    command = String.Format("HDX,{0},{1},{2},{3},{4}", br.symbol, previousdays, HistoricalDataDirection, br.ID, HistoricalDataPointPerSec);
                }
                else if (br.isExplicitStart)
                {
                    // HDT,[Symbol],[BeginDate],[EndDate],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]
                    var start = br.StartDateTime.ToString("yyyyMMdd");
                    var end = br.isExplicitDate ? br.EndDateTime.ToString("yyyyMMdd") : string.Empty;
                    var maxdata = br.isExplicitDate ? (int)br.EndDateTime.Subtract(br.StartDateTime).TotalDays : (int)DateTime.Now.Subtract(br.StartDateTime).TotalDays;
                    br.Tag = "HDT";
                    command = string.Format("HDT,{0},{1},{2},{3},{4},{5},{6}", br.symbol, start, end, maxdata, HistoricalDataDirection, br.ID, HistoricalDataPointPerSec);
                }
            }
            else
            {
                // validate interval type
                string sIntervalType = "s";
                int bint = br.CustomInterval;
                if (br.BarInterval== BarInterval.CustomVol)
                {
                    sIntervalType = "v";
                    bint = br.CustomInterval;
                }
                else if (br.BarInterval== BarInterval.CustomTicks)
                {
                    sIntervalType = "t";
                    bint = br.CustomInterval;
                }
                if (br.isExplictBarsBack && !br.isExplicitEnd && !br.isExplicitStart)
                {
                    br.Tag = "HIX";
                    //HIX,[Symbol],[Interval],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend],[IntervalType]
                    command = String.Format("HIX,{0},{1},{2},{3},{4},{5},{6}", br.symbol, bint, br.BarsBackExplicit, HistoricalDataDirection, br.ID, HistoricalDataPointPerSec, sIntervalType);
                }
                else
                {
                    br.Tag = "HIT";
                    // request in the format:
                    //HIT,[Symbol],[Interval],[BeginDate BeginTime],[EndDate EndTime],[MaxDatapoints],[BeginFilterTime],[EndFilterTime],[DataDirection],[RequestID],[DatapointsPerSend],[IntervalType]<CR><LF> 
                    // HIT,SYMBOL,INTERVAL,BEGINDATE BEGINTIME,ENDDATE ENDTIME,MaxDataPoints,BEGINFILTERTIME,ENDFILTERTIME,DIRECTION,REQUESTID,DATAPOINTSPERSEND,INTERVALTYPE<CR><LF>
                    
                    var startdate = br.isExplicitStart ? br.StartDateTime.ToString("yyyyMMdd") : string.Empty;
                    var starttime = br.isExplicitStart ? br.StartDateTime.ToString("HHmmss") : string.Empty;
                    var enddate = br.isExplicitEnd ? br.EndDateTime.ToString("yyyyMMdd") : string.Empty;
                    var endtime = br.isExplicitEnd ? br.EndDateTime.ToString("HHmmss") : string.Empty;
                    var maxpoints = br.isExplictBarsBack ? br.BarsBackExplicit.ToString("F0") : string.Empty;
                    command = String.Format("HIT,{0},{1},{2} {3},{4} {5},{6},,,{7},{8},{9},{10}", br.symbol, bint, startdate, starttime,enddate ,endtime , maxpoints, HistoricalDataDirection, br.ID, HistoricalDataPointPerSec, sIntervalType);
                }
            }
            reqid2req.Add(br.ID, br);
            byte[] watchCommand = getcmddata(command);
            try
            {
                if (m_hist != null)
                {
                    m_hist.Send(watchCommand, watchCommand.Length, SocketFlags.None);
                    if (VerboseDebugging)
                        v("hist requested: " + br.symbol + " watch: " + command+" for: "+br.ToString());
                    else
                        debug("Requested historical bars for: " + br.ToString());

                }
                else
                {
                    debug("No historical connection available to request bars: " + br.ToString());
                }
            }
            catch (Exception ex)
            {
                debug("Exception sending barrequest: " + br.ToString());
                debug(ex.Message + ex.StackTrace);
            }
        }
示例#17
0
        public void submitBarRequest(BarRequest br)
        {
            waitforhistorical2complete = true;
            debug("br.Client=" + br.Client);
            string symbol = br.Symbol;
            int lRequestID = (int)br.Interval % 100;
            int lPeriod = (int)br.Interval / 100;
            int lMaxRecs = br.CustomInterval / 10;
            bool bUpdate = (br.CustomInterval % 10 == 0) ? false : true;
            int tlDateS = br.StartDate;
            int tlTimeS = br.StartTime;
            DateTime dtStart = TradeLink.Common.Util.ToDateTime(tlDateS, tlTimeS);
            int tlDateE = br.EndDate;
            int tlTimeE = br.EndTime;
            DateTime dtEnd = TradeLink.Common.Util.ToDateTime(tlDateE, tlTimeE);

            if (!_barhandle2barrequest.ContainsKey(lRequestID))
                _barhandle2barrequest.Add(lRequestID, br);
            else
                debug("already had bar request: " + lRequestID + " " + _barhandle2barrequest[lRequestID].ToString());

            int lRequestType = lRequestID % 10;

            switch (lRequestType)
            {
                case 1:
                    MbtHistDayBar moDayBar = m_Hist.CreateHistDayBar();
                    moDayBar.Clear();
                    debug(symbol + " " + lRequestID + " " + lPeriod + " " + dtStart + " " + dtEnd + " " + lMaxRecs + " " + bUpdate);
                    moDayBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
                    break;
                case 2:
                    MbtHistMinBar moMinBar = m_Hist.CreateHistMinBar();
                    moMinBar.Clear();
                    debug(symbol + " " + lRequestID + " " + lPeriod + " " + dtStart + " " + dtEnd + " " + lMaxRecs + " " + bUpdate);
                    moMinBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
                    break;
                case 3:
                    MbtHistTick moTickBar = m_Hist.CreateHistTick();
                    moTickBar.Clear();
                    moTickBar.SendRequest(symbol, lRequestID, lPeriod, dtStart.ToUniversalTime(), dtEnd.ToUniversalTime(), lMaxRecs, bUpdate);
                    break;
            }

        }
示例#18
0
 /// <summary>
 /// parses message into a structured bar request
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static BarRequest ParseBarRequest(string msg)
 {
     string[] r = msg.Split(',');
     BarRequest br  = new BarRequest();
     br.Symbol = r[(int)BarRequestField.Symbol];
     br.Interval = Convert.ToInt32(r[(int)BarRequestField.BarInt]);
     br.StartDate = int.Parse(r[(int)BarRequestField.StartDate]);
     br.StartTime = int.Parse(r[(int)BarRequestField.StartTime]);
     br.EndDate= int.Parse(r[(int)BarRequestField.EndDate]);
     br.EndTime = int.Parse(r[(int)BarRequestField.EndTime]);
     br.CustomInterval = int.Parse(r[(int)BarRequestField.CustomInterval]);
     br.ID = long.Parse(r[(int)BarRequestField.ID]);
     br.Client = r[(int)BarRequestField.Client];
     return br;
 }
示例#19
0
 void processhistory(int lHandle,BarRequest br)
 {
     int numbars = esig.get_GetNumBars(lHandle);
     if (numbars == 0)
     {
         verb("no bars available for reqhandle: " + lHandle);
         return;
     }
     numbars *= -1;
     for (int i = numbars; i<=0; i++)
     {
         try
         {
             BarData bd = esig.get_GetBar(lHandle, i);
             if (VerboseDebugging)
                 verb(br.symbol + " " + bd.dtTime.ToString() + " " + bd.dOpen + " " + bd.dHigh + " " + bd.dLow + " " + bd.dClose + " " + bd.dVolume);
             Bar b = new BarImpl((decimal)bd.dOpen, (decimal)bd.dHigh, (decimal)bd.dLow, (decimal)bd.dClose, (long)bd.dVolume, Util.ToTLDate(bd.dtTime), Util.ToTLTime(bd.dtTime), br.symbol, br.Interval);
             string msg = BarImpl.Serialize(b);
             if (!b.isValid && !AllowSendInvalidBars)
             {
                 debug("Not sending invalid bar: " + b.ToString()+" raw: "+msg);
                 continue;
             }
             tl.TLSend(msg, MessageTypes.BARRESPONSE, br.Client);
         }
         catch (Exception ex)
         {
             verb("error obtaining bar: " + i + " from: " + lHandle);
             verb(ex.Message + ex.StackTrace);
         }
     }
     if (ReleaseBarHistoryAfteRequest)
     {
         try
         {
             esig.ReleaseHistory(lHandle);
             _barhandle2barrequest.Remove(lHandle);
         }
         catch { }
     }
 }
示例#20
0
        void OnReceiveHist(IAsyncResult result)
        {
            try
            {
                int bytesReceived = m_hist.EndReceive(result);
                var records = getrecords(m_buffhist, bytesReceived);

                // mark record processing status
                var lastrecordprocessed = false;
                var lastrecordidx = records.Length - 1;

                // process records
                for (int i = 0; i<records.Length; i++)
                {
                    // get record
                    var rec = records[i];
                    // mark it's status
                    lastrecordprocessed = false;
                    // skip empty data
                    if (string.IsNullOrWhiteSpace(rec))
                        continue;
                    // look for misc responses
                    if (checkhistproto && rec.Contains(expecthistproto))
                    {
                        checkhistproto = false;
                        rec = rec.Replace(expecthistproto, string.Empty);
                        records[i] = rec;
                        lastrecordprocessed = i == lastrecordidx;
                        v("hist protocol ack:" + expecthistproto);
                    }
                    string[] r = rec.Split(',');
                    // test for request id and response type
                    BarRequest br = new BarRequest();
                    var prev = (i == 0) ? string.Empty : records[i - 1];
                    if (isrecorddone(rec, r, prev, out br))
                    {
                        v("hist processed: " + rec);
                        lastrecordprocessed = i == lastrecordidx;
                        continue;
                    }
                    else if (i==lastrecordidx)
                    {
                        lastrecordprocessed = false;
                    }

                    Bar b = new BarImpl();

                    try
                    {
                        if (br.isValid)
                        {
                            if (br.BarInterval == BarInterval.Day)
                            {
                                DateTime dt = DateTime.MinValue;
                                if (!DateTime.TryParse(r[1], System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.NoCurrentDateDefault, out dt))
                                {
                                    v("hist can't parse date: " + r[1] + " data: " + rec);
                                    continue;
                                }
                                decimal o, h, l, c;
                                long vol;
                                if (!decimal.TryParse(r[2], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out h))
                                {
                                    v("hist can't parse high: " + r[2] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[3], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out l))
                                {
                                    v("hist can't parse low: " + r[3] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[4], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out o))
                                {
                                    v("hist can't parse open: " + r[4] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[5], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out c))
                                {
                                    v("hist can't parse close: " + r[5] + " data: " + rec);
                                    continue;
                                }
                                else if (!long.TryParse(r[6], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out vol))
                                {
                                    v("hist can't parse vol: " + r[6] + " data: " + rec);
                                    continue;
                                }
                                // mark iqfeed processing status
                                lastrecordprocessed = i == lastrecordidx;
                                // build bar
                                b = new BarImpl(o, h, l, c, vol, Util.ToTLDate(dt), Util.ToTLTime(dt), br.symbol, br.Interval,br.CustomInterval,br.ID);
                                if (VerboseDebugging)
                                    debug("hist got bar: " + b);
                            }
                            else
                            {
                                DateTime dt = DateTime.MinValue;
                                if (!DateTime.TryParse(r[1], System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.NoCurrentDateDefault, out dt))
                                {
                                    v("hist can't parse date: " + r[1] + " data: " + rec);
                                    continue;
                                }
                                decimal o, h, l, c;
                                long vol;
                                if (!decimal.TryParse(r[2], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out h))
                                {
                                    v("hist can't parse high: " + r[2] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[3], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out l))
                                {
                                    v("hist can't parse low: " + r[3] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[4], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out o))
                                {
                                    v("hist can't parse open: " + r[4] + " data: " + rec);
                                    continue;
                                }
                                else if (!decimal.TryParse(r[5], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out c))
                                {
                                    v("hist can't parse close: " + r[5] + " data: " + rec);
                                    continue;
                                }
                                else if (!long.TryParse(r[7], System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out vol))
                                {
                                    v("hist can't parse vol: " + r[7] + " data: " + rec);
                                    continue;
                                }
                                // mark iqfeed processing status
                                lastrecordprocessed = i == lastrecordidx;
                                // build bar
                                b = new BarImpl(o, h, l, c, vol, Util.ToTLDate(dt), Util.ToTLTime(dt), br.symbol, br.Interval,br.CustomInterval,br.ID);
                                if (VerboseDebugging)
                                    debug("hist got bar: " + b);

                            }
                        }
                        
                    }
                    catch (Exception ex)
                    {
                        v("hist ohlc parse err: " + ex.Message + ex.StackTrace + " data: " + rec);
                        b = new BarImpl();
                    }
                    // send it
                    if (b.isValid)
                    {
                        var barserial = BarImpl.Serialize(b);
                        if (VerboseDebugging)
                            debug("hist sending response to: "+br.ID+" int: "+ b.Interval + " bar: " + b.ToString() + " to: " + br.Client + " using data: " + rec);
                        try
                        {
                            tl.TLSend(barserial, MessageTypes.BARRESPONSE, br.Client);
                            if (VerboseDebugging)
                                debug("hist sent " + b.Symbol + " bar in response to: " + br.ID);
                        }
                        catch (Exception ex)
                        {
                            debug("hist send error: " + ex.Message + ex.StackTrace + " on: " + barserial + " to: " + br.Client);
                        }
                    }
                    
                }
                if (!lastrecordprocessed)
                {
                    string lastrecord = records[lastrecordidx];
                    var endidx = lastrecord.IndexOf(HISTEND);
                    if (endidx >= 0)
                    {
                        lastrecord = lastrecord.Substring(endidx, HISTEND.Length);
                        v("hist got " + HISTEND);
                    }
                    if (!string.IsNullOrWhiteSpace(lastrecord))
                    {
                        _histbuff = lastrecord;
                        v("hist saving: " + _histbuff + " for more data.");
                    }
                }
                // wait for more historical data
                WaitForData(HISTSOCKET);
            }
            catch (SocketException)
            {
                v("hist connection closed.");
            }
            catch (Exception ex)
            {
                debug(ex.Message + ex.StackTrace);
            }
        }