private List <IOrder> GetBuyOrderForSingleAccount(IAccountInterface CustomerAccount, List <ISecurityAnalysis> TradingAnalysis, List <Tuple <string, string> > TradingForeCastPerSymbol) { //ugly way of making the trading a little bit random... List <ISecurityAnalysis> ModifiedList = new List <ISecurityAnalysis>(); Random rnd = new Random(); string[] Sector = ImperaturGlobal.Instruments.GroupBy(i => i.Sector).Select(grp => grp.First()).Select(x => x.Sector).ToArray(); int r = rnd.Next(Sector.Count()); string PreferredSector = Sector[r]; if (TradingAnalysis.Where(tr => tr.Instrument.Sector.Equals(PreferredSector)).Count() > 0) { ModifiedList = TradingAnalysis.Where(tr => tr.Instrument.Sector.Equals(PreferredSector)).ToList(); } else { ModifiedList = TradingAnalysis; } var BuyOrdersForAccountBySector = from bp in ModifiedList where bp.HasValue && CustomerAccount.GetAvailableFunds( new List <ICurrency> { ImperaturGlobal.GetMoney(0m, bp.Instrument.CurrencyCode).CurrencyCode } ).FirstOrDefault().GreaterOrEqualThan(bp.QuoteFromInstrument.LastTradePrice) select new { Order = ImperaturGlobal.Kernel.Get <IOrder>( new Ninject.Parameters.ConstructorArgument("Symbol", bp.Instrument.Symbol), new Ninject.Parameters.ConstructorArgument("Trigger", new List <ITrigger> { ImperaturGlobal.Kernel.Get <ITrigger>( new Ninject.Parameters.ConstructorArgument("m_oOperator", TriggerOperator.EqualOrless), new Ninject.Parameters.ConstructorArgument("m_oValueType", TriggerValueType.TradePrice), new Ninject.Parameters.ConstructorArgument("m_oTradePriceValue", bp.QuoteFromInstrument.LastTradePrice.Amount), new Ninject.Parameters.ConstructorArgument("m_oPercentageValue", 0m) ) }), new Ninject.Parameters.ConstructorArgument("AccountIdentifier", CustomerAccount.Identifier), new Ninject.Parameters.ConstructorArgument("Quantity", (int) CustomerAccount.GetAvailableFunds( new List <ICurrency> { ImperaturGlobal.GetMoney(0m, bp.Instrument.CurrencyCode).CurrencyCode } ).FirstOrDefault().Divide(bp.QuoteFromInstrument.LastTradePrice).Amount ), new Ninject.Parameters.ConstructorArgument("OrderType", OrderType.StopLoss), new Ninject.Parameters.ConstructorArgument("ValidToDate", DateTime.Now.AddDays(2)), new Ninject.Parameters.ConstructorArgument("ProcessCode", TradingForeCastPerSymbol.Where(br => br.Item1.Equals(bp.Instrument.Symbol)).First().Item2.ToString()), new Ninject.Parameters.ConstructorArgument("StopLossValidDays", 30), new Ninject.Parameters.ConstructorArgument("StopLossAmount", 0m), new Ninject.Parameters.ConstructorArgument("StopLossPercentage", 0.8m) ) }; return(BuyOrdersForAccountBySector.Where(i => i != null && i.Order != null && i.Order.Symbol != null).Select(i => i.Order).ToList()); }
public void UpdateAccountInfo(IAccountInterface AccountData) { m_oAccountData = AccountData; var newSymbolsToShow = from i in ImperaturGlobal.Instruments join a in m_oAccountData.GetAvailableFunds() on i.CurrencyCode equals a.CurrencyCode.CurrencyCode select i.Symbol; comboBox_Symbols.DataSource = newSymbolsToShow.ToList(); comboBox_Symbols.Refresh(); }
public SellDialog(IAccountHandlerInterface AccountHandler, IAccountInterface Account, string Ticker, int Quantity)//, ITradeHandlerInterface Tradehandler) { InitializeComponent(); oAH = AccountHandler; oA = Account; textBox_quantity.TextChanged += TextBox_quantity_TextChanged; oQ = Quantity; oT = Ticker; groupBox1.Text += ": " + Ticker; //m_oTradeHandler = Tradehandler; }
private bool SaveSingleAccount(IAccountInterface oA) { try { json.SerializeJSONdata.SerializeObject((Account)oA, string.Format(@"{0}\{1}\{2}.json", ImperaturGlobal.SystemData.SystemDirectory, ImperaturGlobal.SystemData.AcccountDirectory, oA.Identifier)); } catch (Exception ex) { ImperaturGlobal.GetLog().Error(string.Format("Couldn't save account {0} to file", oA.Identifier), ex); } return(true); }
private List <IOrder> GetSellOrderForSingleAccount(IAccountInterface CustomerAccount, List <ISecurityAnalysis> TradingAnalysis, List <Tuple <string, string> > TradingForeCastPerSymbol) { var ActualSellOrders = from bp in TradingAnalysis where bp.HasValue && CustomerAccount.GetHoldings().Count() > 0 && CustomerAccount.GetHoldings().Where(h => h.Symbol != null && h.Symbol.Equals(bp.Instrument.Symbol)).Count() > 0 && CustomerAccount.GetAverageAcquisitionCostFromHolding(bp.Instrument.Symbol).Multiply(1.02m).GreaterOrEqualThan(bp.QuoteFromInstrument.LastTradePrice) select new { Order = ImperaturGlobal.Kernel.Get <IOrder>( new Ninject.Parameters.ConstructorArgument("Symbol", bp.Instrument.Symbol), new Ninject.Parameters.ConstructorArgument("Trigger", new List <ITrigger> { ImperaturGlobal.Kernel.Get <ITrigger>( new Ninject.Parameters.ConstructorArgument("m_oOperator", TriggerOperator.EqualOrGreater), new Ninject.Parameters.ConstructorArgument("m_oValueType", TriggerValueType.TradePrice), new Ninject.Parameters.ConstructorArgument("m_oTradePriceValue", bp.QuoteFromInstrument.LastTradePrice.Amount), new Ninject.Parameters.ConstructorArgument("m_oPercentageValue", 0m) ) }), new Ninject.Parameters.ConstructorArgument("AccountIdentifier", CustomerAccount.Identifier), new Ninject.Parameters.ConstructorArgument("Quantity", Convert.ToInt32(CustomerAccount.GetHoldings().Where(h => h.Symbol.Equals(bp.Instrument.Symbol)).Sum(ho => ho.Quantity)) ), new Ninject.Parameters.ConstructorArgument("OrderType", OrderType.Sell), new Ninject.Parameters.ConstructorArgument("ValidToDate", DateTime.Now.AddDays(2)), new Ninject.Parameters.ConstructorArgument("ProcessCode", TradingForeCastPerSymbol.Where(br => br.Item1.Equals(bp.Instrument.Symbol)).First().Item2.ToString()), new Ninject.Parameters.ConstructorArgument("StopLossValidDays", 0), new Ninject.Parameters.ConstructorArgument("StopLossAmount", 0m), new Ninject.Parameters.ConstructorArgument("StopLossPercentage", 0m) ) }; return(ActualSellOrders.Select(i => i.Order).ToList()); }
public bool DepositAmount(Guid Identifier, IMoney Deposit) { IAccountInterface oA = m_oAccounts.Single(a => a.Identifier.Equals(Identifier)); try { oA.AddTransaction( ImperaturGlobal.Kernel.Get <ITransactionInterface>( new Ninject.Parameters.ConstructorArgument("_DebitAmount", Deposit), new Ninject.Parameters.ConstructorArgument("_CreditAmount", Deposit), new Ninject.Parameters.ConstructorArgument("_DebitAccount", oA.GetBankAccountsFromCache().First()), new Ninject.Parameters.ConstructorArgument("_CreditAccount", oA.Identifier), new Ninject.Parameters.ConstructorArgument("_TransactionType", TransactionType.Transfer), new Ninject.Parameters.ConstructorArgument("_SecurtiesTrade", (object)null) ) ); } catch (Exception ex) { LastErrorMessage = ex.Message; return(false); } return(true); }
public bool ExecuteOrder(IAccountHandlerInterface AccountHandler, ITradeHandlerInterface TradeHandler, out IOrder StopLossOrder) { StopLossOrder = this; if (EvaluateTriggerOnOrder()) { try { IAccountInterface oA = AccountHandler.GetAccount(m_oAccountIdentifier); switch (m_oOrderType) { case OrderType.Buy: oA.AddHoldingToAccount(m_oQuantity, m_oSymbol, TradeHandler); StopLossOrder = this; return(true); case OrderType.Sell: oA.SellHoldingFromAccount(m_oQuantity, m_oSymbol, TradeHandler); return(true); case OrderType.StopLoss: oA.AddHoldingToAccount(m_oQuantity, m_oSymbol, TradeHandler); StopLossOrder = CreateStopLossOrder(ImperaturGlobal.Quotes.Where(q => q.Symbol.Equals(m_oSymbol)).First().LastTradePrice.Amount); return(true); default: break; } } catch (Exception ex) { m_oLastErrorMessage = "OrderExecute error: " + ex.Message; return(false); } } return(false); }
public accountController(IAccountInterface accountInterface) { _accountInterface = accountInterface; }
private void Generate(IAccountInterface generator) { }
public LoginService(IAccountInterface account) { _accountInterface = account; }
public AccountController(IAccountInterface repository, IGuardInterface guardRepository) { this._repository = repository; this._repositoryGuard = guardRepository; }
public AccountController(IAccountInterface account, HttpResponses response) { _account = account; _response = response; }
public ImperaturWebService(IImperaturMarket imperaturMarket) { _imperaturMarket = imperaturMarket; string RestBase = "/api/"; Get["/"] = _ => View["index"]; Get[RestBase + "/accountsearch/{search}"] = parameters => { List <IAccountInterface> oIA = _imperaturMarket.GetAccountHandler().SearchAccount(parameters.search, AccountType.Customer); var feeds2 = oIA.Select (f => new { accountname = f.AccountName, availablefunds = f.GetAvailableFunds().First().ToString(), identifier = f.Identifier, totalfunds = f.GetTotalFunds().First().ToString() }).ToArray(); return(Response.AsJson(feeds2)); }; Get[RestBase + "/account"] = parameters => { List <IAccountInterface> oIA = _imperaturMarket.GetAccountHandler().Accounts(); var feeds2 = oIA.Where(x => x.GetAccountType().Equals(AccountType.Customer)).Select (f => new { accountname = f.AccountName, availablefunds = f.GetAvailableFunds().First().ToString(), identifier = f.Identifier, totalfunds = f.GetTotalFunds().First().ToString() }).ToArray(); return(Response.AsJson(feeds2)); }; Get[RestBase + "account/{id}"] = identifier => { IAccountInterface oA = _imperaturMarket.GetAccountHandler().GetAccount(new Guid(identifier.id)); List <ICurrency> FilterCurrency = new List <ICurrency>(); FilterCurrency.Add(ImperaturGlobal.GetSystemCurrency()); IMoney AvailableSystemAmount = oA.GetAvailableFunds(FilterCurrency).First(); IMoney TotalFunds = oA.GetTotalFunds(FilterCurrency).First(); IMoney TotalDeposit = oA.GetDepositedAmount(FilterCurrency).First(); var feeds2 = new { accountname = oA.AccountName, availablefunds = oA.GetAvailableFunds().First().ToString(), identifier = oA.Identifier, totalfunds = oA.GetTotalFunds().First().ToString(), change = string.Format("{0}%", TotalDeposit.Amount > 0 ? TotalFunds.Subtract(TotalDeposit.Amount).Divide(TotalDeposit.Amount).Multiply(100).ToString(true, false) : "0"), transactions = oA.Transactions.Select(t => new { transdate = t.TransactionDate, amount = t.CreditAmount.ToString(), transactiontype = t.TransactionType.ToString() }).ToArray(), customername = oA.GetCustomer().FullName, holdings = oA.GetHoldings().Select(h => new { name = h.Name, change = h.Change.ToString(), aac = oA.GetAverageAcquisitionCostFromHolding(h.Name).ToString(), purchaseamount = h.PurchaseAmount.ToString() }), orders = _imperaturMarket.OrderQueue.GetOrdersForAccount(new Guid(identifier.id)).Select(o => new { ordertype = o.OrderType.ToString(), symbol = o.Symbol, quantity = o.Quantity.ToString(), validtodate = o.ValidToDate.ToString() }) }; return(Response.AsJson(feeds2)); }; Get[RestBase + "acount/{id}/holdings"] = identifier => { List <Imperatur_v2.trade.Holding> oH = _imperaturMarket.GetAccountHandler().GetAccount(new Guid(identifier.id)).GetHoldings(); var holdings = oH.Select(h => new { name = h.Name, change = h.Change, symbol = h.Symbol, currentamount = h.CurrentAmount }).ToArray(); return(Response.AsJson(holdings)); }; }
public void UpdateAcountInfo(IAccountInterface AccountData) { m_oA = AccountData; try { AccountMainInfo = new CreateInfoControlFromObject(AccountData, "Account main info", new string[] { "Name", "AccountType", "Customer" }); AccountMainInfo.Name = "AccountMainInfo"; if (!tableLayoutPanel_maininfo.Controls.ContainsKey(AccountMainInfo.Name)) { tableLayoutPanel_maininfo.Controls.Add(AccountMainInfo, 0, 0); } else { tableLayoutPanel_maininfo.Controls.RemoveByKey(AccountMainInfo.Name); tableLayoutPanel_maininfo.Controls.Add(AccountMainInfo, 0, 0); } DataGridView AvilableFundsGrid = new DataGridView(); AvilableFundsGrid.AutoGenerateColumns = false; AvilableFundsGrid.AllowUserToAddRows = false; AvilableFundsGrid.Columns.Add( new DataGridViewTextBoxColumn() { CellTemplate = new DataGridViewTextBoxCell(), Name = "Amount", HeaderText = "Amount", DataPropertyName = "Amount", ReadOnly = true } ); DataTable AvilableFundsDT = new DataTable(); AvilableFundsDT.Columns.Add("Amount"); DataRow row = null; foreach (IMoney oM in AccountData.GetAvailableFunds()) { row = AvilableFundsDT.NewRow(); row["Amount"] = oM.ToString(true, true); AvilableFundsDT.Rows.Add(row); } AvilableFundsGrid.DataSource = AvilableFundsDT; AvilableFundsGrid.Dock = DockStyle.Top; AccountMainAvailableFunds = new CreateDataGridControlFromObject( new DataGridForControl { DataGridViewToBuild = AvilableFundsGrid, GroupBoxCaption = "Available Funds" } ); AccountMainAvailableFunds.Name = "AccountMainAvailableFunds"; if (!tableLayoutPanel_maininfo.Controls.ContainsKey(AccountMainAvailableFunds.Name)) { tableLayoutPanel_maininfo.Controls.Add(AccountMainAvailableFunds, 0, 1); } else { tableLayoutPanel_maininfo.Controls.RemoveByKey(AccountMainAvailableFunds.Name); tableLayoutPanel_maininfo.Controls.Add(AccountMainAvailableFunds, 0, 1); } } catch (Exception ex) { int gg = 0; } if (AccountMainInfo != null) { AccountMainInfo.Refresh(); } if (AccountMainAvailableFunds != null) { AccountMainAvailableFunds.Refresh(); } ShowOrders(m_oA.Identifier); }
public void UpdateAccountInfo(IAccountInterface AccountData) { m_oA = AccountData; if (listView_holdings.Items.Count > 0) { listView_holdings.Items.Clear(); } foreach (Holding oH in AccountData.GetHoldings()) { ListViewItem oHoldingRow = new ListViewItem( new string[] { oH.Name, oH.Quantity.ToString(), oH.PurchaseAmount.ToString(), string.Format("{0} / {1}", oH.Change.ToString(true, true), Math.Round(oH.ChangePercent, 2, MidpointRounding.AwayFromZero).ToString() + " %"), oH.CurrentAmount.ToString(), m_oA.GetAverageAcquisitionCostFromHolding(oH.Name).ToString(), "Sell", "Info" } ); oHoldingRow.SubItems.Add(oH.Name); oHoldingRow.Tag = oH.Name.ToString(); listView_holdings.Items.Add(oHoldingRow); } listView_holdings.Refresh(); if (listView_holdings.Items.Count == 1) { //Show the selected symbol in the trade OnSelectedSymbol(new SelectedSymbolEventArg() { Symbol = listView_holdings.Items[0].Tag.ToString() }); } DataTable TotalAvilableFundsDT = new DataTable(); TotalAvilableFundsDT.Columns.Add("Deposit"); TotalAvilableFundsDT.Columns.Add("Amount"); TotalAvilableFundsDT.Columns.Add("Change"); List <IMoney> TotalFundsList = AccountData.GetTotalFunds() ?? new List <IMoney>(); List <IMoney> TotalDeposit = AccountData.GetDepositedAmount() ?? new List <IMoney>(); DataRow row = null; foreach (IMoney oM in TotalFundsList) { row = TotalAvilableFundsDT.NewRow(); row["Deposit"] = TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().ToString(); row["Amount"] = oM.ToString(true, true); row["Change"] = string.Format("{0} / {1}", oM.Subtract(TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First()).ToString(), string.Format("{0}%", TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount > 0 ? oM.Subtract(TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount).Divide(TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount).Multiply(100).ToString(true, false) : "0") ); //row["ChangePercent"] = string.Format("{0}%", TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount > 0 ? oM.Subtract(TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount).Divide(TotalDeposit.Where(od => od.CurrencyCode.Equals(oM.CurrencyCode)).First().Amount).Multiply(100).ToString(true, false) : "0"); TotalAvilableFundsDT.Rows.Add(row); } TotalAvilableFundsGrid.DataSource = TotalAvilableFundsDT; TotalAvilableFundsGrid.Dock = DockStyle.Top; TotalAvilableFundsGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; TotalAvilableFundsGrid.CellFormatting += TotalAvilableFundsGrid_CellFormatting; TotalAvailableFunds = new CreateDataGridControlFromObject( new DataGridForControl { DataGridViewToBuild = TotalAvilableFundsGrid, GroupBoxCaption = "Current Funds" } ); TotalAvailableFunds.Name = "AccountMainAvailableFunds"; if (!tableLayoutPanel1.Controls.ContainsKey(TotalAvailableFunds.Name)) { tableLayoutPanel1.Controls.Add(TotalAvailableFunds, 0, 2); } else { tableLayoutPanel1.Controls.RemoveByKey(TotalAvailableFunds.Name); tableLayoutPanel1.Controls.Add(TotalAvailableFunds, 0, 2); } }