예제 #1
0
        void rs_LevelOneStreaming_TickWithArgs(DateTime time, AmeritradeBrokerAPI.ATradeArgument args)
        {
            if (args.FunctionType != AmeritradeBrokerAPI.RequestState.AsyncType.LevelOneStreaming)
            {
                return;
            }
            Tick t = new TickImpl();

            /*  don't understand the time format provided here
             * int date = 0;
             * int ttime = 0;
             * if (int.TryParse(args.oLevelOneData[0].quotedate, out date))
             *  t.date = date;
             * if (int.TryParse(args.oLevelOneData[0].quotetime, out ttime))
             *  t.time = ttime;
             */
            t.date   = Util.ToTLDate(DateTime.Now);
            t.time   = Util.DT2FT(DateTime.Now);
            t.symbol = args.oLevelOneData[0].stock;
            t.bid    = Convert.ToDecimal(args.oLevelOneData[0].bid);
            t.ask    = Convert.ToDecimal(args.oLevelOneData[0].ask);
            t.ex     = args.oLevelOneData[0].exchange;
            t.trade  = Convert.ToDecimal(args.oLevelOneData[0].last);
            t.size   = Convert.ToInt32(args.oLevelOneData[0].lastsize) * 100;
            t.bs     = Convert.ToInt32(args.oLevelOneData[0].bid_size);
            t.os     = Convert.ToInt32(args.oLevelOneData[0].ask_size);
            tl.newTick(t);
        }
예제 #2
0
 void esig_OnQuoteChanged(string sSymbol)
 {
     try
     {
         // get tick info
         BasicQuote q = esig.get_GetBasicQuote(sSymbol);
         // get our struct
         Tick k = new TickImpl(sSymbol);
         // convert it
         k.ask   = (decimal)q.dAsk;
         k.bid   = (decimal)q.dBid;
         k.trade = (decimal)q.dLast;
         k.bs    = q.lBidSize;
         k.os    = q.lAskSize;
         k.size  = q.lLastSize;
         DateTime now = esig.GetAppTime;
         k.time = Util.ToTLTime(now);
         k.date = Util.ToTLDate(now);
         if (isPaperTradeEnabled)
         {
             ptt.newTick(k);
         }
         // send it
         tl.newTick(k);
     }
     catch (Exception ex)
     {
         if (GotDebug != null)
         {
             GotDebug(DebugImpl.Create(ex.Message + ex.StackTrace, DebugLevel.Debug));
         }
     }
 }
예제 #3
0
        private void api_LevelOneStreaming(object sender, Axtdaactx.ITDAAPICommEvents_OnL1QuoteEvent e)
        {
            DateTime DT = new DateTime(1970, 1, 1);
            //Axtdaactx.AxTDAL1Quote quote = (Axtdaactx.AxTDAL1Quote)e.quote;

            Tick t = new TickImpl();

            t.date   = Util.ToTLDate(DateTime.Now);
            t.time   = Util.DT2FT(DateTime.Now);
            t.symbol = e.quote.Symbol;
            t.bid    = Convert.ToDecimal(e.quote.Bid);
            t.ask    = Convert.ToDecimal(e.quote.Ask);
            t.ex     = e.quote.Exchange.ToString();
            t.trade  = Convert.ToDecimal(e.quote.Last);
            t.size   = !isidx(e.quote.Symbol) ? Convert.ToInt32(e.quote.LastSize) * 100 : -1;
            t.bs     = Convert.ToInt32(e.quote.BidSize);
            t.os     = Convert.ToInt32(e.quote.AskSize);
            tl.newTick(t);
        }
예제 #4
0
        void SimBroker_GotOrderCancel(string sym, bool side, long id)
        {
            // if we get an order cancel notify from the broker, pass along to our clients
            tl.newCancel(id);
            // send the updated book to our clients for same side as order
            Tick book = OrderToTick(SimBroker.BestBidOrOffer(sym, side));

            tl.newTick(book);
        }
