Esempio n. 1
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 { }
            }
        }
Esempio n. 2
0
        private void m_Session_OnHistMessage(object sender, BWHistResponse histMsg)
        {
            if (histMsg.Error.Length > 0)
            {
                debug("ERROR: " + histMsg.Error);
            }
            else
            {
                v(histMsg.Symbol + " received bar history data containing " + histMsg.bars.Length + " bars.");
                if (histMsg.bars != null && histMsg.bars.Length > 0)
                {
                    string sym = histMsg.Symbol;

                    foreach (BWBar bar in histMsg.bars)
                    {
                        int tlDate = TradeLink.Common.Util.ToTLDate(bar.time);
                        int tlTime = TradeLink.Common.Util.ToTLTime(bar.time);
                        Bar tlBar  = new BarImpl((decimal)bar.open, (decimal)bar.high, (decimal)bar.low, (decimal)bar.close, (int)bar.volume, tlDate, tlTime, sym, (int)histMsg.Interval);
                        for (int i = 0; i < tl.NumClients; i++)
                        {
                            tl.TLSend(BarImpl.Serialize(tlBar), MessageTypes.BARRESPONSE, i.ToString());
                        }
                    }
                }
                //else if (histMsg.ticks != null && histMsg.ticks.Length > 0)
                //{
                //    foreach (BWTickData tick in histMsg.ticks)
                //    {
                //        Tick tlTick = new TickImpl(tick.symbol);
                //        tlTick.ask = (decimal)tick.askprice;
                //        tlTick.AskSize = (int)tick.asksize;
                //        tlTick.bid = (decimal)tick.bidprice;
                //        tlTick.BidSize = (int)tick.bidsize;
                //        tlTick.trade = (decimal)tick.price;
                //        tlTick.size = (int)tick.size;
                //    }
                //}
            }
        }
Esempio n. 3
0
 void OnReceiveHist(IAsyncResult result)
 {
     try
     {
         int      bytesReceived = m_hist.EndReceive(result);
         string   recvdata      = Encoding.ASCII.GetString(m_buffhist, 0, bytesReceived);
         string   rawData       = _histbuff == string.Empty ? recvdata : _histbuff + recvdata;
         string[] bars          = rawData.Split(Environment.NewLine.ToCharArray());
         foreach (string bar in bars)
         {
             string[] r = bar.Split(',');
             // this should get hit on ENDMSG
             if (r.Length < 8)
             {
                 continue;
             }
             // get request id
             long rid = 0;
             if (!long.TryParse(r[0], out rid))
             {
                 continue;
             }
             BarRequest br;
             if (!reqid2req.TryGetValue(rid, out br))
             {
                 continue;
             }
             bool errorfree = true;
             Bar  b         = new BarImpl();
             try
             {
                 DateTime dt = DateTime.Parse(r[1]);
                 decimal  h  = Convert.ToDecimal(r[2]);
                 decimal  l  = Convert.ToDecimal(r[3]);
                 decimal  o  = Convert.ToDecimal(r[4]);
                 decimal  c  = Convert.ToDecimal(r[5]);
                 long     v  = Convert.ToInt64(r[7]);
                 // build bar
                 b = new BarImpl(o, h, l, c, v, Util.ToTLDate(dt), Util.ToTLTime(dt), br.Symbol, br.Interval);
             }
             catch { errorfree = false; }
             // send it
             if (errorfree)
             {
                 tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client);
             }
         }
         string lastrecord = bars[bars.Length - 1];
         if (lastrecord.Contains(HISTEND))
         {
             _histbuff = string.Empty;
         }
         else
         {
             _histbuff = lastrecord;
         }
         // wait for more historical data
         WaitForData(HISTSOCKET);
     }
     catch (Exception ex)
     {
         debug(ex.Message + ex.StackTrace);
     }
 }
