Beispiel #1
0
        /// <summary>
        /// Инициализация списка активов портфеля
        /// </summary>
        /// <returns></returns>
        private async Task InitialTradePositions()
        {
            //получаем текущий портфель на счете
            var portfolio = await _context.PortfolioAsync(_accountId);

            if (!portfolio.Positions.Any(p => p.InstrumentType == InstrumentType.Currency && p.Balance > 0))
            {
                await InitialBalance();

                await InitialTradePositions();
            }
            else
            {
                foreach (var tradeFigi in _tradingBaseStrategy.SettingProvider.TradeFigis)
                {
                    TradePosition currentTradePosition = _tradePositions.FirstOrDefault(p => p.Figi == tradeFigi);
                    if (currentTradePosition == null)
                    {
                        currentTradePosition = new TradePosition(tradeFigi);
                        _tradePositions.Add(currentTradePosition);
                    }
                    //обновляем портфелльную позицию
                    currentTradePosition.PortfolioPosition = portfolio.Positions.FirstOrDefault(x => x.Figi == tradeFigi);
                }
            }
        }
        /// <summary>
        /// Получение последней цены
        /// </summary>
        /// <param name="tradePosition"></param>
        /// <returns></returns>
        private async Task CalcLastPrice(TradePosition tradePosition)
        {
            //Получаем текущую цену - это цена LastPrice, которая передается вместе со стаканом заявок
            var orderbook = await _context.MarketOrderbookAsync(tradePosition.Figi, 1);

            tradePosition.LastPrice = orderbook.LastPrice;

            if (tradePosition.PortfolioPosition == null)
            {
                tradePosition.AvgPrice  = tradePosition.LastPrice;
                tradePosition.ProfitSum = Decimal.Zero;
                Console.WriteLine($"Figi: {tradePosition.Figi} avgprice: {tradePosition.AvgPrice} lastprice: {tradePosition.LastPrice}");
            }
            else
            {
                Console.WriteLine($"Ticker: {tradePosition.PortfolioPosition.Ticker} balance:{tradePosition.PortfolioPosition.Balance} avgprice: {tradePosition.AvgPrice} lastprice: {tradePosition.LastPrice} profit: {tradePosition.ProfitSum} prevoperation: {tradePosition.PrevOperationType}");
            }
        }