public static void Open() { HQService.SubscribeStart(); var accounts = AccountDA.List <Account>(); foreach (Account account in accounts) { LoadAccount(account); } var units = UnitDA.List <Unit>(); foreach (Unit unit in units) { LoadUnit(unit); } var positions = PositionDA.List(); foreach (Position position in positions) { LoadPosition(position); } var items = AccountGroupDA.ListItems(); foreach (AccountGroupItem item in items) { LoadAccountGroupItem(item); } HQService.Get(positions.Select(p => p.code)); TradeBiz.Start(); }
public static void Close() { TradeBiz.Stop(); HQBiz.Save(); SaveOrder(); Dictionary <int, decimal[]> dic = new Dictionary <int, decimal[]>(); SaveDeal(ref dic); SavePosition(); SaveAccountCapital(); SaveUnitCapital(dic); StockInfoBiz.RefreshBlockList(); }
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"); } }
public static void LoadAccount(Account account, bool add = true) { TradeBiz.LoadAccount(account); string key = "A_" + account.id; if (add && TradeRA.KeyExists(key)) { return; } if (add) { AccountRA.Add(account, key); } else { AccountRA.Update(account, key); } }