public static void SavePosition() { string[] keys = TradeRA.KeySearch("P_*"); foreach (string key in keys) { Position position = PositionRA.Get(key); if (position.count == 0) { if (position.id > 0) { PositionDA.Delete(position.id); } } else { position.price_latest = HQService.Get(position.code).Last; if (position.id > 0) { PositionDA.Update(position); } else { PositionDA.Add(position); } } } }
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 void DeleteAccountData_() { int accID; // create var accDA = new AccountDA(_options); var insDA = new InstrumDA(_options); var posDA = new PositionDA(_options); int insID = insDA.InsertInstrum("", "", "", 1, 0, 1); accID = accDA.CreateAccount("code", "name", 100, true, AccountTypes.Test).AccountID; accDA.CreateCash(accID, 0, 0, 0, 0, 0, 0); var order = accDA.CreateOrder(accID, DateTime.Now, insID, Platform.BuySell.Buy, 1, null, Platform.OrderStatus.Active, null, 0); var trade = accDA.CreateTrade(accID, order.OrderID, DateTime.Now, insID, Platform.BuySell.Buy, 1, 0, 0, 0); var so = accDA.CreateStopOrder(accID, DateTime.Now, insID, Platform.BuySell.Buy, Platform.StopOrderType.StopLoss, null, 0, null, 0, Platform.StopOrderStatus.Active, null, 0); var h = accDA.CreateHolding(accID, insID, 1); var pos = posDA.CreatePosition(accID, insID, PosTypes.Long, DateTime.Now, 0, 0, null, null); posDA.AddPosTrade(pos.PosID, trade.TradeID); accDA.DeleteAccountData(accID); Assert.Null(accDA.GetCash(accID)); // данные удалились Assert.Empty(accDA.GetOrders(accID)); Assert.Empty(accDA.GetStopOrders(accID)); Assert.Empty(accDA.GetTrades(accID)); Assert.Empty(accDA.GetHoldings(accID)); Assert.Empty(posDA.GetPosTrades(new List <int>() { pos.PosID })); Assert.Empty(posDA.GetPositions(accID, false)); Assert.NotNull(accDA.GetAccountByID(accID)); // а сам account остался // cleanup insDA.DeleteInstrumByID(insID); accDA.DeleteAccount(accID); }
public static List <Position> GetPositionByCompanyID(int companyID) { return(PositionDA.GetPositionByCompanyID(companyID).Select(PositionEntity.Convert).ToList()); }