private void CloseTrades(int index) { Console.WriteLine("Closing trades........."); for (var iPos = index; iPos >= 0; iPos--) { this.FxStock = (ForexData)this.StockObject.TradeList[iPos]; if (this.FxStock.UnrealizedPL > 0.10m) { if (ExchangeObject.CloseTrade(this.FxStock, this.CurrentAccount.Id)) { this.FxStock.Cost = (this.FxStock.Count * this.FxStock.PriceBuy); this.FxStock.Revenue = (this.FxStock.Count * this.FxStock.PriceSell); this.FxStock.UserName = GetUserConfig(this.FxStock.Symbol).Name; //this.FxStock.ProfitnLoss = this.FxStock.ProfitnLoss + FxStock.FeeSell; Console.WriteLine("Sold " + this.FxStock.Count + " " + this.FxStock.Symbol + " with price " + this.FxStock.PriceSell + " and Profit = " + this.FxStock.ProfitnLoss + " at " + DateTime.Now); if (!dbManager.InsertEntity <ForexData>(this.FxStock)) { Console.WriteLine("Error while writing to DB"); } this.StockObject.TradeList.RemoveAt(iPos); thisAnalyzer.ClearAnalyzer(); } } } Console.WriteLine("...................................."); }
private void ProcessTrade() { decimal profitVal = 0.0m; if (this.StockObject.TradeList.Count > 1) { for (var iPos = this.StockObject.TradeList.Count - 1; iPos > 0; iPos--) { this.FxStock = (ForexData)this.StockObject.TradeList[iPos]; if (posConfig.TradeProcessProfitMode == Constants.TradeMode.FIXED) { profitVal = posConfig.FixedTradeProcessProfitValue; } else if (posConfig.TradeProcessProfitMode == Constants.TradeMode.VARIABLE) { profitVal = posConfig.FixedTradeProcessProfitValue; } if (this.FxStock.UnrealizedPL >= (profitVal * 6)) //Move this to configuration { Thread newThread = null; //Quick buy 10K number and try closing soon, if soon not closed, enable flag and monitor daily. if (this.CurrentAccount.Type == "Long") { if (QuickBuyLongAccountInfo == null) { QuickBuyLongAccountInfo = GetAccountDetails(GetAccountId("Long")); } newThread = new Thread(() => this.TriggerQuickBuy(this.FxStock.Symbol)); } else if (this.CurrentAccount.Type == "Short") { if (QuickBuyShortAccountInfo == null) { QuickBuyShortAccountInfo = GetAccountDetails(GetAccountId("Short")); } newThread = new Thread(() => this.TriggerQuickBuy(this.FxStock.Symbol)); } newThread.Name = "QuickBuyTragger"; newThread.Start(); } else if (this.FxStock.UnrealizedPL >= profitVal) { if (ExchangeObject.CloseTrade(this.FxStock, this.CurrentAccount.Id)) { this.FxStock.Cost = (this.FxStock.Count * this.FxStock.PriceBuy); this.FxStock.Revenue = (this.FxStock.Count * this.FxStock.PriceSell); this.FxStock.UserName = GetUserConfig(this.FxStock.Symbol).Name; if (!dbManager.InsertEntity <ForexData>(this.FxStock)) { Console.WriteLine("Error while writing to DB"); } this.StockObject.TradeList.RemoveAt(iPos); } } else { break; } } } }