public void Test2Sell() { SellRequest sell = new SellRequest(); if (buy[0] != 1) { Assert.AreNotEqual(-1, sell.SendSellRequest(1000, 5, 3)); } else { Assert.AreEqual(-1, sell.SendSellRequest(1000, 5, 3)); } }
private void ButtonSell_Click(object sender, RoutedEventArgs e) { myLogger.Info("Sell button was pressed"); string c = commodity.Text; string a = amount.Text; string p = price.Text; if (c.Length != 0 & a.Length != 0 & p.Length != 0) { int cI = Convert.ToInt32(c); int aI = Convert.ToInt32(a); int pI = Convert.ToInt32(p); SellRequest SR = new SellRequest(); int output = SR.SendSellRequest(pI, cI, aI); if (output == -1) { MessageBox.Show("Failed"); } else { MessageBox.Show("The sell is done:request id:" + output); EnterHistory("Sell", cI, aI, pI, output, false); } } else { MessageBox.Show("full all the fields"); } commodity.Text = ""; amount.Text = ""; price.Text = ""; }
private void onTimedEvent(Object source, ElapsedEventArgs e) { sql.close(); sql.connect(); MarketUserData MYUSER = new MarketUserData(); MarketUserData myUser = MYUSER.SendQueryUserRequest(); AllMarketCommodityOffer MACO = new AllMarketCommodityOffer(); List <ComInfo> cominfo = MACO.SendQueryAllMarketRequest(); SqlDataReader rdr = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where buyer = 20) commodity group by commodity order by commodity"); int counterS = 0; string Scom = ""; while (counterS < 10 && rdr.Read()) { Scom = "" + rdr["commodity"]; if (Convert.ToInt32(Scom) > 3 && myUser.commodities[Scom] > 1) { SellRequest SR = new SellRequest(); int price = Math.Max(Convert.ToInt32(rdr["average"]) + Convert.ToInt32(rdr["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr["commodity"])].info.bid); int amount = Convert.ToInt32(myUser.commodities[Scom] / 20) + 1; int commodity = Convert.ToInt32(rdr["commodity"]); int response = SR.SendSellRequest(price, commodity, amount); if (response != -1) { DateTime date = DateTime.Now; string sdate = date.ToString(); HistoryItem h = new HistoryItem("Sell", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr["commodity"]), true, sdate); // MessageBox.Show("SellDone");//for test App.Current.Dispatcher.Invoke((Action) delegate { mainWin.History.Insert(0, h); }); string path = "..\\History.txt"; using (StreamWriter wr = File.AppendText(path)) { wr.WriteLine("Request"); wr.WriteLine("sell"); wr.WriteLine(response); wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 20) + 1); wr.WriteLine(price); wr.WriteLine(Convert.ToInt32(rdr["commodity"])); wr.WriteLine("true"); wr.WriteLine(sdate.ToString()); } } counterS++; } } rdr.Close(); SqlDataReader rdr2 = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where seller = 20) commodity group by commodity order by commodity"); int counterB = 0; while (counterB < 10 && rdr2.Read()) { Scom = "" + rdr2["commodity"]; if (Convert.ToInt32(Scom) > 3 && myUser.funds > 5000) { BuyRequest SB = new BuyRequest(); int price = Math.Min(Convert.ToInt32(rdr2["average"]) - Convert.ToInt32(rdr2["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr2["commodity"])].info.ask); int response = SB.sendBuyRequest(price, Convert.ToInt32(rdr2["commodity"]), Convert.ToInt32(myUser.commodities[Scom] / 20) + 1); if (response != -1) { DateTime date = DateTime.Now; string sdate = date.ToString(); HistoryItem h = new HistoryItem("Buy", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr2["commodity"]), true, sdate); //MessageBox.Show("BuyDone");//for test App.Current.Dispatcher.Invoke((Action) delegate { mainWin.History.Insert(0, h); }); string path = "..\\History.txt"; using (StreamWriter wr = File.AppendText(path)) { wr.WriteLine("Request"); wr.WriteLine("buy"); wr.WriteLine(response); wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 10) + 1); wr.WriteLine(price); wr.WriteLine(Convert.ToInt32(rdr2["commodity"])); wr.WriteLine("true"); wr.WriteLine(sdate.ToString()); } } } counterB++; } rdr2.Close(); sql.close(); }