Exemple #1
0
        public QuantConnect.Holding ConvertToHolding(TEBPosition position)
        {
            //string currencySymbol;
            //if (!Currencies.CurrencySymbols.TryGetValue(currency, out currencySymbol))
            //{
            //    currencySymbol = "$";
            //}
            string currencySymbol = "$";
            string symbol         = position.Symbol;

            return(new Holding
            {
                Symbol = ConvertToSymbol(symbol),
                Type = SecurityType.Equity,
                Quantity = position.NetLotCount,
                //Quantity = position.Side == CashDefinition.SIDE_SELL ? -position.Units : position.Units,
                AveragePrice = position.AvgNetPrice,
                //MarketPrice = marketPrice,
                ConversionRate = 1m, // this will be overwritten when GetAccountHoldings is called to ensure fresh values
                CurrencySymbol = currencySymbol
            });

            //return new Holding
            //{
            //    Symbol = Symbol.Create(position.Symbol, SecurityType.Equity, Market.USA),
            //    Type = SecurityType.Equity,
            //    AveragePrice = position.CostBasis / position.Quantity,
            //    ConversionRate = 1.0m,
            //    CurrencySymbol = "$",
            //    MarketPrice = 0m, //--> GetAccountHoldings does a call to GetQuotes to fill this data in
            //    Quantity = position.Quantity
            //};
        }
Exemple #2
0
        private List <TEBPosition> GetPositions()
        {
            Dictionary <string, TEBPosition> tmpList = new Dictionary <string, TEBPosition>();

            IEnumerable <Teb.FIX.Model.Order> tmpOrders = _fixContext.CashAppContext.FilledOrdersView.Values;
            OrderViewType ViewType = OrderViewType.Filled;

            #region MyRegion
            if (tmpOrders != null)
            {
                TEBPosition to = null;
                //to.Seance = "Tüm Gün";
                int count = 0;
                foreach (var tmpOrder in tmpOrders)
                {
                    count++;
                    string symbol = tmpOrder.Symbol;

                    if (!tmpList.TryGetValue(symbol, out to))
                    {
                        to        = new TEBPosition();
                        to.Symbol = symbol;
                        tmpList.Add(symbol, to);
                    }


                    bool    isBuy = false;
                    decimal price = 0;
                    int     qty   = 0;

                    if (ViewType == OrderViewType.Filled)
                    {
                        if (tmpOrder.LastPx.HasValue)
                        {
                            price = tmpOrder.LastPx.Value;
                        }

                        if (tmpOrder.LastQty.HasValue)
                        {
                            qty = tmpOrder.LastQty.Value;
                        }
                    }
                    else
                    {
                        if (tmpOrder.Price.HasValue)
                        {
                            price = tmpOrder.Price.Value;
                        }

                        if (tmpOrder.LeavesQty.HasValue)
                        {
                            qty = tmpOrder.LeavesQty.Value;
                        }
                    }

                    //if (tmpOrder.OrderQty.HasValue)
                    //    qty = tmpOrder.OrderQty.Value;

                    decimal volume = price * qty;

                    if (tmpOrder.Core.Side.Equals(CashDefinition.SIDE_BUY))
                    {
                        isBuy = true;
                    }

                    if (isBuy)
                    {
                        to.BuyLotCount += qty;
                        to.BuyVolume   += volume;
                    }
                    else
                    {
                        to.SellLotCount += qty;
                        to.SellVolume   += volume;
                    }
                }

                if (count == 0)
                {
                    to = new TEBPosition();
                }
                else
                {
                    to.Count = count;

                    to.NetLotCount = to.BuyLotCount - to.SellLotCount;
                    to.NetVolume   = to.SellVolume - to.BuyVolume;
                    to.TotalVolume = Math.Abs(to.BuyVolume) + Math.Abs(to.SellVolume);

                    if (to.NetLotCount != 0)
                    {
                        to.AvgNetPrice = Math.Abs(to.NetVolume / to.NetLotCount);
                    }
                    else
                    {
                        to.AvgNetPrice = 0;
                    }

                    if (to.BuyLotCount != 0)
                    {
                        to.AvgBuyPrice = Math.Abs(to.BuyVolume / to.BuyLotCount);
                    }
                    else
                    {
                        to.AvgBuyPrice = 0;
                    }

                    if (to.SellLotCount != 0)
                    {
                        to.AvgSellPrice = Math.Abs(to.SellVolume / to.SellLotCount);
                    }
                    else
                    {
                        to.AvgSellPrice = 0;
                    }
                }


                //tmpList.Add(to);
            }
            #endregion

            return(tmpList.Values.ToList());
        }