示例#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);
        }
示例#2
0
        void rightticket(object sender, EventArgs e)
        {
            Security s = GetVisibleSecurity(CurrentRow);

            if (s.Type == SecurityType.IDX)
            {
                return;
            }
            string sym = s.Symbol;

            if ((s.FullName == string.Empty) || (sym == string.Empty))
            {
                return;
            }
            Order o = new OrderImpl(s.FullName, 0);

            o.ex          = s.DestEx;
            o.Security    = s.Type;
            o.LocalSymbol = sym;
            Ticket t = new Ticket(o);

            t.SendOrder += new OrderDelegate(t_neworder);
            spillTick   += new TickDelegate(t.newTick);
            orderStatus += new OrderStatusDel(t.orderStatus);
            System.Drawing.Point p = new System.Drawing.Point(MousePosition.X, MousePosition.Y);
            p.Offset(-315, 20);
            t.SetDesktopLocation(p.X, p.Y);
            t.Show();
        }
示例#3
0
        public void BasicStopAndLimit()
        {
            long id = 1;

            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent  += new DebugDelegate(rt.d);
            sho.VerboseDebugging = true;
            Order o = new OrderImpl();

            // take a position
            o         = new BuyLimit(sym, 100, 21.18m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "entry buy never a short.");
            sho.GotOrder(o);
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 21.14m, 100)), "unable to fill order");
            Trade t = (Trade)o;

            Assert.IsTrue(t.isValid && t.isFilled, "not a valid trade");
            sho.GotFill(t);


            // accept two exits
            o         = new SellStop(sym, 100, 21.09m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "first exit was wrongly a short");
            sho.GotOrder(o);
            o         = new SellLimit(sym, 100, 21.19m, id++);
            o.Account = ACCT;
            Assert.IsTrue(sho.isOrderShort(o), "second exit was wrongly a sell");
            sho.GotOrder(o);
        }
示例#4
0
文件: SimBroker.cs 项目: mpvyard/Core
        /// <summary>
        /// Sends the order to the broker. (uses the default account)
        /// </summary>
        /// <param name="o">The order to be send.</param>
        /// <returns>status code</returns>
        public int SendOrderStatus(PendingOrder o)
        {
            if (!o.Order.IsValid || CheckOrderIntegrity(o) != StatusType.OK)
            {
                o.Cancel();
                return((int)StatusType.INVALID_TRADE_PARAMETERS);
            }

            // make sure book is clearly stamped
            if (o.Order.AccountName.Equals(string.Empty, StringComparison.OrdinalIgnoreCase))
            {
                OrderImpl order = (OrderImpl)o.Order;
                order.AccountName = Default.Id;
                return(SendOrderAccount(o, Default));
            }

            // get account
            SimAccount a;

            if (!Acctlist.TryGetValue(o.Order.AccountName, out a))
            {
                a = new SimAccount(o.Order.AccountName);
                AddAccount(a);
            }
            return(SendOrderAccount(o, a));
        }
示例#5
0
文件: SimBroker.cs 项目: mpvyard/Core
        /// <summary>
        /// Add pending order to local orderbook
        /// </summary>
        /// <param name="o"></param>
        /// <param name="a"></param>
        protected void AddOrder(PendingOrder o, SimAccount a)
        {
            if (!a.IsValid)
            {
                throw new Exception("Invalid account provided"); // account must be good
            }
            //Add event handlers
            o.OnCancel += HandleOrderCancel;
            o.OnUpdate += HandleOrderUpdate;

            // add any remaining order to book as new liquidity route
            List <PendingOrder> tmp;

            // see if we have a book for this account
            if (!MasterOrders.TryGetValue(a, out tmp))
            {
                tmp = new List <PendingOrder>();
                MasterOrders.Add(a, tmp); // if not, create one
            }
            OrderImpl order = (OrderImpl)o.Order;

            order.AccountName = a.Id; // make sure order knows his account
            tmp.Add(o);               // record the order
            // increment pending count
            _pendorders++;
        }
示例#6
0
文件: SimBroker.cs 项目: mpvyard/Core
        public Order BestBidOrOffer(string symbol, Direction direction)
        {
            Order best = new OrderImpl();

            SimAccount[] accts = new SimAccount[MasterOrders.Count];
            MasterOrders.Keys.CopyTo(accts, 0);
            for (int i = 0; i < accts.Length; i++)
            {
                SimAccount a = accts[i];
                // get our first order
                if (!best.IsValid)
                {
                    // if we don't have a valid one yet, check this account
                    best = new OrderImpl(BestBidOrOffer(symbol, direction, a));
                    continue;  // keep checking the accounts till we find a valid one
                }
                // now we have our first order, which will be best if we can't find a second one
                Order next = new OrderImpl(BestBidOrOffer(symbol, direction, a));
                if (!next.IsValid)
                {
                    continue;                      // keep going till we have a second order
                }
                best = BestBidOrOffer(best, next); // when we have two, compare and get best
                // then keep fetching next valid order to see if it's better
            }
            return(best); // if there's no more orders left, this is best
        }
示例#7
0
文件: SimBroker.cs 项目: mpvyard/Core
        public Order BestBidOrOffer(string sym, Direction direction, SimAccount account)
        {
            Order best = new OrderImpl();

            if (!MasterOrders.ContainsKey(account))
            {
                return(best);
            }
            List <PendingOrder> orders = MasterOrders[account];

            for (int i = 0; i < orders.Count; i++)
            {
                Order o = orders[i].Order;
                if (o.Symbol != sym)
                {
                    continue;
                }
                if (o.Direction != direction)
                {
                    continue;
                }
                if (!best.IsValid)
                {
                    best = new OrderImpl(o);
                    continue;
                }
                Order test = BestBidOrOffer(best, o);
                if (test.IsValid)
                {
                    best = new OrderImpl(test);
                }
            }
            return(best);
        }
示例#8
0
        public void IdentityLimits()
        {
            Direction direction  = Direction.Long;
            int       quantity   = 51;
            decimal   limitprice = 120.13m;
            string    comment    = "Hello, World!";

            Order orig = new OrderImpl(security, direction, quantity, limitprice, 0, comment);
            Order comp;

            //Test Market Stop Order Sell Initialization
            comp = new OrderImpl(security, direction, quantity, limitprice, 0, comment);
            Assert.Equal(orig.Direction, comp.Direction);
            Assert.Equal(orig.Type, comp.Type);
            Assert.Equal(orig.Symbol, comp.Symbol);
            Assert.Equal(orig.Size, comp.Size);
            Assert.Equal(orig.StopPrice, comp.StopPrice);
            Assert.Equal(orig.LimitPrice, comp.LimitPrice);
            Assert.Equal(orig.Type, OrderType.Limit);
            Assert.Equal(orig.Comment, comp.Comment);

            //Test Market Stop Order Buy Initialization
            direction = Direction.Long;
            orig      = new OrderImpl(security, direction, quantity, limitprice, 0);
            comp      = new OrderImpl(security, direction, quantity, limitprice, 0);
            Assert.Equal(orig.Direction, comp.Direction);
            Assert.Equal(orig.Type, comp.Type);
            Assert.Equal(orig.Symbol, comp.Symbol);
            Assert.Equal(orig.Size, comp.Size);
            Assert.Equal(orig.StopPrice, comp.StopPrice);
            Assert.Equal(orig.LimitPrice, comp.LimitPrice);
            Assert.Equal(orig.Type, OrderType.Limit);
        }
示例#9
0
        public void BasicWithAccount()
        {
            long id = 1;

            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent += new DebugDelegate(rt.d);
            Order o = new OrderImpl();

            // take a position
            sho.GotPosition(new PositionImpl(sym, 100, 300, 0, ACCT));

            // accept two exits
            o         = new SellLimit(sym, 100, 200, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o));
            sho.GotOrder(o);
            o         = new SellLimit(sym, 200, 105, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o));
            sho.GotOrder(o);

            // send another short
            o         = new SellStop(sym, 300, 99);
            o.Account = ACCT;
            Assert.IsTrue(sho.isOrderShort(o));
        }
示例#10
0
        public void DayFill()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl        day  = new OrderImpl(tsec, Direction.Long, 200);
            PendingOrderImpl pday = new PendingOrderImpl(day);

            broker.SendOrderStatus(pday);

            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 9, 10000, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 9, 10000, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 9, 10000, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 9, 10000, "NYS");

            int c;

            c = broker.Execute(openingTick); Assert.Equal(1, c); // should execute on first received tick
            c = broker.Execute(endMornTick); Assert.Equal(0, c);
            c = broker.Execute(endLunchTick); Assert.Equal(0, c);
            c = broker.Execute(closingTick); Assert.Equal(0, c);
        }
