Exemplo n.º 1
0
        public void PartialFill()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent  += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send a buy order
            o = new BuyLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(200, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");

            // do sell order

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send sell order
            o = new SellLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(-100, ot.Filled(id - 1), "incorrect fill size sell");
            Assert.AreEqual(-200, ot.Sent(id - 1), "not sent sell");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Exemplo n.º 2
0
        public void FixSentOnUnknown()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent      += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging     = true;
            ot.FixSentSizeOnUnknown = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // prepare a buy order
            o = new BuyLimit(sym, 100, 100, id++);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // order will be invalid since it was sent previously (or unknown)
            Assert.False(ot.SentOrder(id - 1).isValid, "valid order was found, none was sent though");
            // verify size/pending/cancel
            Assert.AreEqual(100, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsTrue(ot.isCompleted(id - 1), "wrongly not filled");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Exemplo n.º 3
0
        private void ClientGotOrderFilled(Trade k)
        {
            _tradelist.Add(k);

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                // order table
                int pos = OrderTable.Select(row => row.OrderId).ToList().IndexOf(k.Id);
                if (pos == -1)
                {
                    OnDebug("Order id " + k.Id.ToString() + " is not found in order table; possibly new order.");
                }
                else
                {
                    _ordertracker.GotFill(k);

                    if (_ordertracker[k.Id] == 0)
                    {
                        OrderStatus status     = OrderStatus.Filled;
                        OrderTable[pos].Status = EnumDescConverter.GetEnumDescription(status);
                    }
                    else
                    {
                        OrderStatus status      = OrderStatus.PartiallyFilled;
                        _ordertable[pos].Status = EnumDescConverter.GetEnumDescription(status);
                    }
                }

                // position table only handles one account
                // but it is guarantteed by order id
                _positiontracker.Adjust(k);
                pos = PositionTable.Select(row => row.Symbol).ToList().IndexOf(k.FullSymbol);
                if (pos == -1)
                {
                    // add new position
                    int count = PositionTable.Count;

                    PositionTable.Add(new PositionEntry(count, k.FullSymbol, _positiontracker[k.FullSymbol].AvgPrice, _positiontracker[k.FullSymbol].Size,
                                                        _positiontracker[k.FullSymbol].ClosedPL, _positiontracker[k.FullSymbol].OpenPL));
                }
                else
                {
                    // adjust position
                    PositionTable[pos].AvgPrice = _positiontracker[k.FullSymbol].AvgPrice;
                    PositionTable[pos].Size     = _positiontracker[k.FullSymbol].Size;
                    PositionTable[pos].ClosePL  = _positiontracker[k.FullSymbol].ClosedPL;
                    PositionTable[pos].OpenPL   = _positiontracker[k.FullSymbol].OpenPL;
                }

                FillTable.Add(new FillEntry(k.Id, k.TradeTime, k.FullSymbol, k.TradeSize, k.TradePrice));
            });
        }
Exemplo n.º 4
0
        void tl_gotFill(Trade t)
        {
            ord.GotFill(t);
            if (InvokeRequired)
            {
                Invoke(new FillDelegate(tl_gotFill), new object[] { t });
            }
            else
            {
                if (!t.isValid)
                {
                    return;
                }
                int oidx = orderidx(t.id); // get order id for this order
                if (oidx != -1)
                {
                    int osign       = (t.side ? 1 : -1);
                    int signedtsize = t.xsize * osign;
                    int signedosize = (int)ordergrid["osize", oidx].Value;
                    if (signedosize == signedtsize) // if sizes are same whole order was filled, remove
                    {
                        ordergrid.Rows.RemoveAt(oidx);
                    }
                    else // otherwise remove portion that was filled and leave rest on order
                    {
                        ordergrid["osize", oidx].Value = Math.Abs(signedosize - signedtsize) * osign;
                    }
                }
                pt.Adjust(t);

                UpdateSymbolTrade(GetSymbolRows(t.Sec.FullName), t);
                UpdateSymbolTrade(GetSymbolRows(t.Sec.Symbol), t);

                TradesView.Rows.Add(t.xdate, t.xtime, t.symbol, (t.side ? "BUY" : "SELL"), t.xsize, t.xprice.ToString(_dispdecpointformat), t.comment, t.Account.ToString()); // if we accept trade, add it to list
            }
        }
Exemplo n.º 5
0
 public void GotFill(Trade t)
 {
     ord.GotFill(t);
     pt.GotFill(t);
     ShowItems(AccountActivity.NewTrade(t, pt[t.symbol]));
 }