예제 #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));
            };
        }
예제 #2
0
        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);
            }
        }