private void btnUpdate_Click(object sender, EventArgs e) { string algo = "" + this.comboAlgorithm.SelectedItem; string price = "" + this.tbNewPrice.Text; string limit = "" + this.tbNewLimit.Text; string id = "" + this.tbId.Text; JObject order = ac.updateOrder(algo, id, price, limit); if (order["id"] != null) { this.lblErrorCreate.Visible = false; setEditMode(order); } }
private void runBot() { if (!botRunning) { return; } //read needed data String fileName = Path.Combine(Directory.GetCurrentDirectory(), "bot.json"); if (!File.Exists(fileName)) { return; } toolStripStatusLabel1.Text = "Working"; BotSettings saved = JsonConvert.DeserializeObject <BotSettings>(File.ReadAllText(@fileName)); Console.WriteLine("bot iteration tasks {0} {1} {2}", saved.reffilOrder, saved.lowerPrice, saved.increasePrice); Control.CheckForIllegalCrossThreadCalls = false; refreshOrders(true); if (saved.lowerPrice || saved.increasePrice) { refreshMarket(); } //do refill?? Console.WriteLine("orders to process: {0}", orders.Count); if (saved.reffilOrder) { foreach (JObject order in orders) { float payed = float.Parse("" + order["payedAmount"], CultureInfo.InvariantCulture); float available = float.Parse("" + order["availableAmount"], CultureInfo.InvariantCulture); float spent_factor = payed / available * 100; Console.WriteLine("?refill?; order {0}, payed {1}, available {2}, percent {3}", order["id"], payed, available, spent_factor.ToString("0.00")); if (spent_factor > 90) { JObject algo = ac.getAlgo("" + order["algorithm"]["algorithm"]); Console.WriteLine("===> refill order for {0}", algo["minimalOrderAmount"]); ac.refillOrder("" + order["id"], "" + algo["minimalOrderAmount"]); } } } //do speed adjust?? if (saved.lowerPrice || saved.increasePrice) { foreach (JObject order in orders) { string order_type = "" + order["type"]["code"]; if (order_type.Equals("STANDARD")) { JObject algo = ac.getAlgo("" + order["algorithm"]["algorithm"]); float order_speed = float.Parse("" + order["acceptedCurrentSpeed"], CultureInfo.InvariantCulture); float order_price = float.Parse("" + order["price"], CultureInfo.InvariantCulture); float price_step_down = float.Parse("" + algo["priceDownStep"], CultureInfo.InvariantCulture); Console.WriteLine("?adjust price?; order {0}, speed {1}, price {2}, step_down {3}", order["id"], order_speed, order_price, price_step_down); if (saved.increasePrice && order_speed == 0) { float new_price = (float)Math.Round(order_price + (price_step_down * -1), 4); Console.WriteLine("===> price up order to {0}", new_price); ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]); } else if (saved.lowerPrice && order_speed > 0) { Dictionary <string, float> market = getOrderPriceRangesForAlgoAndMarket("" + order["algorithm"]["algorithm"], "" + order["market"]); var list = market.Keys.ToList(); list.Sort(); int idx = 0; foreach (var key in list) { float curr_tier_price = float.Parse(key, CultureInfo.InvariantCulture); if (key.Equals("" + order_price)) { break; } idx++; } if (idx > 1) { float new_price = (float)Math.Round(order_price + price_step_down, 4); Console.WriteLine("===> price down order to {0}", new_price); ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]); } } } } } toolStripStatusLabel1.Text = "Idle"; }