Ejemplo n.º 1
0
        private void OrderNotifyHandler(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);
            v(o.symbol + " received order ack for: " + o.ToString());
        }
Ejemplo n.º 2
0
        void bwOrder_BWOrderUpdateEvent(object sender, BWOrderStatus BWOrderStatus)
        {
            BWOrder bwo = (BWOrder)sender;
            long    id  = (long)bwo.CustomID;
            Order   o   = new OrderImpl(bwo.Symbol, (int)bwo.Size);

            o.id      = (long)bwo.CustomID;
            o.side    = (bwo.OrderSide == ORDER_SIDE.SIDE_BUY) || (bwo.OrderSide == ORDER_SIDE.SIDE_COVER);
            o.price   = (decimal)bwo.LimitPrice;
            o.stopp   = (decimal)bwo.StopPrice;
            o.Account = bwo.UserID.ToString();
            o.ex      = bwo.Venue.ToString();

            switch (BWOrderStatus)
            {
            case BWOrderStatus.ACCEPTED:
            {
                tl.newOrder(o);
                v(o.symbol + " sent order acknowledgement for: " + o.ToString());
                if (_bwOrdIds.ContainsKey(o.id))
                {
                    _bwOrdIds[o.id] = bwo.OrderID;
                }
            }
            break;

            case BWOrderStatus.CANCELED:
            {
                tl.newCancel(id);
                v("sent cancel notification for order: " + id);
            }
            break;

            case BWOrderStatus.REJECTED:
            {
                tl.newCancel(id);
                debug("Rejected: " + bwo.CustomID.ToString() + bwo.RejectReason);
            }
            break;
            }
        }