示例#11
0
        public void Fill_RegularLiquidity()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl limitBuy  = new OrderImpl(tsec, Direction.Long, 1, 133m);
            OrderImpl limitSell = new OrderImpl(tsec, Direction.Short, 1, 133.5m);
            OrderImpl stopBuy   = new OrderImpl(tsec, Direction.Long, 3, 0, 135.70m);
            OrderImpl stopSell  = new OrderImpl(tsec, Direction.Short, 4, 0, 135.75m);

            PendingOrderImpl plimitBuy  = new PendingOrderImpl(limitBuy);
            PendingOrderImpl plimitSell = new PendingOrderImpl(limitSell);
            PendingOrderImpl pstopBuy   = new PendingOrderImpl(stopBuy);
            PendingOrderImpl pstopSell  = new PendingOrderImpl(stopSell);

            broker.SendOrderStatus(plimitBuy);
            broker.SendOrderStatus(plimitSell);
            broker.SendOrderStatus(pstopBuy);
            broker.SendOrderStatus(pstopSell);

            // OHLC for 6/21/2012 on SPY
            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 135.67m, 10670270, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 135.78m, 10670270, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 132.33m, 10670270, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 132.44m, 10670270, "NYS");

            broker.Execute(openingTick);
            broker.Execute(endMornTick);
            broker.Execute(endLunchTick);
            broker.Execute(closingTick);

            List <Trade> trades = broker.GetTradeList();

            Assert.True(trades.Count == 4);

            foreach (Trade trade in trades)
            {
                if (trade.Xsize == 1)
                {
                    Assert.Equal(132.33m, trade.Xprice);
                }
                else if (trade.Xsize == 2)
                {
                    Assert.Equal(132.33m, trade.Xprice);
                }
                else if (trade.Xsize == 3)
                {
                    Assert.Equal(135.78m, trade.Xprice);
                }
                else if (trade.Xsize == 4)
                {
                    Assert.Equal(135.78m, trade.Xprice);
                }
            }
        }
示例#12
0
        private void fmFastTM_Load(object sender, EventArgs e)
        {
            WinNumberImpl winService = new WinNumberImpl();

            txtIssue.Text           = winService.GetNewIssue().Body;
            this.txtMoney.KeyPress += new KeyPressEventHandler(Common.TextBox_FilterString_KeyPress);
            Common.BindCustomers(cbxCustomer, (sender1, e1) =>
            {
                if (cbxCustomer.SelectedIndex != 0)
                {
                    OrderImpl orderservice = new OrderImpl();
                    textBox1.Text          = orderservice.GetMaxIndex(cbxCustomer.SelectedValue.ToString(), txtIssue.Text.Trim()).Body.ToString();
                }

                OddsImpl oddservice = new OddsImpl();
                var r = oddservice.GetList(cbxCustomer.SelectedValue.ToTryInt());
                tm    = r.Body.FirstOrDefault(x => x.ChildType == childType);
                if (tm == null)
                {
                    MessageEx.ShowWarning("未设置客户赔率");
                    tm            = new OddsData();
                    tm.CustomerId = cbxCustomer.SelectedValue.ToTryInt();
                    tm.PL         = 00.00M;
                    tm.FS         = 0M;
                }
                Common.CustomerId = cbxCustomer.SelectedValue.ToTryInt();
            });
            listView1.GridLines     = true;
            listView1.FullRowSelect = true;
            listView1.View          = View.Details;
            listView1.Scrollable    = true;
            listView1.MultiSelect   = false;
        }
示例#13
0
        public void MOCs()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl moc = new OrderImpl(tsec, Direction.Long, 200);

            moc.ValidInstruct = OrderInstructionType.MOC;
            PendingOrderImpl pmoc = new PendingOrderImpl(moc);

            Assert.True(moc.ValidInstruct == OrderInstructionType.MOC, "unexpected order instruction: " + moc.ValidInstruct);
            Assert.Equal(0, broker.SendOrderStatus(pmoc));

            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 9, 10000, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 9, 10000, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 9, 10000, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 9, 10000, "NYS");

            int c = 0;

            c = broker.Execute(openingTick); Assert.Equal(0, c);
            c = broker.Execute(endMornTick); Assert.Equal(0, c);
            c = broker.Execute(endLunchTick); Assert.Equal(0, c);
            c = broker.Execute(closingTick); Assert.Equal(1, c); // should execute on the first tick at/after 16:00:00
        }