예제 #5
0
        void InsideMktEvent_GBEvent(object pISrc, string bstrSymbol, string bstrHint, object pIEventData)
        {
            GBInsideMkt insideMkt = new GBInsideMktClass();

            insideMkt = (GBInsideMkt)pIEventData;



            Tick k = new TickImpl(bstrSymbol);

            k.bid  = (decimal)insideMkt.BidPrice;
            k.ask  = (decimal)insideMkt.AskPrice;
            k.bs   = insideMkt.BidVolume / 100;
            k.os   = insideMkt.AskVolume / 100;
            k.date = Util.ToTLDate(DateTime.Now);
            k.time = Util.ToTLTime(DateTime.Now);

            tl.newTick(k);
        }
예제 #6
0
        /*
         * private void ExecuteNotifyHandler(object sender, OrderArgs e)
         * {
         *
         *
         *  itemOrder iorder = e.ItemOrder;
         *
         *
         *
         *
         *  Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "", iorder.mc_date, iorder.mc_date, iorder.morderid);
         *  Trade trade = new TradeImpl();
         *  trade.symbol = iorder.msecsym;
         *  trade.side = iorder.IsBuyOrder();
         *  trade.xprice = Convert.ToDecimal(iorder.mprice);
         *  trade.xsize = iorder.mqty;
         *  DateTime mdate = ComFucs.GetDate(iorder.mm_date);
         *
         *  trade.xdate = mdate.Day+ mdate.Month*100+mdate.Year*10000;
         *  trade.xtime = mdate.Second + mdate.Minute*100+ mdate.Hour*10000 ;
         *  tl.newFill(trade);
         * }
         *
         *
         *
         * private void OrderHandler(object sender, OrderArgs e)
         * {
         *
         *
         *      itemOrder iorder = e.ItemOrder;
         *      // if (!ls.Contains(iorder.morigtkn)) return;
         *      DateTime mdate = ComFucs.GetDate(iorder.mm_date);
         *      Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "",
         *                  mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000, mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000, iorder.morderid);
         *
         *      tl.newOrder(o);
         *
         *
         *
         * }
         *
         *
         * private void OrderModifyHandler(object sender, OrderArgs e)
         * {
         *
         *      if ((e.ItemOrder.mstatus | 0x0004) != 0)
         *      {
         *        //  tl.newCancel(e.ItemOrder.morderid);
         *      }
         *      if ((e.ItemOrder.mstatus | 0x0002) != 0)
         *      {
         *          itemOrder iorder = e.ItemOrder;
         *          Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "", iorder.mc_date, iorder.mc_date, iorder.morderid);
         *          Trade trade = new TradeImpl();
         *          trade.symbol = iorder.msecsym;
         *          trade.side = iorder.IsBuyOrder();
         *          trade.xprice = Convert.ToDecimal(iorder.mprice);
         *          trade.xsize = iorder.mqty;
         *          DateTime mdate = ComFucs.GetDate(iorder.mm_date);
         *          trade.xdate = mdate.Day + mdate.Month * 100 + mdate.Year * 10000;
         *          trade.xtime = mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000;
         *          tl.newFill(trade);
         *      }
         *
         *
         *
         * }
         * */


        private void Lv1Handler(object sender, Lv1Args e)
        {
            DateTime DT = new DateTime(1970, 1, 1);

            Tick t = new TickImpl();

            t.date   = Util.ToTLDate(DateTime.Now);
            t.time   = Util.DT2FT(DateTime.Now);
            t.symbol = e.TheIssuIfo.secsym;
            t.bid    = Convert.ToDecimal(e.TheIssuIfo.l1_BidPrice);
            t.ask    = Convert.ToDecimal(e.TheIssuIfo.l1_AskPrice);
            t.ex     = e.TheIssuIfo.PrimExch.ToString();
            t.trade  = Convert.ToDecimal(e.TheIssuIfo.l1_lastPrice);
            t.size   = e.TheIssuIfo.l1_volume;
            t.bs     = e.TheIssuIfo.l1_BidSize;
            t.os     = e.TheIssuIfo.l1_AskSize;
            t.ex     = e.TheIssuIfo.PrimExch.ToString();

            tl.newTick(t);
        }
