public async Task <string> cancelAllOrders() { var ord = getAllOrders(); string res = ""; for (int i = 0; i < ord.Count; i++) { if (ord[i].order_status != "CANCELLING") { res = await FlyerAPI2.cancelChildOrdersAsync(ord[i].order_id); if (res == "") { updateOrderStatus("CANCELLING", ord[i].order_id); takeLog(DateTime.Now + ": cancelling " + ord[i].order_side + " for " + ord[i].order_price + " x " + ord[i].order_lot + " id=" + ord[i].order_id); Log.addLog("Accoubt-getAllOrders", ": cancelling " + ord[i].order_side + " for " + ord[i].order_price + " x " + ord[i].order_lot + " id=" + ord[i].order_id); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("cancelling " + ord[i].order_side + " for " + ord[i].order_price + " x " + ord[i].order_lot + " id=" + ord[i].order_id); })); cancelling = true; } else { takeLog("failed cancel all orders: " + res); Log.addLog("Accoubt-getAllOrders", "failed cancel all orders: " + res); } } } return(res); }
private async void buttonCancelOrder_Click(object sender, EventArgs e) { /* * var res8 = await FlyerAPI2.cancelAllChildOrdersAsync(); * Form1Instance.addListBox(res8); */ System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var r = await FlyerAPI2.cancelChildOrdersAsync(id); addListBox2(r); sw.Stop(); addListBox2("time=" + sw.ElapsedMilliseconds); }
private async void buttonGetExecutionsId_Click(object sender, EventArgs e) { var buy = await FlyerAPI2.sendChiledOrderAsync("BUY", 600000, 0.01, 1); var res = await FlyerAPI2.getExecutionsAcceptanceIDAsync(buy.order_id); if (res.Count > 0) { this.addListBox(res[0].exec_date.ToLongTimeString()); } var cancel = await FlyerAPI2.cancelChildOrdersAsync(buy.order_id); var active = await FlyerAPI2.getChildOrderAsync("ACTIVE"); this.addListBox("active order=" + active.Count); }
public async Task <string> cancelOrder(string id) { string res = ""; if (getOrderStatus(id) != "CANCELLING") { res = await FlyerAPI2.cancelChildOrdersAsync(id); if (res == "") { var ord = getAllOrders().Where(x => x.order_id == id).ToList(); if (ord.Count > 0) { if (ord[0].order_status != "CANCELLING") { takeLog(DateTime.Now + ": cancelling " + ord[0].order_side + " for " + ord[0].order_price + " x " + ord[0].order_lot + " id=" + ord[0].order_id); Log.addLog("Account-CancelOrder", ": cancelling " + ord[0].order_side + " for " + ord[0].order_price + " x " + ord[0].order_lot + " id=" + ord[0].order_id); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("cancelling " + ord[0].order_side + " for " + ord[0].order_price + " x " + ord[0].order_lot + " id=" + ord[0].order_id); })); updateOrderStatus("CANCELLING", id); cancelling = true; } } } else { takeLog("failed cancel order: " + res); Log.addLog("Account-CancelOrder", "failed cancel order, id= " + id + " res=" + res); res = "error"; } } else { res = "alreday cancelling"; } return(res); }
private async Task <string> checkCancel() { await Task.Run(async() => { while (SystemFlg.getMMFlg()) { if (cancelling) { var order = await FlyerAPI2.sendChiledOrderAsync("BUY", MarketDataLog.getLastExecutionsData().price - 100000, 0.01, 1); //send dummy order Log.addLog("Account-CheckCancel", "sendChiledOrderAsync-dummy"); var ord_dt = DateTime.Now; if (order.order_id.Contains("JRF")) { bool flg = true; do { if (FlyerAPI2.getApiAccessProhibition() == false) { var orders = await FlyerAPI2.getChildOrderAsync("ACTIVE");//get current active orders Log.addLog("Account-CheckCancel", "getChildOrderAsync-ACTIVE"); var dt = DateTime.Now; var orders_id = orders.Select(x => x.child_order_acceptance_id).ToList(); if (orders_id.Contains(order.order_id)) //when the dummy order is in the active order list { //treat all cancelling status orders not exist in order list as properlly cancelled var ord = getAllOrders(); int num_cancelling = 0; for (int i = 0; i < ord.Count; i++) { if (ord[i].order_status == "CANCELLING" && dt > ord[i].order_dt) { num_cancelling++; //if (orders_id.Contains(ord[i].order_id))// { takeLog(DateTime.Now + ": cancelled " + ord[i].order_side + ", price=" + ord[i].order_price + " x " + ord[i].order_lot); Log.addLog("Account-CheckCancel", "cancelled " + ord[i].order_side + ", price=" + ord[i].order_price + " x " + ord[i].order_lot); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("cancelled " + ord[i].order_side + ", price=" + ord[i].order_price + " x " + ord[i].order_lot); })); removeOrder(ord[i].order_id); } } } if (num_cancelling == 0)//cancel dummy order and stop current checking { string res = "error"; do { res = await FlyerAPI2.cancelChildOrdersAsync(order.order_id); flg = false; cancelling = false; Log.addLog("Account-CheckCancel", "num cancelling = 0, res=" + res); } while (res == "error"); } else if ((DateTime.Now - ord_dt).Seconds > 60) { flg = false; } } } await Task.Delay(500); } while (flg); } } else { Log.addLog("Account-CheckCancel", "cancelling = false, num orders=" + getNumCurrentOrders()); await Task.Delay(1000); } } }); return(""); }