示例#14
0
        /// <summary>
        /// Round the prices to a correct number for this order and its associated security
        /// </summary>
        /// <param name="order">The order.</param>
        protected virtual void RoundOrderPrices(OrderImpl order)
        {
            //check if we need to round order prices
            if (order.Type == OrderType.Market ||
                order.Type == OrderType.MarketOnClose ||
                order.Type == OrderType.MarketOnOpen)
            {
                return;
            }

            decimal minimumincrement = Portfolio.BrokerModel.GetMinimumPriceIncrement(order.Security);

            if (minimumincrement == 0)
            {
                return;
            }

            decimal limitprice        = 0;
            decimal limitchangedprice = 0;
            decimal stopprice         = 0;
            decimal stopchangedprice  = 0;

            switch (order.Type)
            {
            case OrderType.Limit:
                limitprice        = ((LimitOrder)order).LimitPrice;
                limitchangedprice = Math.Round(((LimitOrder)order).LimitPrice / minimumincrement) * minimumincrement;
                ((LimitOrder)order).LimitPrice = limitchangedprice;
                break;

            case OrderType.StopMarket:
                stopprice        = ((StopMarketOrder)order).StopPrice;
                stopchangedprice = Math.Round(((StopMarketOrder)order).StopPrice / minimumincrement) * minimumincrement;
                ((StopMarketOrder)order).StopPrice = stopchangedprice;
                break;

            case OrderType.StopLimit:
                limitprice        = ((StopLimitOrder)order).LimitPrice;
                stopprice         = ((StopLimitOrder)order).StopPrice;
                limitchangedprice = Math.Round(((StopLimitOrder)order).LimitPrice / minimumincrement) * minimumincrement;
                stopchangedprice  = Math.Round(((StopLimitOrder)order).StopPrice / minimumincrement) * minimumincrement;
                ((StopLimitOrder)order).LimitPrice = limitchangedprice;
                ((StopLimitOrder)order).StopPrice  = stopchangedprice;
                break;
            }

            //check for changes to be notified
            void Message(string type, decimal oldvalue, decimal newvalue) => Portfolio.Log(LogLevel.Error, $"Warning: To meet brokerage precision requirements, order with id {order.InternalId} and its {type}Price was rounded to {newvalue} from {oldvalue}");

            if (limitprice != limitchangedprice)
            {
                Message("Limit", limitprice, limitchangedprice);
            }
            if (stopprice != stopchangedprice)
            {
                Message("Stop", stopprice, stopchangedprice);
            }
        }
示例#15
0
        private void fmFastLX_Load(object sender, EventArgs e)
        {
            WinNumberImpl winService = new WinNumberImpl();

            txtIssue.Text           = winService.GetNewIssue().Body;
            this.txtMoney.KeyPress += new KeyPressEventHandler(Common.TextBox_FilterString_KeyPress);


            Common.BindLXType(comboBox1, (sender1, e1) =>
            {
                if (cbxCustomer.SelectedIndex == 0 || comboBox1.SelectedIndex == 0)
                {
                    return;
                }
                OddsImpl oddservice = new OddsImpl();
                var r        = oddservice.GetList(cbxCustomer.SelectedValue.ToTryInt());
                var oddsList = r.Body.FirstOrDefault(x => x.ChildType == comboBox1.SelectedValue.ToTryInt());
                if (oddsList != null)
                {
                    odds = Newtonsoft.Json.JsonConvert.DeserializeObject <LXOdds>(oddsList.strJson);
                }
                else
                {
                    odds      = new LXOdds();
                    odds.List = new Dictionary <int, decimal>();
                }
            });
            Common.BindCustomers(cbxCustomer, (sender1, e1) =>
            {
                if (cbxCustomer.SelectedIndex != 0)
                {
                    OrderImpl orderservice = new OrderImpl();
                    textBox1.Text          = orderservice.GetMaxIndex(cbxCustomer.SelectedValue.ToString(), txtIssue.Text.Trim()).Body.ToString();
                }
                if (cbxCustomer.SelectedIndex == 0 || comboBox1.SelectedIndex == 0)
                {
                    return;
                }
                OddsImpl oddservice = new OddsImpl();
                var r        = oddservice.GetList(cbxCustomer.SelectedValue.ToTryInt());
                var oddsList = r.Body.FirstOrDefault(x => x.ChildType == comboBox1.SelectedValue.ToTryInt());
                if (oddsList != null)
                {
                    odds = Newtonsoft.Json.JsonConvert.DeserializeObject <LXOdds>(oddsList.strJson);
                }
                else
                {
                    odds      = new LXOdds();
                    odds.List = new Dictionary <int, decimal>();
                }
                Common.CustomerId = cbxCustomer.SelectedValue.ToTryInt();
            });
            listView1.GridLines     = true;
            listView1.FullRowSelect = true;
            listView1.View          = View.Details;
            listView1.Scrollable    = true;
            listView1.MultiSelect   = false;
        }