예제 #7
0
        static unsafe void OnNxCoreTrade(NxCoreSystem *pNxCoreSys, NxCoreMessage *pNxCoreMsg)
        {
            if (keepcurrent && (STATUS < 4))
            {
                return;
            }
            if (DOLIVESKIPTEST)
            {
                if (pNxCoreSys->nxTime.MsOfDay < (DateTime.UtcNow.TimeOfDay.TotalMilliseconds - (DateTime.Now.IsDaylightSavingTime() ? (1000 * 60 * 60 * 4) : (1000 * 60 * 60 * 5))))
                {
                    return;
                }
                DOLIVESKIPTEST = false;
                D("NxCore starting realtime data");
            }
            // Get the symbol for category message

            int idx = _nxsyms.getindex(new string(&pNxCoreMsg->coreHeader.pnxStringSymbol->String));

            if (idx < 0)
            {
                return;
            }
            if (!_nxsyms[idx])
            {
                return;
            }
            // Assign a pointer to the Trade data
            NxCoreTrade *Trade = &pNxCoreMsg->coreData.Trade;
            // Get the price and net change
            double Price = NxCore.PriceToDouble(Trade->Price, Trade->PriceType);
            //double NetChange = NxCore.PriceToDouble(Trade->NetChange, Trade->PriceType);
            NxTime time   = pNxCoreMsg->coreHeader.nxExgTimestamp;
            int    tltime = time.Hour * 10000 + time.Minute * 100 + time.Second;
            NxDate date   = pNxCoreMsg->coreHeader.nxSessionDate;
            int    tldate = (int)date.Year * 10000 + (int)date.Month * 100 + (int)date.Day;
            string ex     = excode2name(pNxCoreMsg->coreHeader.ReportingExg);
            int    size   = (int)Trade->Size;

            // check for index
            if (size <= 0)
            {
                return;
            }
            Tick k = new TickImpl();

            k.symbol = _realsym2nxidx.getlabel(idx);
            k.date   = tldate;
            k.time   = tltime;
            k.trade  = (decimal)Price;
            k.ex     = ex;
            k.size   = size;
            try
            {
                tl.newTick(k);
            }
            catch (Exception e)
            {
                D("bad tick: " + k.symbol + " " + Price + " " + size + " " + ex + " " + e.Message + e.StackTrace);
            }
        }
예제 #8
0
        private void FireTick(string[] actualData)
        {
            if (actualData.Length < 66)
            {
                return;
            }
            try
            {
                if (actualData[0] == "F")
                {
                    return;
                }

                Tick tick = new TickImpl();
                tick.date = Util.ToTLDate();
                DateTime now;
                if (DateTime.TryParse(actualData[65], out now))
                {
                    tick.time = Util.DT2FT(now);
                }
                else
                {
                    tick.time = Util.ToTLTime();
                }
                int v = 0;
                if (int.TryParse(actualData[64], out v))
                {
                    tick.oe = getmarket(v);
                }
                if (int.TryParse(actualData[63], out v))
                {
                    tick.be = getmarket(v);
                }
                if (int.TryParse(actualData[62], out v))
                {
                    tick.ex = getmarket(v);
                }
                tick.symbol  = actualData[1];
                tick.bid     = Convert.ToDecimal(actualData[10]);
                tick.ask     = Convert.ToDecimal(actualData[11]);
                tick.trade   = Convert.ToDecimal(actualData[3]);
                tick.size    = Convert.ToInt32(actualData[7]);
                tick.BidSize = Convert.ToInt32(actualData[12]);
                tick.AskSize = Convert.ToInt32(actualData[13]);
                // get symbol index for custom data requests
                int idx = _highs.getindex(tick.symbol);
                // update custom data (tryparse is faster than convert)
                decimal d = 0;
                if (decimal.TryParse(actualData[8], out d))
                {
                    _highs[idx] = d;
                }
                if (decimal.TryParse(actualData[9], out d))
                {
                    _lows[idx] = d;
                }
                if (isPaperTradeEnabled)
                {
                    tl.newTick(tick);
                }
                tl.newTick(tick);
            }
            catch (Exception ex)
            {
                debug("Tick error: " + string.Join(",", actualData));
                debug(ex.Message + ex.StackTrace);
            }
        }
