public bool CanBuy(int Amount, int UnderStock) { if (Amount > 0 && UnderStock > 0 && UnderStock <= Amount && Amount <= Stock) { PriceMap PM = new PriceMap(Prices); if (!double.IsNaN(PM.getValue(Amount, 0))) { return(true); } return(!double.IsNaN(PM.getValue(UnderStock, 0))); } return(false); }
public BitTransaction Buy(int amount, int understock) { BitTransaction BT = null; PriceMap PM = new PriceMap(Prices); if (CanBuy(amount, understock)) { if (!double.IsNaN(PM.getValue(amount, 0))) { BT = new BitTransaction(this); BT.Amount = amount; } if (!double.IsNaN(PM.getValue(understock, 0))) { BT = new BitTransaction(this); BT.Amount = understock; } } return(BT); }
private bool setOffer(BitOffer BO, GenericMessage M) { if (getValue(M.RawContent, "Title") != null) { try { BO.Title = getValue(M.RawContent, "Title"); } catch (Exception ex) { sendErr(new GenericMessage() { Receiver = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } if (getValue(M.RawContent, "Description") != null) { try { BO.Description = Encoding.UTF8.GetString(A85(getValue(M.RawContent, "Description"))); } catch (Exception ex) { sendErr(new GenericMessage() { Receiver = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } if (getValue(M.RawContent, "Category") != null) { int cat = 0; if (int.TryParse(getValue(M.RawContent, "Category"), out cat) && cat > -3 && cat != 0) { try { BitCategory BC = new BitCategory(cat); BO.Category = cat; } catch (Exception ex) { sendErr(new GenericMessage() { Sender = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } } if (getValue(M.RawContent, "Files") != null) { string[] fIndexes = getValue(M.RawContent, "Files").Split(','); if (fIndexes.Length > 1 || !string.IsNullOrEmpty(fIndexes[0].ToString())) { try { for (int i = 0; i < fIndexes.Length; i++) { int.Parse(fIndexes[i]); } BO.Files = getValue(M.RawContent, "Files"); } catch (Exception ex) { sendErr(new GenericMessage() { Receiver = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } else { } } if (getValue(M.RawContent, "Stock") != null) { try { int sCount = int.Parse(getValue(M.RawContent, "Stock")); if (sCount > -2) { BO.Stock = sCount; } else { throw new Exception("Invalid stock count"); } } catch (Exception ex) { sendErr(new GenericMessage() { Receiver = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } if (getValue(M.RawContent, "PriceMap") != null) { try { PriceMap PM = new PriceMap(getValue(M.RawContent, "PriceMap")); BO.Prices = PM.ToString(); } catch (Exception ex) { sendErr(new GenericMessage() { Receiver = M.Sender, RawContent = "Cannot edit the offer: " + ex.Message, Server = M.Server }); return(false); } } return(true); }