示例#16
0
        // runs after simulation is complete
        void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            debug(_sb.ToString());
            _sb = new System.Text.StringBuilder(10000000);
            GauntArgs gargs = (GauntArgs)e.Result;

            if (!e.Cancelled)
            {
                List <Trade> list = SimBroker.GetTradeList();
                tradeResults1.NewResultTrades(LogFile("Trades"), list);
                if (gargs.Trades)
                {
                    debug("writing " + list.Count + " trades...");
                    Util.ClosedPLToText(list, ',', LogFile("Trades"));
                }
                if (gargs.Orders)
                {
                    List <Order> olist = SimBroker.GetOrderList();
                    debug("writing " + olist.Count + " orders...");
                    StreamWriter sw   = new StreamWriter(LogFile("Orders"), false);
                    string[]     cols = Enum.GetNames(typeof(OrderField));
                    sw.WriteLine(string.Join(",", cols));
                    for (int i = 0; i < olist.Count; i++)
                    {
                        sw.WriteLine(OrderImpl.Serialize(olist[i]));
                    }
                    sw.Close();
                }
                string msg = "Done.  Ticks: " + gargs.TicksProcessed + " Speed:" + gargs.TicksSecond.ToString("N0") + " t/s  Fills: " + gargs.Executions.ToString();
                debug(msg);
                status(msg);
            }
            else
            {
                debug("Canceled.");
            }
            // close indicators
            if (indf != null)
            {
                indf.Close();
                indf = null;
            }

            // reset simulation
            h.Reset();
            count = 0;
            lastp = 0;
            if (args.isUnattended)
            {
                Close();
                return;
            }
            // enable new runs
            ProgressBar1.Enabled = false;
            ProgressBar1.Value   = 0;
            queuebut.Enabled     = true;
            Invalidate(true);
        }
示例#17
0
 void reset()
 {
     tks = new TIFTracker_Ticks();
     tks.SendCancelEvent += new LongDelegate(tks_SendCancelEvent);
     tks.SendDebugEvent  += new DebugDelegate(tks_SendDebugEvent);
     tks.SendOrderEvent  += new OrderDelegate(tks_SendOrderEvent);
     lasto      = new OrderImpl();
     lastcancel = 0;
 }
示例#18
0
        public void Defaults()
        {
            // assert that a default order is:
            // not valid, not filled
            OrderImpl o = new OrderImpl();

            Assert.True(!o.IsValid);
            Assert.True(!o.IsFilled);
        }
示例#19
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);
        }
示例#20
0
文件: fmMain.cs 项目: tanzw/six
        private void  除订单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var       sd      = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            OrderImpl service = new OrderImpl();

            if (service.DeleteOrder(sd).Body)
            {
                BindDataSource();
            }
        }
示例#21
0
        public void MarketOrder()
        {
            const string s = "SYM";
            OrderImpl    o = new OrderImpl(security, Direction.Long, 1);

            Assert.True(o.IsValid);
            Assert.True(o.Direction == Direction.Long);
            Assert.True(o.Type == OrderType.Market);
            Assert.True(!o.IsFilled);
            Assert.True(o.Symbol == s);
        }
示例#22
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);
        }
示例#23
0
        public override void StatusReport(OrderStatusReport oReport)
        {
            Order o = new OrderImpl(oReport.Symbol, oReport.EntryType.Contains("BUY"), oReport.ConfirmedSize);

            o.Account = oReport.Account.AccountId;
            o.id      = Convert.ToInt64(oReport.Tag);
            o.ex      = oReport.Exchange;
            o.date    = Util.ToTLDate();
            o.time    = Util.ToTLTime();
            tl.newOrder(o);
        }
