public TransationResult EmmitPurchaseOrder(int diginotesAmmount, int userId) { //ve se tem salto suficiente para comprar decimal currentQuote = GetCurrentQuote(); decimal pendingMoney = 0; List <BuyOrder> userBuyOrders = serverHandler.GetUserBuyOrders(userId); if (userBuyOrders != null) { for (int j = 0; j < userBuyOrders.Count; j++) { pendingMoney += userBuyOrders[i].nDiginotes * currentQuote; } } if ((currentQuote * diginotesAmmount > (serverHandler.GetUserBalance(userId) - pendingMoney)) || (diginotesAmmount < 1)) { return(TransationResult.DIGINOTES_ERROR); } //Create sell order int buyOrderId = serverHandler.AddBuyOrder(diginotesAmmount, userId, false); if (buyOrderId == -1) { return(TransationResult.ERROR); } //Is there buyers that can buy? List <SellOrder> sellingOrdersIDsList = serverHandler.GetSellingOrdersList(); if (sellingOrdersIDsList == null) { return(TransationResult.PARTIAL); } //For each buy order, see if it can fulfill atleast part, when you get full, it means I sold everything for (int i = 0; i < sellingOrdersIDsList.Count; i++) { if (!sellingOrdersIDsList[i].suspended) { TransationResult transactionRes = serverHandler.MakeBuyTransaction(sellingOrdersIDsList[i].id, buyOrderId); NotifyClients(EventOperation.TRANSACTION, sellingOrdersIDsList[i].userID); if (transactionRes == TransationResult.FULL) { return(TransationResult.FULL); } } } //Sold nothing return(TransationResult.PARTIAL); }
//Emmits a sell order (should change quota with result = PARTIAL) public TransationResult EmmitSellOrder(int diginotesAmmount, int userId) { decimal pendingDiginotes = 0; List <SellOrder> userSellOrders = serverHandler.GetUserSellOrders(userId); if (userSellOrders != null) { for (int j = 0; j < userSellOrders.Count; j++) { pendingDiginotes += userSellOrders[i].nDiginotes; } } if (diginotesAmmount > (GetDiginotesNumber(userId) - pendingDiginotes) || diginotesAmmount < 1) { return(TransationResult.DIGINOTES_ERROR); } //Create sell order int sellOrderId = serverHandler.AddSellOrder(diginotesAmmount, userId, false); if (sellOrderId == -1) { return(TransationResult.ERROR); } //Is there buyers that can buy? List <BuyOrder> buyingOrdersIDsList = serverHandler.GetBuyingOrdersList(); if (buyingOrdersIDsList == null) { return(TransationResult.PARTIAL); } //For each buy order, see if it can fulfill atleast part, when you get full, it means I sold everything for (int i = 0; i < buyingOrdersIDsList.Count; i++) { if (!buyingOrdersIDsList[i].suspended) { TransationResult transactionRes = serverHandler.MakeSellTransaction(sellOrderId, buyingOrdersIDsList[i].id); NotifyClients(EventOperation.TRANSACTION, buyingOrdersIDsList[i].userID); if (transactionRes == TransationResult.FULL) { return(TransationResult.FULL); } } } //Sold nothing return(TransationResult.PARTIAL); }