예제 #9
0
        public void FireTick(string[] actualData)
        {
            if (actualData.Length < 66)
            {
                return;
            }
            try
            {
                if (actualData[0] == "F")
                {
                    return;
                }

                Tick tick = new TickImpl();
                tick.date = Util.ToTLDate();
                DateTime now;
                int      local = Util.ToTLTime();
                if (DateTime.TryParse(actualData[65], out now))
                {
                    tick.time = Util.DT2FT(now);

                    if (ReportLatency)
                    {
                        Int64 latency = 0;
                        if (lastticktime != 0)
                        {
                            latency = DateTime.Now.Ticks - lastticktime;
                        }
                        lastticktime = now.Ticks;

                        latencyavg = (latency + latencyavg) / 2;
                        tickssincelastlatencyreport++;
                        // test for peak
                        if (latency > peaklatency)
                        {
                            peaklatency = latency;
                        }
                        // test for report
                        if (tickssincelastlatencyreport > 500000)
                        {
                            // convert to ms
                            double latencyms = latencyavg / 10000;
                            double peakms    = peaklatency / 10000;
                            debug(string.Format("latency (ms) avg {0:N1} peak: {0:N1}", latencyms, peaklatency));
                            tickssincelastlatencyreport = 0;
                            latencyavg = 0;
                        }
                    }
                }
                else
                {
                    tick.time = local;
                }
                // see if user has tick ignoring enabled
                //(this is because in early AM iqfeed will frequently send ticks with yesterday time stamps
                if (usebeforeafterignoretime)
                {
                    // ensure that ordering works across multiple days
                    if (lasttickdate != tick.date)
                    {
                        lasttickordertime = 0;
                        lasttickdate      = tick.date;
                    }

                    // see if tick should be ignored
                    if ((local < IfBeforeTimeUseIgnoreAfter) &&
                        (tick.time > IgnoreAfterTimeWithBefore))
                    {
                        return;
                    }
                    // allow ignoring for ignoring other ticks that are out of order
                    else if (ignoreoutoforder && (tick.time < lasttickordertime))
                    {
                        return;
                    }
                    lasttickordertime = tick.time;
                }

                int v = 0;
                if (int.TryParse(actualData[64], out v))
                {
                    tick.oe = getmarket(v);
                }
                if (int.TryParse(actualData[63], out v))
                {
                    tick.be = getmarket(v);
                }
                if (int.TryParse(actualData[62], out v))
                {
                    tick.ex = getmarket(v);
                }
                tick.symbol  = actualData[1];
                tick.bid     = Convert.ToDecimal(actualData[10]);
                tick.ask     = Convert.ToDecimal(actualData[11]);
                tick.trade   = Convert.ToDecimal(actualData[3]);
                tick.size    = Convert.ToInt32(actualData[7]);
                tick.BidSize = Convert.ToInt32(actualData[12]);
                tick.AskSize = Convert.ToInt32(actualData[13]);
                // get symbol index for custom data requests
                int idx = _highs.getindex(tick.symbol);
                // update custom data (tryparse is faster than convert)
                decimal d = 0;
                if (decimal.TryParse(actualData[8], out d))
                {
                    _highs[idx] = d;
                }
                if (decimal.TryParse(actualData[9], out d))
                {
                    _lows[idx] = d;
                }
                if (isPaperTradeEnabled)
                {
                    ptt.newTick(tick);
                }
                tl.newTick(tick);
            }
            catch (Exception ex)
            {
                debug("Tick error: " + string.Join(",", actualData));
                debug(ex.Message + ex.StackTrace);
            }
        }
예제 #10
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);
                    }
                }
            }
        }