示例#24
0
文件: fmMain.cs 项目: tanzw/six
        private void 校验ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OrderImpl service = new OrderImpl();
            var       id      = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            var       result  = service.SetCheck(id);

            if (result.Code == 0)
            {
                dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.AliceBlue;
                dataGridView1.CurrentRow.Cells[6].Value             = "已校验";
            }
        }
示例#25
0
        public void SplitCancelCopy()
        {
            lasto = new OrderImpl();
            oc    = 0;
            cancels.Clear();
            ost = new OversellTracker();
            ost.SendOrderEvent  += new OrderDelegate(ost_SendOrderEvent);
            ost.SendDebugEvent  += new DebugDelegate(rt.d);
            ost.SendCancelEvent += new LongDelegate(ost_SendCancelEvent);

            ost.Split = true;
            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 300));
            // over sell
            Order o = new SellMarket("TST", 500);

            o.id = 5;
            ost.sendorder(o);
            // verify that only flat was sent
            Assert.AreEqual(2, oc);
            Assert.AreEqual(-200, lasto.size);
            // make sure we've not canceled
            Assert.AreEqual(0, cancels.Count);
            // cancel original order
            ost.sendcancel(5);
            // ensure two cancels sent
            Assert.AreEqual(2, cancels.Count);
            // ensure different cancels
            Assert.AreEqual(5, cancels[0]);
            Assert.AreNotEqual(5, cancels[1]);

            // do it again

            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 300));

            // over sell
            o    = new SellMarket("TST", 500);
            o.id = 10;
            ost.sendorder(o);
            // verify that only flat was sent
            Assert.AreEqual(4, oc);
            Assert.AreEqual(-200, lasto.size);
            // make sure we've not canceled
            Assert.AreEqual(2, cancels.Count);
            // cancel original order
            ost.sendcancel(10);
            // ensure two cancels sent
            Assert.AreEqual(4, cancels.Count);
            // ensure different cancels
            Assert.AreEqual(10, cancels[2]);
            Assert.AreNotEqual(10, cancels[3]);
        }
示例#26
0
        public void MarketOrder()
        {
            const string s = "SYM";
            OrderImpl    o = new OrderImpl(s, 100);

            Assert.That(o.isValid);
            Assert.That(o.isMarket);
            Assert.That(!o.isLimit);
            Assert.That(!o.isStop);
            Assert.That(!o.isFilled);
            Assert.That(o.symbol == s);
        }
示例#27
0
        public void SerializationAndDeserialization()
        {
            // create an order
            const string s = "TST";
            const string x = "NYSE";
            const string a = "ACCOUNT";
            const string u = "COMMENT";

            const decimal      p = 10;
            const int          z = 100;
            const CurrencyType c = CurrencyType.USD;
            const SecurityType t = SecurityType.STK;
            Order o = new OrderImpl(s, z);

            o.date     = 20080718;
            o.time     = 94800;
            o.price    = p;
            o.Account  = a;
            o.ex       = x;
            o.Currency = c;
            o.Security = t;
            o.comment  = u;
            var inst = OrderInstructionType.GTC;

            o.ValidInstruct = inst;
            //o.TIF = ot;
            // convert it to a message
            string msg = OrderImpl.Serialize(o);

            // convert it back to an object and validate nothing was lost
            string exception = null;
            Order  n         = new OrderImpl();

            try
            {
                n = OrderImpl.Deserialize(msg);
            }
            catch (Exception ex) { exception = ex.ToString(); }
            Assert.That(exception == null, msg + " " + exception);
            Assert.That(n.Account == a, n.Account);
            Assert.That(n.symbol == s, n.symbol);
            Assert.That(n.size == z, n.size.ToString());
            Assert.That(n.price == p, n.price.ToString());
            Assert.That(n.Exchange == x, n.Exchange);

            Assert.That(n.Security == t, n.Security.ToString());
            Assert.That(n.Currency == c, n.Currency.ToString());
            Assert.That(n.ValidInstruct == inst, n.ValidInstruct.ToString(), "unexpected instruction: " + n.ValidInstruct.ToString());
            Assert.That(n.date == o.date, n.date.ToString());
            Assert.That(n.time == o.time, n.time.ToString());
        }
