Example #1
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);
        }
Example #2
0
        public async Task <OrderData> entry(double p, double size, string order)
        {
            var res = await FlyerAPI2.sendChiledOrderAsync(order, p, size, 10);

            if (res.order_id.Contains("JRF"))
            {
                addOrder(DateTime.Now, p, size, res.order_id, "ACTIVE", order);
                Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("new entry for " + order + ": price=" + p + ": size=" + size + ": id=" + res.order_id); }));
                takeLog(DateTime.Now + ": new entry for " + order + ": price=" + p + ": size=" + size + ": id=" + res.order_id);
                Log.addLog("Account-Entry", ": new entry for " + order + ": price=" + p + ": size=" + size + ": id=" + res.order_id);
            }
            else
            {
                takeLog("failed new entry, price=" + p);
                Log.addLog("Account-Entry", "failed new entry, price=" + p);
                Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("failed new entry for " + order + ": price=" + p + ": size=" + size + ": id=" + res.order_id); }));
            }
            return(res);
        }
Example #3
0
        private async void buttonSendOrder_Click(object sender, EventArgs e)
        {
            if (SystemFlg.getMarketDataFlg() == false)
            {
                MarketData.startMarketData();
                await Task.Delay(3000);
            }


            var board = await FlyerAPI2.getBoardAsync("FX_BTC_JPY");

            double price = board.Asks.Select(x => x.Price).ToList().Min() - 1;

            var res = await FlyerAPI2.sendChiledOrderAsync("SELL", price, 0.01, 1);

            if (res.order_id != "")
            {
                addListBox2("completed send order:" + res.order_id);
            }

            if (id == "")
            {
                id = res.order_id;
            }


            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            bool   flg   = true;
            string dotti = "";

            while (flg)
            {
                var exe = await FlyerAPI2.getExecutionsAcceptanceIDAsync(res.order_id);

                System.Diagnostics.Debug.WriteLine(exe);
                if (exe.Count > 0)
                {
                    if (exe[0].child_order_accesptance_id == res.order_id)
                    {
                        flg   = false;
                        dotti = "getExecutionsAcceptanceIDAsync";
                    }
                }
                if (MarketDataLog.getExecutionStatus(res.order_id))
                {
                    flg   = false;
                    dotti = "getExecutionStatus";
                }
            }

            sw.Stop();
            id = res.order_id;
            Form1Instance.addListBox2(res.order_id + ":time=" + sw.ElapsedMilliseconds + ", dotti=" + dotti);

            SystemFlg.setMarketDataFlg(false);
            SystemFlg.setDBWriterFlg(false);

            /*
             * var board2 = await FlyerAPI2.getBoardAsync("FX_BTC_JPY");
             * var res2 = await FlyerAPI2.sendChiledOrderAsync("SELL", board2.Asks.Select(x => x.Price).ToList().Max()-1, 0.01, 1);
             *
             * var exe2 = await FlyerAPI2.getExecutionsAcceptanceIDAsync(res2.order_id);
             *
             * var posi2 = await FlyerAPI2.getPositionsAsync();
             */
        }
Example #4
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("");
        }