Esempio n. 1
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));
            };
        }
Esempio n. 2
0
        private void button_Show_Transactions_Click(object sender, EventArgs e)
        {
            if (m_oA == null)
            {
                return;
            }
            MessageBox.Show(string.Join(", ", m_oA.GetSymbolInHoldings()));

            DataGridView TransactionGrid = new DataGridView();

            TransactionGrid.AutoGenerateColumns = false;
            TransactionGrid.AllowUserToAddRows  = false;

            TransactionGrid.Columns.Add(
                new DataGridViewTextBoxColumn()
            {
                CellTemplate     = new DataGridViewTextBoxCell(),
                Name             = "Amount",
                HeaderText       = "Amount",
                DataPropertyName = "Amount",
                ReadOnly         = true
            }
                );
            TransactionGrid.Columns.Add(
                new DataGridViewTextBoxColumn()
            {
                CellTemplate     = new DataGridViewTextBoxCell(),
                Name             = "TransactionDate",
                HeaderText       = "Date",
                DataPropertyName = "TransactionDate",
                ReadOnly         = true
            }
                );
            TransactionGrid.Columns.Add(
                new DataGridViewTextBoxColumn()
            {
                CellTemplate     = new DataGridViewTextBoxCell(),
                Name             = "TransactionType",
                HeaderText       = "Type",
                DataPropertyName = "TransactionType",
                ReadOnly         = true
            }
                );
            TransactionGrid.Columns.Add(
                new DataGridViewTextBoxColumn()
            {
                CellTemplate     = new DataGridViewTextBoxCell(),
                Name             = "Symbol",
                HeaderText       = "Symbol",
                DataPropertyName = "Symbol",
                ReadOnly         = true
            }
                );
            TransactionGrid.Columns.Add(
                new DataGridViewTextBoxColumn()
            {
                CellTemplate     = new DataGridViewTextBoxCell(),
                Name             = "Revenue",
                HeaderText       = "Revenue",
                DataPropertyName = "Revenue",
                ReadOnly         = true
            }
                );

            DataTable TransactionsDT = new DataTable();

            TransactionsDT.Columns.Add("Amount");
            TransactionsDT.Columns.Add("TransactionDate");
            TransactionsDT.Columns.Add("TransactionType");
            TransactionsDT.Columns.Add("Symbol");
            TransactionsDT.Columns.Add("Revenue");

            DataRow row = null;

            foreach (ITransactionInterface oT in m_oA.Transactions)
            {
                row                    = TransactionsDT.NewRow();
                row["Amount"]          = oT.DebitAccount.Equals(m_oA.Identifier) ? oT.DebitAmount.ToString() : oT.CreditAmount.ToString();
                row["TransactionDate"] = oT.TransactionDate;
                row["TransactionType"] = oT.TransactionType.ToString();
                row["Symbol"]          = oT.SecuritiesTrade != null ? oT.SecuritiesTrade.Security.Symbol : "";
                row["Revenue"]         = oT.SecuritiesTrade != null && oT.SecuritiesTrade.Revenue != null?oT.SecuritiesTrade.Revenue.ToString() : "";

                TransactionsDT.Rows.Add(row);
            }
            TransactionGrid.DataSource       = TransactionsDT;
            TransactionGrid.Dock             = DockStyle.Fill;
            TransactionGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;

            UserControl TransactionControl = new CreateDataGridControlFromObject(
                new DataGridForControl
            {
                DataGridViewToBuild = TransactionGrid,
                GroupBoxCaption     = string.Format("Transactions on {0}", m_oA.GetCustomer().FullName)
            }
                );

            Form Ftrans = new Form();

            Ftrans.Controls.Add(TransactionControl);
            Ftrans.ShowDialog();


            //window.ShowDialog();
        }