Beispiel #1
0
        void _client_UpdatePortfolio(AccountResponseFuturesFromWebSocket portfs)
        {
            try
            {
                if (portfs == null)
                {
                    return;
                }

                if (_portfolios == null)
                {
                    return;
                }

                Portfolio portfolio = null;

                portfolio = _portfolios.Find(p => p.Number == "BinanceFutures");


                if (portfolio == null)
                {
                    return;
                }

                foreach (var onePortf in portfs.a.B)
                {
                    if (onePortf == null ||
                        onePortf.a == null ||
                        onePortf.wb == null)
                    {
                        continue;
                    }

                    PositionOnBoard neeedPortf =
                        portfolio.GetPositionOnBoard().Find(p => p.SecurityNameCode == onePortf.a);

                    if (neeedPortf == null)
                    {
                        continue;
                    }

                    neeedPortf.ValueCurrent =
                        onePortf.wb.ToDecimal();
                }

                foreach (var onePortf in portfs.a.P)
                {
                    if (onePortf == null ||
                        onePortf.s == null ||
                        onePortf.pa == null)
                    {
                        continue;
                    }

                    PositionOnBoard neeedPortf =
                        portfolio.GetPositionOnBoard().Find(p => p.SecurityNameCode == onePortf.s);

                    if (neeedPortf == null)
                    {
                        PositionOnBoard newPositionOnBoard = new PositionOnBoard();
                        newPositionOnBoard.SecurityNameCode = onePortf.s;
                        newPositionOnBoard.PortfolioName    = portfolio.Number;
                        newPositionOnBoard.ValueBegin       =
                            onePortf.pa.ToDecimal();
                        portfolio.SetNewPosition(newPositionOnBoard);
                        neeedPortf = newPositionOnBoard;
                    }

                    neeedPortf.ValueCurrent =
                        onePortf.pa.ToDecimal();
                }

                if (PortfolioEvent != null)
                {
                    PortfolioEvent(_portfolios);
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
        void _client_UpdatePortfolio(AccountResponseFuturesFromWebSocket portfs)
        {
            try
            {
                return;

                if (portfs == null)
                {
                    return;
                }

                if (_portfolios == null)
                {
                    return;
                }

                Portfolio portfolio = null;

                portfolio = _portfolios.Find(p => p.Number == "BinanceFutures");


                if (portfolio == null)
                {
                    return;
                }

                foreach (var onePortf in portfs.a.B)
                {
                    if (onePortf == null ||
                        onePortf.a == null ||
                        onePortf.wb == null)
                    {
                        continue;
                    }

                    PositionOnBoard neeedPortf =
                        portfolio.GetPositionOnBoard().Find(p => p.SecurityNameCode == onePortf.a);

                    if (neeedPortf == null)
                    {
                        continue;
                    }

                    neeedPortf.ValueCurrent =
                        onePortf.wb.ToDecimal();
                }

                bool allPosesIsNull = true;

                foreach (var onePortf in portfs.a.P)
                {
                    if (onePortf == null ||
                        onePortf.s == null ||
                        onePortf.pa == null)
                    {
                        continue;
                    }

                    if (onePortf.ep.ToDecimal() == 0)
                    {
                        continue;
                    }

                    allPosesIsNull = false;

                    string name = onePortf.s;

                    if (onePortf.pa.ToDecimal() > 0)
                    {
                        name += "_LONG";
                    }
                    else
                    {
                        name += "_SHORT";
                    }

                    PositionOnBoard neeedPortf =
                        portfolio.GetPositionOnBoard().Find(p => p.SecurityNameCode == name);

                    if (neeedPortf == null)
                    {
                        PositionOnBoard newPositionOnBoard = new PositionOnBoard();
                        newPositionOnBoard.SecurityNameCode = name;
                        newPositionOnBoard.PortfolioName    = portfolio.Number;
                        newPositionOnBoard.ValueBegin       =
                            onePortf.pa.ToDecimal();
                        portfolio.SetNewPosition(newPositionOnBoard);
                        neeedPortf = newPositionOnBoard;
                    }

                    neeedPortf.ValueCurrent =
                        onePortf.pa.ToDecimal();
                }

                if (allPosesIsNull == true)
                {
                    foreach (var onePortf in portfs.a.P)
                    {
                        if (onePortf == null ||
                            onePortf.s == null ||
                            onePortf.pa == null)
                        {
                            continue;
                        }

                        PositionOnBoard neeedPortf =
                            portfolio.GetPositionOnBoard().Find(p => p.SecurityNameCode == onePortf.s);

                        if (neeedPortf == null)
                        {
                            PositionOnBoard newPositionOnBoard = new PositionOnBoard();
                            newPositionOnBoard.SecurityNameCode = onePortf.s;
                            newPositionOnBoard.PortfolioName    = portfolio.Number;
                            newPositionOnBoard.ValueBegin       = 0;
                            portfolio.SetNewPosition(newPositionOnBoard);
                            neeedPortf = newPositionOnBoard;
                        }

                        neeedPortf.ValueCurrent = 0;
                        break;
                    }
                }

                if (PortfolioEvent != null)
                {
                    PortfolioEvent(_portfolios);
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }