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());
        }
        private void TextBox_Quantity_KeyDown(object sender, KeyEventArgs e)
        {
            int  QuantityToBuy;
            bool isNumeric = int.TryParse(textBox_Quantity.Text.Trim(), out QuantityToBuy);

            if (m_oAccountData != null && isNumeric && comboBox_Symbols.SelectedItem != null && comboBox_Symbols.SelectedItem.ToString().Length > 0)
            {
                IMoney MarketValue = ImperaturGlobal.Quotes.Where(q => q.Symbol.Equals(comboBox_Symbols.SelectedItem.ToString())).First().LastTradePrice.Multiply(Convert.ToDecimal(QuantityToBuy));
                if (
                    MarketValue.Amount >
                    m_oAccountData.GetAvailableFunds().Where(m => m.CurrencyCode.Equals(MarketValue.CurrencyCode)).First().Amount
                    )
                {
                    button_BuySecurity.Enabled = false;
                    return;
                }
                else
                {
                    button_BuySecurity.Enabled = true;
                }
            }

            if (e.KeyCode == Keys.Enter)
            {
                button_BuySecurity_Click(this, null);
            }
        }
        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();
        }
Beispiel #4
0
        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));
            };
        }
Beispiel #5
0
        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);
        }