Esempio n. 4
0
        void doquote(ref structSTIQuoteUpdate q)
        {
            Tick k = new TickImpl(q.bstrSymbol);

            k.bid = (decimal)q.fBidPrice;
            k.ask = (decimal)q.fAskPrice;
            k.bs  = q.nBidSize / 100;
            k.os  = q.nAskSize / 100;
            k.ex  = GetExPretty(q.bstrExch);
            k.be  = GetExPretty(q.bstrBidExch);
            k.oe  = GetExPretty(q.bstrAskExch);
            int now = Convert.ToInt32(q.bstrUpdateTime);

            k.date = Util.ToTLDate(DateTime.Now);
            //int sec = now % 100;
            k.time = now;

            // we don't want to simply return on out-of-order ticks because it'll prevent processing
            // of the mdx messages further in this function.
            if (!IgnoreOutOfOrderTicks || (k.time > _lasttime))
            {
                _lasttime = k.time;
                k.trade   = (decimal)q.fLastPrice;
                k.size    = q.nLastSize;
                // execute orders if papertrade is enabled
                if (isPaperTradeEnabled)
                {
                    ptt.newTick(k);
                }
                // notify clients of tick
                if (!_imbalance || (_imbalance && k.isValid))
                {
                    tl.newTick(k);
                }
            }

            /////////////////////////
            // MDX Processing
            /////////////////////////
            if (q.nMdxMsgType == 1)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Regulatory Imbalance for: " + q.bstrSymbol
                          + "  ValidIntradayMarketImb: " + q.bValidIntradayMktImb
                          + "  ValidMktImb: " + q.bValidMktImb
                          + "  Imbalance: " + q.nImbalance
                          + "  iMktImbalance: " + q.nIntradayMktImbalance
                          + "  MktImbalance: " + q.nMktImbalance);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Imbalance imb = new ImbalanceImpl(q.bstrSymbol, GetExPretty(q.bstrExch), q.nIntradayMktImbalance, time, 0, 0, 0);
                    tl.newImbalance(imb);
                }
            }
            else if (q.nMdxMsgType == 2)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Informational Imbalance for: " + q.bstrSymbol
                          + "  ValidIntradayMarketImb: " + q.bValidIntradayMktImb
                          + "  ValidMktImb: " + q.bValidMktImb
                          + "  Imbalance: " + q.nImbalance
                          + "  iMktImbalance: " + q.nIntradayMktImbalance
                          + "  MktImbalance: " + q.nMktImbalance);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Imbalance imb = new ImbalanceImpl(q.bstrSymbol, GetExPretty(q.bstrExch), 0, time, 0, 0, q.nIntradayMktImbalance);
                    tl.newImbalance(imb);
                }
            }
            else if (q.nMdxMsgType == 3)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Halt/Delay for: " + q.bstrSymbol
                          + "  Status: " + q.bstrHaltResumeStatus
                          + "  Reason: " + q.bstrHaltResumeReason);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    HaltResume h = new HaltResumeImpl(q.bstrSymbol, GetExPretty(q.bstrExch), time, q.bstrHaltResumeStatus, q.bstrHaltResumeReason);
                    for (int clientNumber = 0; clientNumber < tl.NumClients; clientNumber++)
                    {
                        tl.TLSend(HaltResumeImpl.Serialize(h), MessageTypes.HALTRESUME, clientNumber);
                    }
                }
            }
            else if (q.nMdxMsgType == 4)
            {
                if (VerboseDebugging)
                {
                    debug(q.bstrUpdateTime
                          + "  Received Indication for: " + q.bstrSymbol
                          + "  ValidIndicators: " + q.bValidIndicators
                          + "  IndicatorHigh: " + q.fIndicatorHigh
                          + "  IndicatorLow: " + q.fIndicatorLow);
                }

                int time;
                if (int.TryParse(q.bstrUpdateTime, out time))
                {
                    Indication ind = new IndicationImpl(q.bstrSymbol, GetExPretty(q.bstrExch), time, q.bValidIndicators, (decimal)q.fIndicatorHigh, (decimal)q.fIndicatorLow);
                    for (int clientNumber = 0; clientNumber < tl.NumClients; clientNumber++)
                    {
                        tl.TLSend(IndicationImpl.Serialize(ind), MessageTypes.INDICATION, clientNumber);
                    }
                }
            }
        }