示例#28
0
        public void FillBidAsk()
        {
            string s = security.Name;
            // market should fill on trade but not on quote
            OrderImpl o = new OrderImpl(security, Direction.Long, 100);

            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 8, 100), trans) == StatusType.OFF_QUOTES);

            // buy limit

            // limit should fill if order price is inside market
            o = new OrderImpl(security, Direction.Long, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Long, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 11, 100), trans) == StatusType.OFF_QUOTES);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 11, 100), trans) == StatusType.OK);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 10, 100), trans) == StatusType.OFF_QUOTES);

            // sell limit

            // limit should fill if order price is inside market
            o = new OrderImpl(security, Direction.Short, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 11, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Short, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);

            // buy stop

            o = new OrderImpl(security, Direction.Long, 100, 0, 10m);
            Assert.True(o.Type == OrderType.Stop);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 11, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Long, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);

            // sell stop

            o = new OrderImpl(security, Direction.Short, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Short, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 11, 100), trans) == StatusType.OFF_QUOTES);

            // always fail filling an invalid tick
            o = new OrderImpl(security, Direction.Long, 100);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 0, 0), trans) == StatusType.OFF_QUOTES);
        }
示例#29
0
        public void Basics()
        {
            Broker broker = new Broker();

            broker.GotFill  += new FillDelegate(broker_GotFill);
            broker.GotOrder += new OrderDelegate(broker_GotOrder);
            OrderImpl o     = new OrderImpl();
            int       error = broker.SendOrderStatus(o);

            Assert.AreNotEqual((int)MessageTypes.OK, error);
            Assert.That(orders == 0);
            Assert.That(fills == 0);
            o = new BuyMarket(s, 100);
            broker.SendOrderStatus(o);
            Assert.That(orders == 1);
            Assert.That(fills == 0);
            Assert.That(broker.Execute(TickImpl.NewTrade(s, 10, 200)) == 1);
            Assert.That(fills == 1);

            // test that a limit order is not filled outside the market
            o = new BuyLimit(s, 100, 9);
            broker.SendOrderStatus(o);
            Assert.AreEqual(0, broker.Execute(TickImpl.NewTrade(s, 10, 100)));
            Assert.That(fills == 1); // redudant but for counting

            // test that limit order is filled inside the market
            Assert.AreEqual(1, broker.Execute(TickImpl.NewTrade(s, 8, 100)));
            Assert.That(fills == 2);

            OrderImpl x = new OrderImpl();

            // test that a market order is filled when opposite book exists
            o = new SellLimit(s, 100, 11);
            x = new BuyMarket(s, 100);
            const string t2 = "trader2";

            x.Account = t2;
            broker.SendOrderStatus(o);
            broker.SendOrderStatus(x);
            Assert.AreEqual(3, fills);

            // test that a market order is not filled when no book exists
            // on opposite side

            // clear existing orders
            broker.CancelOrders();
            o         = new SellMarket(s, 100);
            o.Account = t2;
            broker.SendOrderStatus(o);
            Assert.AreEqual(3, fills);
        }
示例#30
0
        public void FillThenStopAndLimitOversell()
        {
            long id = 1;

            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent  += new DebugDelegate(rt.d);
            sho.VerboseDebugging = true;
            lastids.Clear();
            Order o = new OrderImpl();

            // send some initial orders
            so(new SellLimit(sym, 100, 25.83m, id++));
            so(new SellStop(sym, 100, 25.83m, id++));
            o = new SellStop(sym, 200, 25.83m, id++);
            so(o);
            // cancel first two orders
            sho.GotCancel(lastids[0]);
            sho.GotCancel(lastids[1]);
            // fill last order
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 25.80m, 200)), "missing initial fill");
            sho.GotFill((Trade)o);
            // check pending size
            Assert.AreEqual(0, pendingsize(sym), "had pending size after cancels and fills");
            // flat position
            sho.GotPosition(new PositionImpl(sym, 0, 0, 0, ACCT));



            // take a position
            o         = new BuyLimit(sym, 100, 25.83m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "entry buy never a short.");
            sho.GotOrder(o);
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 25.80m, 100)), "unable to fill order");
            Trade t = (Trade)o;

            Assert.IsTrue(t.isValid && t.isFilled, "not a valid trade");
            sho.GotFill(t);


            // accept two exits
            o         = new SellStop(sym, 100, 21.09m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "first exit was wrongly a short");
            sho.GotOrder(o);
            o         = new SellLimit(sym, 100, 21.19m, id++);
            o.Account = ACCT;
            Assert.IsTrue(sho.isOrderShort(o), "second exit was wrongly a sell");
            sho.GotOrder(o);
        }