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); } }); }
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); }); } }
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); }
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(""); }