private static void writeExecutionsData() { if (MarketDataLog.getNumExecutionsLog() > 10000) { DBManager.insertExecutions(MarketDataLog.getExecutionsData()); } }
private async static void marketDataThread() { A: disconnect_flg = false; //var api = new API(); //var api2 = new API(); var api3 = new API(); //api.Subscribe<Tick>(api.TickerFxBtcJpy, OnReceive, OnConnect, OnError); //api2.Subscribe<BoardDiff>(api.boardFxBtcJpy, OnReceiveBoard, OnConnectBoard, OnError); api3.Subscribe <List <Executions> >(api3.ExecutionsFxBtcJpy, OnReceiveExecutions, OnConnectExecutions, OnErrorExecutions); while (SystemFlg.getMarketDataFlg()) { await Task.Delay(300); //Thread.Sleep(10); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.setLabel("num executions log=" + MarketDataLog.getNumExecutionsLog().ToString()); Form1.Form1Instance.setLabel2("num board data log=" + MarketDataLog.getNumBoardData().ToString()); })); if (disconnect_flg) { goto A;//make new instance when unexpectedlly disconnected } } api3.unsubscribe(); }
public async Task <string> checkExecutionAndUpdateOrders() { var res = ""; if (MarketDataLog.getNumExecutionsLog() < last_ind_marketdata) { last_ind_marketdata = 0; } var exe_data = MarketDataLog.getExecutionsDataRange(last_ind_marketdata); last_ind_marketdata += exe_data.Count; var ord = getAllOrders(); for (int i = 0; i < ord.Count; i++) { for (int j = 0; j < exe_data.Count; j++) { if (exe_data[j].buy_child_order_acceptance_id == ord[i].order_id || exe_data[j].sell_child_order_acceptance_id == ord[i].order_id) { addHolding(ord[i].order_price, exe_data[j].size, ord[i].order_side); takeLog(DateTime.Now + ": executed " + ord[i].order_side + " for " + exe_data[j].price + " x " + exe_data[j].size); Log.addLog("Account-checkExecutionAndUpdateOrders", ": executed " + ord[i].order_side + " for " + exe_data[j].price + " x " + exe_data[j].size); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("executed " + ord[i].order_side + " for " + exe_data[j].price + " x " + exe_data[j].size); })); if ((ord[i].order_lot - exe_data[j].size) <= 0) { takeLog(DateTime.Now + ": order " + ord[i].order_id + " was full filled and removed"); Log.addLog("Account-checkExecutionAndUpdateOrders", ": order " + ord[i].order_id + " was full filled and removed"); Form1.Form1Instance.Invoke((Action)(() => { Form1.Form1Instance.addListBox2("order " + ord[i].order_id + " was full filled and removed"); })); removeOrder(ord[i].order_id); num_trade++; } else { Log.addLog("Account-checkExecutionAndUpdateOrders", ": order " + ord[i].order_id + " was partially executed"); updateOrderSize(ord[i].order_lot - exe_data[j].size, ord[i].order_id); } } } } return(res); }