Пример #1
0
        private async void buttonGetOrders_Click(object sender, EventArgs e)
        {
            Form1Instance.initializeListBox();
            var res5 = await FlyerAPI2.getChildOrderAsync("ACTIVE");

            foreach (var v in res5)
            {
                Form1Instance.addListBox(v.child_order_date + " - " + v.side + " - " + v.price + "*" + v.size + " - " + v.child_order_acceptance_id);
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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("");
        }