示例#1
0
        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);
        }
示例#2
0
        public static async void startBoardUpdate()
        {
            initialize();

            await Task.Run(async() =>
            {
                while (SystemFlg.getMarketDataFlg())
                {
                    if (FlyerAPI2.getApiAccessProhibition() == false)
                    {
                        var board = await FlyerAPI2.getBoardAsync("FX_BTC_JPY");

                        if (board.MidPrice != 0)
                        {
                            board.dt  = DateTime.Now;
                            var ask_p = board.Asks.Select(c => c.Price).ToArray();
                            var bid_p = board.Bids.Select(c => c.Price).ToArray();

                            var ask_min = ask_p.Min();
                            var bid_max = bid_p.Max();

                            board.spread = ask_min - bid_max;
                            setCurrentBoard(board);
                            MarketDataLog.addBoardData(board.dt, new double[] { bid_max, ask_min, board.spread });
                            Form1.Form1Instance.Invoke((Action)(() =>
                            {
                                Form1.Form1Instance.setLabel3(board.spread.ToString());
                            }));
                        }
                    }
                    //await Task.Delay(0);
                }
            });
        }
示例#3
0
        private async void button1_Click(object sender, EventArgs e) //get posisiont
        {
            var positions = await FlyerAPI2.getPositionsAsync();

            for (int i = 0; i < positions.Count; i++)
            {
                addListBox(positions[i].side + ":" + positions[i].size + "@" + positions[i].price);
            }
        }
示例#4
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);
            }
        }
示例#5
0
        private async void buttonGetPositions_Click(object sender, EventArgs e)
        {
            initializeListBox();
            var res = await FlyerAPI2.getPositionsAsync();

            foreach (var v in res)
            {
                addListBox(v.open_date + ", price=" + v.price + ", pnl=" + v.pnl + ", sfd=" + v.sfd + ", size" + v.size);
            }
        }
示例#6
0
        private async void buttonGetExecutions_Click(object sender, EventArgs e)
        {
            initializeListBox();
            var res = await FlyerAPI2.getExecutionsAsync();

            foreach (var v in res)
            {
                addListBox("acceptance id=" + v.child_order_accesptance_id + ", commission=" + v.commission + ", price=" + v.price + ", size=" + v.size);
            }
        }
示例#7
0
        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);
        }
示例#8
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);
        }
示例#9
0
        public async Task <string> updateCurrentPositions()
        {
            var res = "";

            holding_price = new List <double>();
            holding_side  = new List <string>();
            holding_size  = new List <double>();

            var positions = await FlyerAPI2.getPositionsAsync();

            foreach (var v in positions)
            {
                addHolding(v.price, v.size, v.side);
            }
            Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("initialized holding and update positions"); }));
            return(res);
        }
示例#10
0
 public async static void startExchangeMonitor()
 {
     while (SystemFlg.getMarketDataFlg())
     {
         await Task.Run(async() =>
         {
             if (FlyerAPI2.getApiAccessProhibition() == false)
             {
                 Form1.Form1Instance.Invoke((Action)(() =>
                 {
                 }));
             }
             await Task.Delay(10000);
             return(0);
         });
     }
 }
示例#11
0
        private async void buttonGetINfo_Click(object sender, EventArgs e)
        {
            Form1Instance.initializeListBox();
            var res = await FlyerAPI2.getBalanceAsync();

            //var res2 = await FlyerAPI2.getBoardAsync("FX_BTC_JPY");
            //var res3 = await FlyerAPI2.getCollateralAsync();
            //var res4 = await FlyerAPI2.getParentOrderAsync();
            //var res5 = await FlyerAPI2.getChildOrderAsync("ACTIVE");
            //var res6 = await FlyerAPI2.getPositionsAsync();
            //var res7 = await FlyerAPI2.getExecutionsAsync();
            //var res8 = await FlyerAPI2.cancelAllChildOrdersAsync();
            foreach (var v in res)
            {
                Form1Instance.addListBox(v.currency_code + "- amount=" + v.amount + ", avaialble=" + v.available);
            }
        }
示例#12
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);
        }
示例#13
0
        public async static void startMasterThread()
        {
            SystemFlg.setMasterFlg(true);
            start_dt = new DateTime();
            start_dt = DateTime.Now;

            FlyerAPI2.startFlyerAPIMonitoring();

            while (SystemFlg.getMasterFlg())
            {
                await Task.Run(async() =>
                {
                    Form1.Form1Instance.Invoke((Action)(() =>
                    {
                        Form1.Form1Instance.setLabel10("system time elapsed (min)=" + Math.Round((DateTime.Now - start_dt).TotalMinutes, 2));
                    }));
                    await Task.Delay(100);
                    return(0);
                });
            }
        }
示例#14
0
        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);
        }
示例#15
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("");
        }
示例#16
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();
             */
        }
示例#17
0
 private async void buttonCancelAllOrders_Click(object sender, EventArgs e)
 {
     await FlyerAPI2.cancelAllChildOrdersAsync();
 }
示例#18
0
 private void buttonMarketData_Click(object sender, EventArgs e)
 {
     SystemFlg.setMasterFlg(true);
     MarketData.startMarketData();
     FlyerAPI2.startFlyerAPIMonitoring();
 }
示例#19
0
        public async static Task <string> startMMBot(double entry_spread_width, double size)
        {
            string res = "";

            SystemFlg.setMMFlg(true);

            initialize();
            entry_spread = entry_spread_width;
            order_size   = size;
            var ac = new Account();

            await Task.Delay(3000);


            await Task.Run(async() =>
            {
                int num = 0;
                while (SystemFlg.getMMFlg())
                {
                    if (FlyerAPI2.getApiAccessProhibition() == false)
                    {
                        //Log.addLog("MMBOT", "num=" + num.ToString());
                        await MMStrategy(ac);

                        //string line2 = "";
                        //var ord = ac.getAllOrders();

                        /*for (int i = 0; i < ord.Count; i++)
                         *  line2 += ord[i].order_side + " - " + ord[i].order_lot + "@" + ord[i].order_price + ", ";
                         */
                        //ac.takeLog("orders:"+line2);
                        //ac.takeLog("holdings:"+ ac.holding_ave_side + ", hold ave price=" + ac.holding_ave_price + " x " + ac.holding_total_size);

                        Form1.Form1Instance.Invoke((Action)(() =>
                        {
                            Form1.Form1Instance.setLabel5(ac.holding_ave_side + ", hold ave price=" + ac.holding_ave_price + " x " + ac.holding_total_size);
                            Form1.Form1Instance.setLabel4("num trade=" + ac.num_trade);
                            //Form1.Form1Instance.setLabel6(line2);
                        }));
                        num++;
                    }
                    else
                    {
                        Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.setLabel4("api prohibited"); }));
                        await Task.Delay(1000);
                    }
                }
            });

            Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("Finishing MMBot"); }));
            await ac.cancelAllOrders();

            await ac.checkExecutionAndUpdateOrders();

            await ac.startExitPriceTracingOrder();

            Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("Finished MMBot"); }));

            //ac.displayAllLog();
            ac.writeLog();

            return(res);
        }