Ejemplo n.º 3
0
        void MessageCache_CacheEvent(int action, int row)
        {
            switch (action)
            {
            case 1:     //CN_Submit
                break;

            case 4:     //CN_Insert
            {
                try
                {
                    int    i   = row;
                    int    err = 0;
                    object cv  = null;
                    string orderReferenceNumber = String.Empty;
                    Order  o = new OrderImpl();
                    _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err);
                    if (!(cv == null))
                    {
                        o.symbol = cv.ToString();
                    }
                    _messageCache.VBGetCell(row, "SIDE", ref cv, ref err);
                    if (!(cv == null))
                    {
                        v("order side: " + cv.ToString());
                        if (cv.ToString() == "BUY")
                        {
                            o.side = true;
                        }
                        else if (cv.ToString() == "SELL")
                        {
                            o.side = false;
                        }
                        else if (cv.ToString().Contains("SHORT"))
                        {
                            o.side = false;
                        }
                    }
                    _messageCache.VBGetCell(row, "QUANTITY", ref cv, ref err);
                    if (!(cv == null))
                    {
                        o.size = int.Parse(cv.ToString());
                    }
                    _messageCache.VBGetCell(row, "PRICE", ref cv, ref err);
                    if (!(cv == null))
                    {
                        o.price = decimal.Parse(cv.ToString());
                    }
                    _messageCache.VBGetCell(row, "STOPPRICE", ref cv, ref err);
                    if (!(cv == null))
                    {
                        o.stopp = decimal.Parse(cv.ToString());
                    }
                    _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err);
                    if (!(cv == null))
                    {
                        o.Account = cv.ToString();
                    }
                    _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err);
                    if (!(cv == null))
                    {
                        orderReferenceNumber = cv.ToString();
                    }
                    _messageCache.VBGetCell(row, "Status", ref cv, ref err);
                    if (!(cv == null))
                    {
                        if (cv.ToString() == "Open")
                        {
                            o.id = row;
                            long now  = Util.ToTLDate(DateTime.Now);
                            int  xsec = (int)(now % 100);
                            long rem  = (now - xsec) / 100;
                            o.time = ((int)(rem % 10000)) * 100 + xsec;
                            o.date = (int)((rem - o.time) / 10000);
                            o.size = o.side ? o.UnsignedSize : o.UnsignedSize * -1;
                            OrderIdDict.Add(orderReferenceNumber, (long)row);
                            if (_onotified.Contains((int)row))
                            {
                                return;
                            }
                            _onotified.Add(o.id);
                            tl.newOrder(o);
                            v("order ack received and sent: " + o.ToString());
                        }
                        else if (cv.ToString() == "Canceled")
                        {
                            long id = OrderIdDict[orderReferenceNumber];
                            tl.newCancel(id);
                            v("order cancel ack received and sent: " + id);
                        }
                        else if (cv.ToString() == "Complete")
                        {
                            Trade f = new TradeImpl();
                            _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err);
                            if (!(cv == null))
                            {
                                f.symbol = cv.ToString();
                            }
                            _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err);
                            if (!(cv == null))
                            {
                                f.Account = cv.ToString();
                            }
                            _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err);
                            if (!(cv == null))
                            {
                                long id = 0;
                                if (OrderIdDict.TryGetValue(cv.ToString(), out id))
                                {
                                    f.id = id;
                                }
                                else
                                {
                                    f.id = _idt.AssignId;
                                }
                                f.id = id;
                            }
                            _messageCache.VBGetCell(row, "EXECQUANTITY", ref cv, ref err);
                            if (!(cv == null))
                            {
                                f.xsize = int.Parse(cv.ToString());
                            }
                            _messageCache.VBGetCell(row, "EXECPRICE", ref cv, ref err);
                            if (cv != null)
                            {
                                f.xprice = decimal.Parse(cv.ToString());
                            }
                            else
                            {
                                v(f.symbol + " error getting EXECPRICE, err: " + err + " retrying...");
                                _messageCache.VBGetCell(row, "EXECPRICE", ref cv, ref err);
                                if (cv != null)
                                {
                                    f.xprice = decimal.Parse(cv.ToString());
                                }
                                else
                                {
                                    v(f.symbol + " error getting EXECPRICE, err: " + err + " retrying new method...");
                                    _messageCache.VBGetCell(row, "EXECVALUE", ref cv, ref err);
                                    bool    ok    = false;
                                    decimal val   = 0;
                                    int     usize = Math.Abs(f.xsize);
                                    if (cv != null)
                                    {
                                        if (decimal.TryParse(cv.ToString(), out val))
                                        {
                                            if ((val != 0) && (usize != 0))
                                            {
                                                ok       = true;
                                                f.xprice = val / usize;
                                            }
                                            else
                                            {
                                            }
                                        }
                                    }
                                    if (!ok)
                                    {
                                        v(f.symbol + " error inferring EXECPRICE, usize: " + usize + " execval: " + val);
                                    }
                                }
                            }


                            _messageCache.VBGetCell(row, "EXCHANGE", ref cv, ref err);
                            if (!(cv == null))
                            {
                                f.ex = cv.ToString();
                            }
                            else
                            {
                                _messageCache.VBGetCell(row, "EXECSIDE", ref cv, ref err);
                            }
                            if (!(cv == null))
                            {
                                if (cv.ToString().Contains("BUY"))
                                {
                                    f.side = true;
                                }
                                else if (cv.ToString().Contains("SELL") ||
                                         cv.ToString().Contains("SHORT"))
                                {
                                    f.side = false;
                                }
                                else
                                {
                                    v("invalid fill side: " + cv.ToString());
                                }
                            }
                            f.xtime = Util.ToTLDate();
                            f.xdate = Util.ToTLTime();
                            Object objErr = null;
                            _positionCache.VBRediCache.AddWatch(2, string.Empty, f.Account, ref objErr);
                            if (f.isValid)
                            {
                                pt.Adjust(f);
                                tl.newFill(f);
                                v("fill ack received and sent: " + f.ToString());
                            }
                            else
                            {
                                debug("ignoring invalid fill: " + f.ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    debug(ex.Message + ex.StackTrace);
                }
            }
            break;

            case 5:     //CN_Update
            {
                try
                {
                    int    i           = row;
                    int    err         = 0;
                    object cv          = null;
                    string orderStatus = null;
                    _messageCache.VBGetCell(row, "Status", ref cv, ref err);
                    if (!(cv == null))
                    {
                        orderStatus = cv.ToString();
                    }
                    if (orderStatus == "Complete")
                    {
                        Trade f = new TradeImpl();
                        _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err);
                        if (!(cv == null))
                        {
                            f.symbol = cv.ToString();
                        }
                        _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err);
                        if (!(cv == null))
                        {
                            f.Account = cv.ToString();
                        }
                        _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err);
                        if (!(cv == null))
                        {
                            long id = 0;
                            if (OrderIdDict.TryGetValue(cv.ToString(), out id))
                            {
                                f.id = id;
                            }
                            else
                            {
                                f.id = _idt.AssignId;
                            }
                            f.id = id;
                        }
                        _messageCache.VBGetCell(row, "EXECPRICE", ref cv, ref err);
                        if (!(cv == null))
                        {
                            f.xprice = decimal.Parse(cv.ToString());
                        }
                        _messageCache.VBGetCell(row, "EXECQUANTITY", ref cv, ref err);
                        if (!(cv == null))
                        {
                            f.xsize = int.Parse(cv.ToString());
                        }
                        _messageCache.VBGetCell(row, "EXCHANGE", ref cv, ref err);
                        if (!(cv == null))
                        {
                            f.ex = cv.ToString();
                        }
                        _messageCache.VBGetCell(row, "SIDE", ref cv, ref err);
                        if (!(cv == null))
                        {
                            if (cv.ToString() == "BUY")
                            {
                                f.side = true;
                            }
                            else if (cv.ToString() == "SELL")
                            {
                                f.side = false;
                            }
                        }
                        long now  = Util.ToTLDate(DateTime.Now);
                        int  xsec = (int)(now % 100);
                        long rem  = (now - xsec) / 100;
                        f.xtime = ((int)(rem % 10000)) * 100 + xsec;
                        f.xdate = (int)((now - f.xtime) / 1000000);
                        Object objErr = null;
                        _positionCache.VBRediCache.AddWatch(2, string.Empty, f.Account, ref objErr);
                        if (f.isValid)
                        {
                            pt.Adjust(f);
                            tl.newFill(f);
                            v("fill ack received and sent: " + f.ToString());
                        }
                        else
                        {
                            debug("ignoring invalid fill: " + f.ToString());
                        }
                    }
                    if (orderStatus == "Partial")
                    {
                    }
                }
                catch (Exception exc)
                {
                    debug(exc.Message);
                }
            }
            break;

            case 8:     //CN_Remove
                break;
            }
        }
Ejemplo n.º 4
0
        void doorderupdate(ref structSTIOrderUpdate structOrderUpdate)
        {
            Order o = new OrderImpl();

            o.symbol = structOrderUpdate.bstrSymbol;
            long id = 0;

            // see if the order id is unknown
            if (!long.TryParse(structOrderUpdate.bstrClOrderId, out id))
            {
                // use the norderrecordid as our order id
                id = (long)structOrderUpdate.nOrderRecordId;

                // ensure this is not a secondary notification of same order
                string tmp;
                if (!idacct.TryGetValue(id, out tmp))
                {
                    // save the id
                    debug("manual order: " + id + " " + structOrderUpdate.bstrAccount);
                    idacct.Add(id, structOrderUpdate.bstrAccount);
                    ismanorder.Add(id, true);
                }
            }
            // if this is a cancel notification, pass along
            if (structOrderUpdate.nOrderStatus == (int)STIOrderStatus.osSTICanceled)
            {
                // if it's a cancel, we'll have cancel id rather than order id
                // get new id
                long orderid = 0;
                if (_cancel2order.TryGetValue(id, out orderid))
                {
                    tl.newCancel(orderid);
                    if (VerboseDebugging)
                    {
                        debug("cancel received for: " + orderid);
                    }
                }
                else
                {
                    debug("manual cancel sent with id: " + id);
                }
                return;
            }
            // don't notify for same order more than once
            if (_onotified.Contains(id))
            {
                return;
            }
            if (structOrderUpdate.bstrLogMessage.Contains("REJ"))
            {
                debug(id + " " + structOrderUpdate.bstrLogMessage);
            }
            o.id      = id;
            o.size    = structOrderUpdate.nQuantity;
            o.side    = structOrderUpdate.bstrSide == "B";
            o.price   = (decimal)structOrderUpdate.fLmtPrice;
            o.stopp   = (decimal)structOrderUpdate.fStpPrice;
            o.TIF     = structOrderUpdate.bstrTif;
            o.Account = structOrderUpdate.bstrAccount;
            o.ex      = structOrderUpdate.bstrDestination;
            long now  = Convert.ToInt64(structOrderUpdate.bstrUpdateTime);
            int  xsec = (int)(now % 100);
            long rem  = (now - xsec) / 100;

            o.time = ((int)(rem % 10000)) * 100 + xsec;
            o.date = (int)((rem - o.time) / 10000);
            _onotified.Add(o.id);
            if (VerboseDebugging)
            {
                debug("order acknowledgement: " + o.ToString());
            }
            tl.newOrder(o);
        }