public virtual Trade StartTrade(Entity source, Entity destination) { Trade trade = new Trade() { DateTime = DateTime.Now, Day = GameHelper.CurrentDay, DestinationAccepted = false, DestinationEntityID = destination.EntityID, DestinationUsedFuelAmount = null, SourceAccepted = false, SourceUsedFuelAmount = null, SourceEntityID = source.EntityID, TradeStatusID = (int)TradeStatusEnum.Ongoing, UpdatedDate = DateTime.Now, }; tradeRepository.Add(trade); ConditionalSaveChanges(tradeRepository); var sourceLink = EntityLinkCreator.Create(source); var tradeLink = TradeLinkCreator.Create(trade); var msg = $"{sourceLink} started {tradeLink} with you."; warningService.AddWarning(destination.EntityID, msg); return(trade); }
public async Task Add(Trade trade) { if (!PerformValidation(new TradeValidation(), trade)) { return; } await _tradeRepository.Add(trade); }
public TradeResource Add(EditTradeResource resource) { if (resource == null) { throw new ArgumentNullException(); } var trade = _mapper.Map <Trade>(resource); _tradeRepo.Add(trade); _tradeRepo.SaveChanges(); return(_mapper.Map <TradeResource>(trade)); }
public override async Task Handle(TradeAccountCreateDto input) { await HandleAsync(input, async() => { //通过工厂创建交易领域对象 var trade = new TradeFactory().Create(input.Id); //规约校验 if (await new TradeCreateSpecification(tradeRepository).SatisfiedBy(trade)) { //仓储持久化 tradeRepository.Add(trade); await tradeRepository.SaveAsync(); } }); }
public IActionResult Post([FromBody] Trade trade) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Repo.Validate(trade); } catch (Exception xe) { return(BadRequest(xe)); } return(Ok(Repo.Add(trade))); }
//[Authorize] public async Task <IActionResult> CreateTrade([FromBody] SaveTradeResource tradeResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var trade = mapper.Map <SaveTradeResource, Trade>(tradeResource); repository.Add(trade); await unitOfWork.CompleteAsync(); var result = mapper.Map <Trade, SaveTradeResource>(trade); return(Ok(result)); }
public async Task <Response <Trade> > SaveAsync(Trade payload) { try { _tradeRepository.Add(payload); await _unitOfWork.CompleteAsync(); return(new Response <Trade>(payload)); } catch (Exception ex) { _logger.LogError($"{nameof(TradeService)} {nameof(SaveAsync)} {ex.Message}"); return(new Response <Trade>(ex.Message)); } }
private string ManageAssets(Asset soldAsset, TradeOrder order, OrderType orderType, string uuid) { var reserverAsset = new Asset(soldAsset) { Amount = order.Amount, IsReserved = true, StrategyId = soldAsset.StrategyId, }; soldAsset.Amount -= order.Amount; _assetRepository.AddNotSave(reserverAsset); if (soldAsset.Amount < 0.00000001m) { _assetRepository.DeleteNotSave(soldAsset); } else { _assetRepository.EditNotSave(soldAsset); } var quantity = orderType == OrderType.Buy ? order.Amount / order.Rate.Value : order.Amount; var trade = new Trade { MarketId = order.Symbol, Opened = DateTime.Now, Quantity = quantity, OrderType = orderType, StrategyId = soldAsset.StrategyId, TradeState = TradeState.New, Price = order.Rate.Value, QuantityRemaining = quantity, ReservedAsset = reserverAsset, Total = orderType == OrderType.Buy ? order.Amount : order.Amount * order.Rate.Value, ExchangeUuid = uuid, Exchange = order.Exchange, }; _tradeRepository.Add(trade); _assetRepository.Save(); return(trade.Id); }
static void SetUpData() { _stockRepository.Add(new StockCommon("TEA", 100, 0, 100)); _stockRepository.Add(new StockCommon("POP", 100, 8, 100)); _stockRepository.Add(new StockCommon("ALE", 60, 23, 60)); _stockRepository.Add(new StockPreferred("GIN", 100, 8, 100, 2)); _stockRepository.Add(new StockCommon("JOE", 250, 13, 250)); _stockService = new StocksService(_stockRepository); _tradeRepository.Add(new Trade(new StockCommon("TEA", 100, 0, 100), DateTime.Now.AddMinutes(-5), 3, Trade.TradeType.Buy, 23)); _tradeRepository.Add(new Trade(new StockCommon("TEA", 100, 0, 100), DateTime.Now.AddMinutes(5), 3, Trade.TradeType.Buy, 33)); _tradeRepository.Add(new Trade(new StockCommon("POP", 100, 8, 100), DateTime.UtcNow.AddMinutes(-5), 4, Trade.TradeType.Buy, 33)); _tradeRepository.Add(new Trade(new StockCommon("ALE", 60, 23, 60), DateTime.UtcNow.AddMinutes(-1), 5, Trade.TradeType.Buy, 23)); _tradeRepository.Add(new Trade(new StockPreferred("GIN", 100, 8, 100, 2), DateTime.UtcNow.AddMinutes(-1), 6, Trade.TradeType.Buy, 23)); _tradeRepository.Add(new Trade(new StockCommon("JOE", 250, 13, 250), DateTime.UtcNow.AddMinutes(-1), 7, Trade.TradeType.Buy, 23)); _tradeService = new TradeService(_tradeRepository); }
/// <summary>'#] /// Recording a trade. An event of Sell/Buy has occured for a stock /// and it needs to be recorded. /// </summary> /// <param name="stock"></param> private void recordTrade(Stock stock, int quanitityOfShares, Trade.TradeType trade, double price) { _tradeRepository.Add(new Trade(stock, DateTime.Now, quanitityOfShares, trade, price)); }