private void JY_OrderCanceled(object sender, OrderItem e) { string[] keys = TradeRA.KeySearch("O_" + e.order_no + "_*"); if (keys.Length == 0 || keys[0].EndsWith("U_0") || keys[0].EndsWith("_F")) { return; } Order model = new Order() { order_no = e.order_no, deal_count = (int)decimal.Parse(e.deal_count), cancel_count = (int)decimal.Parse(e.cancel_count), status = e.status, }; OrderRA.UpdateStatus(model, keys[0]); //撤单成功取消冻结 Order order = OrderRA.Get(keys[0]); MessageBiz.Send(order.user_id.ToString(), MessageTypeEnum.Order_Canceled, "[" + order.code + "]" + order.name + "撤单成功,撤单数量:" + model.cancel_count); if (e.type == "0") { string key_unit = "U_" + order.unit_id; UnitRA.UpdateCapitalOrderBuy(-order.price * model.cancel_count, key_unit); } else if (e.type == "1") { string key_position = "P_" + order.code + "_A_" + order.account_id + "_U_" + order.unit_id; PositionRA.UpdateSellableOrderSell(order.cancel_count, key_position); } MonitorRA.Increment("account_" + account_id, "cancel_count"); }
public void Order(Order order) { string request_id = FuncHelper.GetUniqueID().ToString(); order.account_id = account_id; order.name = StockInfoBiz.GetStock(order.code).name; order.time_dt = DateTime.Now; OrderRA.Add(order, "O_" + request_id + "_T_" + order.trade_no + "_U_" + order.unit_id + "_F"); JY.Order(new JY.Order(order.code, order.type, order.count, order.price, request_id)); MonitorRA.Increment("account_" + account_id, "order_count"); }
private void JY_NewOrder(object sender, OrderItem e) { Order order; string[] keys = TradeRA.KeySearch("O_" + e.order_no + "_*"); //处理系统中是否存在未能正常收到回报但已成功的委托(通常由于下单超时导致) if (keys.Length == 0 && !string.IsNullOrWhiteSpace(e.request_id) && e.request_id != "0") { JY_Order_Done(null, new OrderResult(true, e.order_no, "", e.request_id)); keys = TradeRA.KeySearch("O_" + e.order_no + "_*"); } if (keys.Length > 0) { order = OrderRA.Get(keys[0]); if (order.cancel_count != (int)decimal.Parse(e.cancel_count)) { JY_OrderCanceled(null, e); return; } } else { order = new Order(); } order.deal_count = (int)decimal.Parse(e.deal_count); order.cancel_count = (int)decimal.Parse(e.cancel_count); order.status = e.status; order.time_dt = DateTime.Parse(e.date.ToDate() + " " + e.time.ToTime()); if (keys.Length > 0) { OrderRA.UpdateNew(order, keys[0]); } else { string key = "O_" + e.order_no + "_T_0_U_0"; order.trade_no = "0"; order.order_no = e.order_no; order.name = e.name; order.code = e.code; order.price = decimal.Parse(e.price); order.count = order.trade_count = (int)decimal.Parse(e.count); order.type = int.Parse(e.type); order.account_id = account_id; order.state_enum = OrderStatusEnum.Success; OrderRA.Add(order, key); } }
private void JY_OrderChanged(object sender, OrderItem e) { string[] keys = TradeRA.KeySearch("O_" + e.order_no + "_*"); if (keys.Length > 0) { Order model = new Order() { order_no = e.order_no, deal_count = (int)decimal.Parse(e.deal_count), cancel_count = (int)decimal.Parse(e.cancel_count), status = e.status }; OrderRA.UpdateStatus(model, keys[0]); } }
private void JY_NewDeal(object sender, DealItem e) { Order order = null; int unit_id = 0; string[] keys = TradeRA.KeySearch("O_" + e.order_no + "_*"); if (keys.Length > 0) { order = OrderRA.Get(keys[0]); unit_id = order.unit_id; } string key = "D_" + e.deal_no + "_O_" + e.order_no + "_U_" + unit_id; if (TradeRA.KeyExists(key)) { return; } Deal deal = new Deal() { code = e.code, name = e.name, type = int.Parse(e.type), count = (int)decimal.Parse(e.count), money = decimal.Parse(e.money), time_dt = DateTime.Parse(e.date.ToDate() + " " + e.time.ToTime()), deal_no = e.deal_no, order_no = e.order_no, price = decimal.Parse(e.price), unit_id = unit_id, account_id = account_id, transferred = unit_id > 0 ? 0 : 1, }; DealRA.Add(deal, key); //更新成交均价 DealAveragePrice(deal); //系统内成交 if (unit_id > 0) { MessageBiz.Send(order.user_id.ToString(), MessageTypeEnum.Order_Dealt, "[" + deal.code + "]" + deal.name + "已成交,成交数量:" + deal.count); TradeBiz.NewDeal(deal, order.price); MonitorRA.Increment("account_" + account_id, "deal_count"); } }
private void JY_Order_Done(object sender, OrderResult e) { string[] keys = TradeRA.KeySearch("O_" + e.request_id + "_*"); if (keys.Length == 0) { return; } Order order = OrderRA.Get(keys[0]); if (order.state_enum != OrderStatusEnum.Submitted) { return; } //委托失败解除冻结 if (!e.result) { if (order.type_enum == OrderTypeEnum.Buy) { string key_unit = "U_" + order.unit_id; UnitRA.UpdateCapitalOrderBuy(-order.price * order.count, key_unit); } else if (order.type_enum == OrderTypeEnum.Sell) { string key_position = "P_" + order.code + "_A_" + order.account_id + "_U_" + order.unit_id; PositionRA.UpdateSellableOrderSell(order.count, key_position); } OrderRA.UpdateOrderFailed(keys[0], e.message); MessageBiz.Send(order.user_id.ToString(), MessageTypeEnum.Order_Failed, "[" + order.code + "]" + order.name + "委托失败。" + e.message); MonitorRA.Increment("account_" + account_id, "failed_count"); } else { OrderRA.UpdateOrderSuccess(keys[0], order.unit_id, order.trade_no, e.order_no); MonitorRA.Increment("account_" + account_id, "success_count"); } }