/// <summary>
        /// This Function Will return the missing trades
        /// </summary>
        /// <param name="trade">trade</param>
        /// <param name="slavelist">slavelist</param>
        /// <returns>List of BOMAM Trade</returns>
        public List <BOMAMTrade> AddMissingOpenTrades(TradesHistory trade, List <R_AssetManager_IntroducingBroker_ClientAccount> slavelist)
        {
            try
            {
                var boMAMTradeList = new List <BOMAMTrade>();

                //Checking the Count
                if (slavelist.Count > 0)
                {
                    //Loop through all the slavelist and create missing trade
                    foreach (var item in slavelist)
                    {
                        var boMAMTrade = new BOMAMTrade()
                        {
                            OrderID            = (int)trade.OrderID,
                            FK_IBID            = (int)item.FK_IBID,
                            FK_ClientAccountID = (int)item.FK_ClientAccountID,
                            OpenPrice          = trade.OpenPrice,
                            ClosePrice         = trade.ClosePrice,
                            OpenTime           = trade.OpenTime,
                            CloseTime          = trade.CloseTime,
                            Symbol             = trade.Symbol,
                            Agent           = "",
                            LastIDProcessed = trade.PK_TradeID,
                            Size            = (double)trade.Volume * (double)item.AllocationRatio,
                            Swap            = trade.Storage * item.AllocationRatio,
                            Commission      = trade.Commission * item.AllocationRatio,
                            Pnl             = trade.Profit * item.AllocationRatio,
                            IsopenTrades    = false
                        };
                        boMAMTradeList.Add(boMAMTrade);
                    }
                }

                return(boMAMTradeList);
            }
            catch (Exception exceptionMessage)
            {
                CommonErrorLogger.CommonErrorLog(exceptionMessage, System.Reflection.MethodBase.GetCurrentMethod().Name);
                return(null);
            }
        }
        /// <summary>
        /// This Function is running in thread
        /// it will get all the trades after the
        /// processed id and than populateBOBOpen Trades data.
        /// </summary>
        public void StartBOMAMOpenTrades()
        {
            var lastProcessedID = 0;
            var tradeBO         = new TradeBO();
            var boMAMTradeBO    = new BOMAMTradeBO();
            var clientAccountBO = new Client_AccountBO();

            while (true)
            {
                //Check If Initiated
                if (isInitiated)
                {
                    try
                    {
                        if (assetManagerDict.Keys.Count > 0)
                        {
                            //If The LastProcessID is 0 get it from database
                            if (lastProcessedID == 0)
                            {
                                lastProcessedID = boMAMTradeBO.GetLastOpenTradeProcessedID();
                            }

                            //Get All Open Trades For All the asset Manager
                            var openTradeResult = tradeBO.GetAssetManagerOpenTrades(assetManagerDict.Keys.ToList(), lastProcessedID);

                            //Check If the Count > 0
                            if (openTradeResult.Count > 0)
                            {
                                lastProcessedID = openTradeResult.Max(x => x.PK_TradeID);
                                var boMAMTradeList = new List <BOMAMTrade>();

                                //Loop Through The Open trades
                                foreach (var item in openTradeResult)
                                {
                                    foreach (var res in assetManagerDict[(int)item.Login])
                                    {
                                        BOMAMTrade openBOMAMTrade = new BOMAMTrade();
                                        openBOMAMTrade.OrderID            = (int)item.OrderID;
                                        openBOMAMTrade.OpenPrice          = item.OpenPrice;
                                        openBOMAMTrade.ClosePrice         = item.ClosePrice;
                                        openBOMAMTrade.OpenTime           = item.OpenTime;
                                        openBOMAMTrade.CloseTime          = item.CloseTime;
                                        openBOMAMTrade.Agent              = "";
                                        openBOMAMTrade.FK_IBID            = (int)res.FK_IBID;
                                        openBOMAMTrade.FK_ClientAccountID = (int)res.FK_ClientAccountID;
                                        openBOMAMTrade.Symbol             = item.Symbol;
                                        openBOMAMTrade.LastIDProcessed    = item.PK_TradeID;
                                        openBOMAMTrade.Size         = item.Volume != null ? (double)item.Volume * slaveAllocationDict[(int)res.FK_ClientAccountID] : 0.0;
                                        openBOMAMTrade.Commission   = item.Commission != null ? (double)item.Commission * slaveAllocationDict[(int)res.FK_ClientAccountID] : 0.0;
                                        openBOMAMTrade.Swap         = item.Storage != null ? (double)item.Storage * slaveAllocationDict[(int)res.FK_ClientAccountID] : 0.0;
                                        openBOMAMTrade.Pnl          = item.Profit != null ? (double)item.Profit * slaveAllocationDict[(int)res.FK_ClientAccountID] : 0.0;
                                        openBOMAMTrade.IsopenTrades = true;
                                        boMAMTradeList.Add(openBOMAMTrade);
                                    }
                                }

                                //If Count > 0 Add it to the database
                                if (boMAMTradeList.Count > 0)
                                {
                                    boMAMTradeBO.AddBOMAMOpenTrades(boMAMTradeList);
                                }
                            }
                        }
                    }
                    catch (Exception exceptionMessage)
                    {
                        //Log Error
                        CurrentDeskLog.Error("Monitoring Open Trades :" + exceptionMessage);
                    }
                }
            }
        }
Esempio n. 3
0
 public void Delete(BOMAMTrade entity)
 {
     Repository.Delete(entity);
 }
Esempio n. 4
0
 public void Add(BOMAMTrade entity)
 {
     Repository.Add(entity);
 }