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);
        }
Ejemplo n.º 2
0
        void BlackBox_GrayBoxOrderConfirmEventMy(object ob, GrayBoxAPI.BBEventArgs e)
        {
            UpdateOrderStatus(e);
            Order o = new OrderImpl();

            OrderList.TryGetValue(e.BBXid, out o);
            tl.newOrder(o);
            string orderside = o.side ? "BUY" : "SELL";

            debug("Order confirmed " + o.id + " " + o.symbol + " " + orderside + " " + o.size);
        }
Ejemplo n.º 3
0
        long ServerDBFX_newSendOrderRequest(Order o)
        {
            if ((o.id != 0) && !isunique(o))
            {
                return((long)MessageTypes.DUPLICATE_ORDERID);
            }
            if (o.id == 0)
            {
                o.id = _id.AssignId;
            }
            object psOrderId;
            object psDI;
            string acct = _acct[0];

            _tradeDesk.CreateEntryOrder(acct, o.symbol, o.side, o.size, (double)o.price, (double)o.stopp, (double)o.price, 0, out psOrderId, out psDI);
            _tl2dbfx.Add(o.id, psOrderId.ToString());
            tl.newOrder(o);
            //D(psOrderId.ToString());
            return((long)MessageTypes.OK);
        }
Ejemplo n.º 4
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.º 5
0
 void SimBroker_GotOrder(Order o)
 {
     tl.newOrder(o);
 }
Ejemplo n.º 6
0
        long tl_gotSrvFillRequest(Order o)
        {
            if (!ok)
            {
                debug("not logged in.");
                return((long)MessageTypes.SYMBOL_NOT_LOADED);
            }

            string action = o.side ? "buy" : "sell";
            string otype  = o.isLimit ? "limit" : "market";

            if (o.id == 0)
            {
                o.id = OrderImpl.Unique;
            }
            string route = "auto";

            if (o.ex.ToUpper().Contains("ARCA"))
            {
                route = "ecn_arca";
            }
            else if (o.ex.ToUpper().Contains("INET"))
            {
                route = "inet";
            }

            AmeritradeBrokerAPI.ATradeArgument brokerReplyargs = new AmeritradeBrokerAPI.ATradeArgument();
            string        cResultMessage  = string.Empty;
            string        cEnteredOrderID = string.Empty;
            StringBuilder cOrderString    = new StringBuilder();

            cOrderString.Append("action=" + api.Encode_URL(action));
            cOrderString.Append("~clientorderid=" + api.Encode_URL(o.id.ToString()));
            cOrderString.Append("~accountid=" + api.Encode_URL(api._accountid));
            cOrderString.Append("~actprice=" + api.Encode_URL(string.Empty));
            cOrderString.Append("~expire=" + api.Encode_URL(o.TIF));
            cOrderString.Append("~ordtype=" + api.Encode_URL(otype));
            cOrderString.Append("~price=" + api.Encode_URL(o.price.ToString()));
            cOrderString.Append("~quantity=" + api.Encode_URL(o.size.ToString()));
            cOrderString.Append("~spinstructions=" + api.Encode_URL("none"));
            cOrderString.Append("~symbol=" + api.Encode_URL(o.symbol));
            cOrderString.Append("~routing=" + api.Encode_URL(route));

            cOrderString.Append("~tsparam=" + api.Encode_URL(string.Empty));
            cOrderString.Append("~exmonth=" + api.Encode_URL(string.Empty));
            cOrderString.Append("~exday=" + api.Encode_URL(string.Empty));
            cOrderString.Append("~exyear=" + api.Encode_URL(string.Empty));
            cOrderString.Append("~displaysize=" + api.Encode_URL(string.Empty));
            brokerReplyargs.ResultsCode =
                api.TD_sendOrder(_user.Text, _pass.Text, AmeritradeBrokerAPI.SOURCEID, APIVER, cOrderString.ToString(), ref cResultMessage, ref cEnteredOrderID);

            if (brokerReplyargs.ResultsCode != OK)
            {
                debug(cResultMessage);
            }
            else
            {
                long tdid = 0;
                if (long.TryParse(cEnteredOrderID, out tdid))
                {
                    idmap.Add(o.id, tdid);
                }
                tl.newOrder(o);
            }

            return((long)MessageTypes.OK);
        }
Ejemplo n.º 7
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);
        }