private void buyAskLowerThanBid() { updateCommodities(); Commodity[] askLowerThanBid = _commodities.Where(x => x.getAskToBid() < 1).ToArray(); //wait(askLowerThanBid.Length); foreach (Commodity comm in askLowerThanBid) { int toBuy = checkAmountToBuy(comm); _marketClient.SendBuyRequest(comm.info.ask, comm.id, toBuy); } }
//Those functions Prepare the string recieved from the Parser and send it to the relevant function in market client //Buy Request public void buy(String str) { String[] words = str.Split(' '); if (words.Length == 3) { int commodity = idStringToInt(words[0], -1, "commodity"); int amount = generalStringToInt(words[1], 0, "The amount should be a number different then 0"); int price = generalStringToInt(words[2], 0, "The price should be a number different then 0"); //goes to buy request if (commodity >= 0 && amount != 0 && price != 0) { int resp = marketClient.SendBuyRequest(price, commodity, amount); if (resp >= 0) { Console.WriteLine("Success! Trade id: " + resp); } } } else { printNoValidCommandError(); } }