Exemplo n.º 1
0
        void stiEvents_OnSTIOrderUpdate(ref structSTIOrderUpdate structOrderUpdate)
        {
            Order o = new OrderImpl();

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

            if (!uint.TryParse(structOrderUpdate.bstrClOrderId, out id))
            {
                id = (uint)structOrderUpdate.nOrderRecordId;
            }
            o.id      = id;
            o.size    = structOrderUpdate.nQuantity;
            o.side    = o.size > 0;
            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);
            tl.newOrder(o);
        }
Exemplo n.º 2
0
        void m_OrderClient_OnSubmit(MbtOpenOrder pOrd)
        {
            OrderImpl o = new OrderImpl(pOrd.Symbol, pOrd.Quantity);

            o.side  = pOrd.BuySell == MBConst.VALUE_BUY;
            o.price = (decimal)pOrd.Price;
            o.stopp = (decimal)pOrd.StopLimit;
            o.TIF   = pOrd.TimeInForce == MBConst.VALUE_DAY ? "DAY" : "GTC";
            o.time  = Util.ToTLTime(pOrd.UTCDateTime);
            o.date  = Util.ToTLDate(pOrd.UTCDateTime);
            o.sec   = pOrd.UTCDateTime.Second;
            o.trail = (decimal)pOrd.TrailingOffset;
            //o.ex = pOrd.Route;
            o.id = Convert.ToUInt32(pOrd.OrderNumber);
            tl.newOrder(o);
        }
Exemplo n.º 3
0
        protected virtual int OnStockSendingOrder(UInt32 hStock, GTSession.GTSending32 pending)
        {
            // get order
            Order o = new OrderImpl(pending.szStock, pending.nEntryShares);

            o.id   = (uint)pending.dwTicketNo;
            o.side = pending.chEntrySide == 'B';
            //o.TIF = pending.nEntryTIF;
            o.Account = pending.szAccountID;
            o.date    = pending.nEntryDate;
            o.time    = pending.nEntryTime;
            // is this limit v stop?
            char type = pending.chPriceIndicator;

            // not sure about these two
            o.price = (decimal)pending.dblEntryPrice;
            o.stopp = (decimal)pending.dblEntryStopLimitPrice;
            // notify clients
            tl.newOrder(o);
            return(0);
        }
Exemplo n.º 4
0
        // event handlers

        long tl_gotSrvFillRequest(Order o)
        {
            s.newOrder(o);
            fillrequest++;
            return(0);
        }
Exemplo n.º 5
0
 void SimBroker_GotOrder(Order o)
 {
     tl.newOrder(o, true);
 }
Exemplo n.º 6
0
        /*
         * [Test]
         * public void PerformanceTests()
         * {
         *  // expected performance
         *  const decimal EXPECT = .10m;
         *  // get ticks for test
         *  const int TICKSENT = 1000;
         *  Tick[] tick = TradeLink.Research.RandomTicks.GenerateSymbol(SYM, TICKSENT);
         *  // subscribe to symbol
         *  c.Unsubscribe();
         *  c.Subscribe(new BasketImpl(SYM));
         *  // reset ticks
         *  int save = ticks;
         *  ticks = 0;
         *  // start clock
         *  DateTime start = DateTime.Now;
         *
         *  // process ticks
         *  for (int i = 0; i < tick.Length; i++)
         *      s.newTick(tick[i]);
         *
         *  // stop clock
         *  double time = DateTime.Now.Subtract(start).TotalSeconds;
         *  // make sure time exists
         *  Assert.Greater(time, 0);
         *  // make sure it's less than expected
         *  Assert.LessOrEqual(time, EXPECT);
         *  // make sure we got all the ticks
         *  Assert.AreEqual(TICKSENT, ticks);
         *  decimal ticksec = TICKSENT/(decimal)time;
         *  Console.WriteLine("protocol performance (tick/sec): " + ticksec.ToString("N0"));
         *
         *  // restore ticks
         *  ticks = save;
         * }*/

        // event handlers

        void tl_gotSrvFillRequest(Order o)
        {
            s.newOrder(o);
            fillrequest++;
        }
Exemplo n.º 7
0
        void tl_gotSrvFillRequest(Order o)
        {
            if (!ok)
            {
                debug("not logged in."); return;
            }

            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);
            }
        }