private bool _CanCancel(string Account, string KeyNo) { string msg; if (!Order.isCapitalConnect) { return(false); } if (Utility.Load <bool>("ORDERSETTING", "STOPORDER")) { msg = "已勾選【禁止下單】!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", msg); Utility.Log(this, "Cancel", msg); return(false); } if (string.IsNullOrEmpty(Account) || string.IsNullOrEmpty(KeyNo)) { msg = "尚未選擇商品,不下單!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("商品錯誤", msg)); Utility.Log(this, "Cancel", msg); return(false); } return(true); }
private bool _CanOrder(string Exchange, string OrderHead, string YM, String YM2, double Price) { string msg; if (!Order.isCapitalConnect) { return(false); } if (Utility.Load <bool>("ORDERSETTING", "STOPORDER")) { msg = "已勾選【禁止下單】!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", msg); Utility.Log(this, "Order", msg); return(false); } if (string.IsNullOrEmpty(Exchange) || string.IsNullOrEmpty(OrderHead) || string.IsNullOrEmpty(YM)) { msg = "尚未選擇商品,不下單!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("商品錯誤", msg)); Utility.Log(this, "Order", msg); return(false); } if (Price <= 0D && string.IsNullOrEmpty(YM2)) { msg = "委託價 = 0,不下單!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("價格錯誤", msg)); Utility.Log(this, "Order", msg); return(false); } int qty = Utility.Load <int>("ORDERSETTING", "LOTS"); if (qty == 0) { msg = "口數 = 0,不下單!"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("數量錯誤", msg)); Utility.Log(this, "Order", msg); return(false); } //股數限制 int limit = (LotsLimit != 0 && AutoLotsLimit != 0 ? Math.Min(LotsLimit, AutoLotsLimit) : Math.Max(LotsLimit, AutoLotsLimit)); if (qty > limit) { msg = $"口數 [{qty}] > 口數上限 [{limit}]"; AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("數量錯誤", msg)); Utility.Log(this, "Order", msg); return(false); } return(true); }
public bool DoCancel2(string Account, string KeyNo) { if (!_CanCancel(Account, KeyNo)) { return(false); } string sb; bool re = Order.Cancel(Account, KeyNo, out sb); Utility.Log(this, "Cancel", sb.ToString()); if (!re) { AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "刪單錯誤", new MsgLine("帳號", Account), new MsgLine("KeyNo", KeyNo), new MsgLine("錯誤", sb, Color.Crimson)); } return(re); }
public void DoOrder(string Account, string Exchange, string OrderHead, string YM, string YM2, OrderProcessor.Side Side, double Price, int qty = -1) { if (!_CanOrder(Exchange, OrderHead, YM, YM2, Price)) { return; } string msg; //int qty = Utility.Load<int>("ORDERSETTING", "LOTS"); if (qty == -1) { qty = Utility.Load <int>("ORDERSETTING", "LOTS"); } if (Utility.Load <bool>("ORDERSETTING", "ORDERALERT")) { //下單前詢問 Color color = Side == OrderProcessor.Side.B ? Color.Crimson : Color.ForestGreen; if (!AlertBox.Alert(null, AlertBoxButton.OKCancel, "下單", new MsgLine("帳號", Account, color), new MsgLine("交易所", Exchange, color), new MsgLine("商品", OrderHead, color), new MsgLine("月份", !string.IsNullOrEmpty(YM2) ? $"{YM}/{YM2}" : YM, color), new MsgLine("買賣", Side, color), new MsgLine("口數", qty.ToString("#,##0"), color), new MsgLine("價格", Price, color))) { Utility.Log(this, "Order", "Cancel"); return; } } if (string.IsNullOrEmpty(YM2)) { bool re = Order.Order(Account, Exchange, OrderHead, YM, Side, qty, Price, out msg); Utility.Log(this, "Order", msg); if (!re) { AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "下單錯誤", new MsgLine("帳號", Account), new MsgLine("交易所", Exchange), new MsgLine("商品", OrderHead), new MsgLine("月份", YM), new MsgLine("買賣", Side), new MsgLine("口數", qty), new MsgLine("價格", Price), new MsgLine("錯誤", msg, Color.Crimson)); } } else { bool re = Order.SpreadOrder(Account, Exchange, OrderHead, YM, YM2, Side, qty, Price, out msg); Utility.Log(this, "SpreadOrder", msg); if (!re) { AlertBox.AlertWithoutReply(null, AlertBoxButton.Error_OK, "轉倉下單錯誤", new MsgLine("帳號", Account), new MsgLine("交易所", Exchange), new MsgLine("商品", OrderHead), new MsgLine("月份", !string.IsNullOrEmpty(YM2) ? $"{YM}/{YM2}" : YM), new MsgLine("買賣", Side), new MsgLine("口數", qty), new MsgLine("價格", Price), new MsgLine("錯誤", msg, Color.Crimson)); } } }