Пример #1
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));
            });
        }
Пример #2
0
        private void ClientGotOrderCancelConfirmation(long oid)
        {
            int pos = OrderTable.Select(row => row.OrderId).ToList().IndexOf(oid);

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                if (pos == -1)
                {
                    OnDebug("Order id " + oid.ToString() + " is not found in order table; possibly new order.");
                }
                else
                {
                    // order table
                    _ordertracker.GotCancel(oid);
                    OrderStatus status     = OrderStatus.Canceled;
                    OrderTable[pos].Status = EnumDescConverter.GetEnumDescription(status);
                }
            });
        }
Пример #3
0
        private void ClientGotOrder(Order o)
        {
            int pos = OrderTable.Select(row => row.OrderId).ToList().IndexOf(o.Id);

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                if (pos == -1)      // not found
                {
                    OnDebug("Order id " + o.Id.ToString() + " is not found in order table; possibly new order.");
                    // it must be previous open order, or placed by tws
                    // add to _ordertracker
                    _ordertracker.GotOrder(o);
                    // update status
                    OrderTable.Add(new OrderEntry(o.Id, o.Account, o.FullSymbol, o.OrderType, o.Price, o.OrderSize, o.OrderTime, EnumDescConverter.GetEnumDescription(o.OrderStatus)));
                }
                else
                {
                    OrderTable[pos].Status = EnumDescConverter.GetEnumDescription(o.OrderStatus);
                }
            });
        }