private void OnReceiveBalance(object sender, Holding e) { if (EnCash > 0) { EnCash--; int price = 0; string code = string.Empty; foreach (string en in e.Hold) { if (en.Equals(string.Empty)) { break; } string[] temp = en.Split(';'); if (temp[0].Length > 0 && (temp[0].Substring(0, 3).Equals("101") || temp[0].Substring(0, 3).Equals(OrderType))) { continue; } int close = int.Parse(temp[5]); if (close > price) { code = temp[0]; price = close; } } if (price > 0) { api.OnReceiveOrder(new PurchaseInformation { Code = code, SlbyTP = "1", OrdTp = ((int)IStrategy.OrderType.시장가).ToString(), Price = string.Empty, Qty = 1 }); } BeginInvoke(new Action(() => new LogMessage().Record("Options", string.Concat(DateTime.Now.ToLongTimeString(), "*", code, "*", (price / (double)100).ToString("N2"), "*", "Sell")))); } balGrid.SuspendLayout(); balGrid.Rows.Clear(); balGrid.AutoSize = true; foreach (string info in e.Hold) { string[] arr = new string[7]; int i = 0; foreach (string val in info.Split(';')) { if (val.Equals(string.Empty)) { break; } switch (i) { case 0: case 1: arr[i++] = val; break; case 2: arr[i++] = val.Equals("1") ? "매도" : "매수"; break; case 3: case 6: arr[i++] = int.Parse(val).ToString("N0"); break; case 4: case 5: arr[i++] = (double.Parse(val) / 100).ToString("N2"); break; } } if (arr[0] != null) { balGrid.Rows.Add(arr); } } if (balGrid.Rows.Count > 0) { balGrid.Show(); balGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; balGrid.Cursor = Cursors.Hand; balGrid.AutoResizeRows(); balGrid.AutoResizeColumns(); balGrid.ResumeLayout(); SendReSize?.Invoke(this, new GridReSize(balGrid.Rows.GetRowsHeight(DataGridViewElementStates.None), balGrid.Rows.Count)); return; } balGrid.Hide(); }
private void OnReceiveBalance(object sender, Holding e) { BeginInvoke(new Action(() => { balGrid.SuspendLayout(); balGrid.Rows.Clear(); balGrid.AutoSize = true; foreach (string info in e.Hold) { string[] arr = new string[7]; int i = 0; foreach (string val in info.Split(';')) { if (val.Equals(string.Empty)) { break; } switch (i) { case 0: case 1: arr[i++] = val; break; case 2: arr[i++] = val.Equals("1") ? "매도" : "매수"; break; case 3: case 6: arr[i++] = int.Parse(val).ToString("N0"); break; case 4: case 5: arr[i++] = (double.Parse(val) / 100).ToString("N2"); break; } } if (arr[0] != null) { balGrid.Rows.Add(arr); foreach (DataGridViewRow row in balGrid.Rows) { var type = row.Cells[2]; if (type.Value.Equals("매도")) { type.Style.ForeColor = Color.Navy; type.Style.SelectionForeColor = Color.DeepSkyBlue; } else if (type.Value.Equals("매수")) { type.Style.ForeColor = Color.Maroon; type.Style.SelectionForeColor = Color.FromArgb(0xB9062F); } type = row.Cells[6]; long revenue = long.Parse(type.Value.ToString().Replace(",", string.Empty)); if (revenue > 0) { type.Style.ForeColor = Color.Maroon; type.Style.SelectionForeColor = Color.FromArgb(0xB9062F); } else if (revenue < 0) { type.Value = type.Value.ToString().Replace("-", string.Empty); type.Style.ForeColor = Color.Navy; type.Style.SelectionForeColor = Color.DeepSkyBlue; } } } } if (EnCash > 0 && balGrid.Rows.Count > 0) { EnCash--; int price = 0; string code = string.Empty; foreach (string en in e.Hold) { if (en.Equals(string.Empty)) { break; } string[] temp = en.Split(';'); if (temp[0].Length > 0 && (temp[0].Substring(0, 3).Equals("101") || temp[0].Substring(0, 3).Equals(OrderType))) { continue; } if (!temp[0].Substring(0, 3).Equals("101") && temp[2].Equals("1")) { api.OnReceiveOrder(new PurchaseInformation { Code = temp[0], SlbyTP = "2", OrdTp = ((int)IStrategy.OrderType.시장가).ToString(), Price = string.Empty, Qty = 1 }); new LogMessage().Record("Options", string.Concat(DateTime.Now.ToLongTimeString(), "*", temp[0], "*", (int.Parse(temp[5]) / (double)100).ToString("N2"), "*", "Revise")); continue; } int close = int.Parse(temp[5]); if (close > price) { code = temp[0]; price = close; } } if (price > 0) { api.OnReceiveOrder(new PurchaseInformation { Code = code, SlbyTP = "1", OrdTp = ((int)IStrategy.OrderType.시장가).ToString(), Price = string.Empty, Qty = 1 }); } new LogMessage().Record("Options", string.Concat(DateTime.Now.ToLongTimeString(), "*", code, "*", (price / (double)100).ToString("N2"), "*", "Sell")); } if (balGrid.Rows.Count > 0) { balGrid.Show(); balGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; balGrid.Cursor = Cursors.Hand; balGrid.AutoResizeRows(); balGrid.AutoResizeColumns(); balGrid.ResumeLayout(); SendReSize?.Invoke(this, new GridReSize(balGrid.Rows.GetRowsHeight(DataGridViewElementStates.None), balGrid.Rows.Count)); Application.DoEvents(); return; } balGrid.Hide(); })); }
public void OnReceiveBalance(object sender, Balance e) { BeginInvoke(new Action(() => { balGrid.SuspendLayout(); balGrid.Rows.Clear(); balGrid.AutoSize = true; foreach (string info in e.Hold) { string[] arr = new string[7]; int i = 0; foreach (string val in info.Split(';')) { if (val.Equals(string.Empty)) { break; } switch (i) { case 0: case 1: arr[i++] = val; break; case 2: arr[i++] = val.Equals("1") ? "매도" : "매수"; break; case 3: case 6: arr[i++] = int.Parse(val).ToString("N0"); break; case 4: case 5: arr[i++] = (val.Contains(".") ? double.Parse(val) : (double.Parse(val) / 100)).ToString("N2"); break; } } if (arr[0] != null) { balGrid.Rows.Add(arr); } } foreach (DataGridViewRow row in balGrid.Rows) { var type = row.Cells[2]; if (type.Value.Equals("매도")) { type.Style.ForeColor = Color.Navy; type.Style.SelectionForeColor = Color.DeepSkyBlue; } else if (type.Value.Equals("매수")) { type.Style.ForeColor = Color.Maroon; type.Style.SelectionForeColor = Color.FromArgb(0xB9062F); } type = row.Cells[6]; long revenue = long.Parse(type.Value.ToString().Replace(",", string.Empty)); if (revenue > 0) { type.Style.ForeColor = Color.Maroon; type.Style.SelectionForeColor = Color.FromArgb(0xB9062F); } else if (revenue < 0) { type.Value = type.Value.ToString().Replace("-", string.Empty); type.Style.ForeColor = Color.Navy; type.Style.SelectionForeColor = Color.DeepSkyBlue; } } balGrid.Show(); balGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; balGrid.Cursor = Cursors.Hand; balGrid.AutoResizeRows(); balGrid.AutoResizeColumns(); SendReSize?.Invoke(this, new GridResize(balGrid.Rows.GetRowsHeight(DataGridViewElementStates.None), balGrid.Rows.Count)); balGrid.ResumeLayout(); })); }